Missing Expression for insert statement in PL/SQL ODBM?

喜夏-厌秋 提交于 2019-12-25 01:32:41

问题


I'm attempting to populate an object-relational database in PL/SQL on Oracle SQL Developer, and keep getting the error ORA-00936: Missing Expression.

I've attempted different fixes, but they all result in different errors. The database was provided, and the INSERT statement is all mine.

The result should be inserting into the table properly, but it isn't, and I'm at a loss on how to progress.

-- 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  
/ 

Here is my insert statement

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:


You have several errors in your INSERT statement:

  1. You are missing a closing ) at the end (this is something where editors highlighting matching parentheses can help a lot)
  2. you have no type artist_array_list you only haveartist_array_type
  3. you nave no type albumReviews that should be review_table_type

Putting that all together, the following works:

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)
);


来源:https://stackoverflow.com/questions/58342509/missing-expression-for-insert-statement-in-pl-sql-odbm

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!