Reputation:
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?
Upvotes: 0
Views: 2023
Reputation: 1269563
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.
Upvotes: 2
Reputation: 191245
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.
Upvotes: 1