我试图输入日期即18-Sep-09
并将其存储到v_today
。但是我收到
PLS-00201:标识符'SEP'必须声明。
SET SERVEROUTPUT ON
DECLARE
v_today DATE :=TO_DATE(&today,'YY-MMM-DD');
v_tomorrow v_today%TYPE :=today+1;
BEGIN
DMBS_OUTPUT.PUT_LINE('Today is: '|| v_today);
DMBS_OUTPUT.PUT_LINE('Tomorrow will be: '|| v_tomorrow);
END;
虽然您这样做了,但我建议您不要依赖隐式数据类型转换。'&today'
是字符串,不是日期。考虑这样做,使用适当的格式掩码应用to_date
(和to_char
,就像您已经做的那样):
SQL> DECLARE
2 v_today DATE := to_date('&today', 'dd.mm.yyyy');
3 v_tomorrow v_today%TYPE := v_today + 1;
4 BEGIN
5 DBMS_OUTPUT.PUT_LINE('Today is : '|| TO_CHAR(v_today, 'DAY'));
6 DBMS_OUTPUT.PUT_LINE('Tomorrow will be: '|| TO_CHAR(v_tomorrow,'DAY'));
7 END;
8 /
Enter value for today: 24.09.2021
Today is : FRIDAY
Tomorrow will be: SATURDAY
PL/SQL procedure successfully completed.
SQL>
对于有帮助的人,我已经整理好了
我需要将输入字符串用单引号括起来,然后在输出中使用TO_CHAR函数。
SET SERVEROUTPUT ON
DECLARE
v_today DATE :='&today';
v_tomorrow v_today%TYPE :=v_today+1;
BEGIN
DBMS_OUTPUT.PUT_LINE('Today is: '|| TO_CHAR(v_today, 'DAY'));
DBMS_OUTPUT.PUT_LINE('Tomorrow will be: '|| TO_CHAR(v_tomorrow,'DAY'));
END;