Oracle:消除错误
我有一个假期表,其描述
Name Null? Type
HOLIDAYDATE DATE
DESCRIPTION VARCHAR2(20)
包含数据,
HOLIDAYDA DESCRIPTION
--------- --------------------
19-JAN-11 to
17-JAN-11 to
10-JAN-11 a
这里是我的代码:
DECLARE a date;
SELECT holidaydate
INTO a
FROM holiday
WHERE holidaydate = SYSDATE;
DBMS_OUTPUT.PUT_LINE(a);
我收到这样的错误。
第 2 行出现错误: ORA-06550: 第 2 行,第 1 列: PLS-00103:在预期以下情况之一时遇到符号“SELECT”: 开始函数包编译指示过程子类型类型使用 形式 当前光标
谁能告诉我我的代码有什么问题吗?
I have the holiday table whose description are
Name Null? Type
HOLIDAYDATE DATE
DESCRIPTION VARCHAR2(20)
which contains data are
HOLIDAYDA DESCRIPTION
--------- --------------------
19-JAN-11 to
17-JAN-11 to
10-JAN-11 a
here is my code :
DECLARE a date;
SELECT holidaydate
INTO a
FROM holiday
WHERE holidaydate = SYSDATE;
DBMS_OUTPUT.PUT_LINE(a);
i am receiving error like this.
ERROR at line 2:
ORA-06550: line 2, column 1:
PLS-00103: Encountered the symbol "SELECT" when expecting one of the following:
begin function package pragma procedure subtype type use
form
current cursor
Can anyone tell me what is the problem in my code?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
但这可能会给您带来新的错误(未找到数据),因为可能没有在 Holidaydate 中输入 Sysdate 的记录,因为 sysdate 也包含时间。
所以试试这个:
这将切断时间部分,检查整个日期。如果表中也有完整日期,则更有可能给出结果。如果不是,则来自 Dual 的 select 将捕获该信息,并使
a
返回 NULL。您现在可能遇到的唯一错误是当有多个记录包含相同日期时。
But this will probably give you a new error (no data found), because there probably is no record that has Sysdate entered in Holidaydate, because sysdate includes the time as well.
So try this:
That will cut off the time part, checking for whole dates. If there are whole dates in your table as well, this will more likely give a result. If not, the select from dual will capture that, and make
a
return NULL.The only error you may get now, is when there are more than one records containing the same date.