在PL / SQL ODBM中缺少insert语句的表达式?

时间:2019-10-11 13:40:00

标签: sql oracle plsql sql-insert

我正在尝试在Oracle SQL Developer上的PL / SQL中填充对象关系数据库,并不断收到错误ORA-00936:缺少表达式。

我尝试了不同的修复程序,但它们均导致不同的错误。已经提供了数据库,并且INSERT语句全是我的。

结果应该正确地插入到表中,但事实并非如此,而且我对如何前进感到困惑。

-- create OMDB --
-----------------
-- drop tables --
drop table albums 
/ 
drop type disk_type 
/ 
drop type mp3_type 
/
drop type album_type 
/
drop type artist_array_type 
/
drop type artist_type 
/
drop type review_table_type 
/
drop type review_type 
/
-- create types --
create or replace type artist_type as object 
(artistName     varchar(50), 
 artistRole     varchar(25)) 
/ 
create type artist_array_type  
as varray(5) of artist_type 
/ 
create or replace type review_type as object 
(reviewerName   varchar(25), 
 reviewDate     date,
 reviewText     varchar(250), 
 reviewScore    number) 
/
create or replace type review_table_type as table of review_type 
/
create or replace type album_type as object 
(albumTitle         varchar(50),
 albumPlaytime      number(3), -- minutes
 albumReleaseDate   date, 
 albumGenre         varchar(15),
 albumPrice         number(9,2),
 albumTracks        number(2),
 albumArtists       artist_array_type,
 albumReviews       review_table_type,
member function discountPrice return number,
member function containsText (pString1 varchar2, pString2 varchar2) return integer)
not instantiable not final  
/
create or replace type disk_type under album_type 
( mediaType         varchar(10),
 diskNum            number(2), -- number of disks
 diskUsedPrice      number(9,2),
 diskDeliveryCost   number(9,2), 
overriding member function discountPrice return number) 
/
create or replace type mp3_type under album_type
(downloadSize   number, -- size in MB
 overriding member function discountPrice return number) 
/
-- create tables --
create table albums of album_type 
object id system generated
nested table albumReviews store as store_reviews  
/ 

这是我的插入语句

insert into albums values (disk_type('The Essential Bob Dylan', 99, '8-Jul-2016', 'Pop', 37.00, 32, 
artist_array_list(artist_type('Bob Dylan', 'Vocals'), artist_type('Bob Dylan', 'Composer')), 
albumReviews(review_type('Shawn', '24-Jul-2018', 'Wife loved it!', 5), review_type('Reuben', '2-Aug-2019', 'Great compilation of some of his most known songs', 5)), 
'Vinyl', 2, '', 11.00)
/

1 个答案:

答案 0 :(得分:3)

您的INSERT语句中有几个错误:

  1. 您最后缺少结尾处的)(这是编辑器突出显示匹配的括号会很有帮助的地方)
  2. 您没有artist_array_list类型,只有artist_array_type
  3. 您没有albumReviews类型的review_table_type

将所有内容整合在一起,可以完成以下工作:

insert into albums 
values (
  disk_type('The Essential Bob Dylan', 99, '8-Jul-2016', 'Pop', 37.00, 32, 
             artist_array_type(artist_type('Bob Dylan', 'Vocals'), 
                               artist_type('Bob Dylan', 'Composer')), 
             review_table_type(review_type('Shawn', '24-Jul-2018', 'Wife loved it!', 5), 
                               review_type('Reuben', '2-Aug-2019', 'Great compilation of some of his most known songs', 5)), 
             'Vinyl', 2, '', 11.00)
);