to_date 函数 pl/sql
undefine dates
declare
v_dateInput VARCHAR(10);
v_dates DATE;
begin
v_dateInput := &&dates;
v_dates := to_date(v_dateInput,'dd-mm-yyyy');
DBMS_OUTPUT.put_line(v_dates);
end;
不知道为什么每当我运行此代码时,例如输入 03-03-1990,就会出现此错误。
Error report:
ORA-01847: day of month must be between 1 and last day of month
ORA-06512: at line 6
01847. 00000 - "day of month must be between 1 and last day of month"
*Cause:
*Action:
undefine dates
declare
v_dateInput VARCHAR(10);
v_dates DATE;
begin
v_dateInput := &&dates;
v_dates := to_date(v_dateInput,'dd-mm-yyyy');
DBMS_OUTPUT.put_line(v_dates);
end;
Not sure why whenever I run this code with ,for example , input of 03-03-1990, this error shows up.
Error report:
ORA-01847: day of month must be between 1 and last day of month
ORA-06512: at line 6
01847. 00000 - "day of month must be between 1 and last day of month"
*Cause:
*Action:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
哈,不错的一个。那是因为 &&就地替换变量,因此您的脚本变为:
请注意缺少引号。 v_dateInput 实际上是“-1990”,因为 oracle 计算的数值是 03 - 03 - 1990。当然,这不适用于给定的格式字符串。
要修复它,您需要
Ha, good one. That's because && replaces the variable in-place, so your script becomes:
Note the absence of quotes. v_dateInput is, effectively, '-1990', because oracle calculates the numeric value of 03 - 03 - 1990. Of course, this doesn't work with the given format string.
To fix it, you need
当提示输入日期值时,请确保将其放在单引号中,例如
共享并享受。
When prompted to enter a value for dates make sure you put it in single-quotes, e.g.
Share and enjoy.