简体   繁体   English

oracle Sql Developer错误绑定变量未声明

[英]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. 未声明值Booked

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. 因此:00PM:30PM被解释为绑定变量。 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. 但我希望尽可能使用日期/时间戳文字,如Gordon所示。 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. 您还缺少仅日期值周围的单引号,并且也像Booked Gordon提到的那样,明确列出列名确实是个好主意。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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