简体   繁体   中英

oracle Sql Developer Error Bind Variable not declared

Insert into booking values 
('EWKF2VN','Canada',TO_DATE(11/20/12,'DD/MON/YY'),
TO_DATE(1/10/18 4:00PM,'DD/MON/YY HH:MIAM'),
TO_DATE(1/10/18 6:30PM,'DD/MON/YY HH:MIAM'),
'B',125.00,Booked,'AC101',8521169618);

Not sure why I am getting this error

Bind Variable not declared

Any suggestions?

This is your code:

Insert into booking
    values ('EWKF2VN', 'Canada', TO_DATE(11/20/12,'DD/MON/YY'),
            TO_DATE(1/10/18 4:00PM, 'DD/MON/YY HH:MIAM'),
            TO_DATE(1/10/18 6:30PM, 'DD/MON/YY HH:MIAM'),
            'B', 125.00, Booked, 'AC101', 8521169618
           );

The value Booked is undeclared.

I would write this as:

Insert into booking ( . . . ) -- explicitly list columns here
    values ('EWKF2VN', 'Canada', DATE '2012-11-20',
            TIMESTAMP '2018-01-10 16:00:00',
            TIMESTAMP '2018-01-10 18:30:00',
            'B', 125.00, 'Booked', 'AC101', 8521169618
           );

This lists the columns explicitly. And it uses the built-in keywords for providing date and timestamp constants.

You're getting that error because you're doing this:

TO_DATE(1/10/18 4:00PM, 'DD/MON/YY HH:MIAM'),
TO_DATE(1/10/18 6:30PM, 'DD/MON/YY HH:MIAM'),

with the value you are trying to convert missing single quote enclosures; so the :00PM and :30PM are being interpreted as bind variables. Hence the error message, as they are indeed not declared.

So you could do:

TO_DATE(‘1/10/18 4:00PM’, 'DD/MON/YY HH:MIAM'),
TO_DATE(‘1/10/18 6:30PM’, 'DD/MON/YY HH:MIAM'),

but I'd prefer to use date/timestamp literals if possible, as Gordon shows. You're also missing single quotes around the date-only value and Booked as Gordon also mentioned, and explicitly listing the column names is indeed a good idea.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM