问题
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:
- You are missing a closing
)
at the end (this is something where editors highlighting matching parentheses can help a lot) - you have no type
artist_array_list
you only haveartist_array_type
- you nave no type
albumReviews
that should bereview_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