????7?????????????????????????????

?????????????У?????????????????δ??????????????????????????????????????????????????????????????????????

DECLARE
         sql_stat  VARCHAR2(100);
         v_date    DATE :=&dt;      --???????????????δ???????
         v_empno   NUMBER :=7900;
         v_ename   tb_emp.ename%TYPE;
         v_sal     tb_emp.sal%TYPE;
        
       BEGIN
         sql_stat := 'SELECT ename??sal FROM tb_emp WHERE hiredate=:v_date';    --??????λ??:v_date???б?????
                 
         EXECUTE IMMEDIATE sql_stat
         INTO v_ename??v_sal
         USING v_date;
         DBMS_OUTPUT.PUT_LINE('Employee Name '||v_ename||'?? sal is '||v_sal);
       END;
 
       Enter value for dt: 1981-05-01              --?????????????????δ?????????????????????
       old   3:   v_date    DATE :=&dt;
       new   3:   v_date    DATE :=1981-05-01;
         v_date    DATE :=1981-05-01;
                        *
       ERROR at line 3:
       ORA-06550: line 3?? column 20:
       PLS-00382: expression is of wrong type
       ORA-06550: line 3?? column 13:
       PL/SQL: Item ignored
       ORA-06550: line 13?? column 9:
       PLS-00320: the declaration of the type of this expression is incomplete or malformed
       ORA-06550: line 11?? column 3:
       PL/SQL: Statement ignored

??????????

?????????????????????

flasher@ORCL> /
Enter value for dt: '1981-05-01'
old   3:   v_date    DATE :=&dt;
new   3:   v_date    DATE :='1981-05-01';
Employee Name BLAKE?? sal is 2850

PL/SQL procedure successfully completed.

???????????

?????????????????????????????

v_date    DATE :='&dt';

?????????????????????????????????????????

v_date    DATE :=TO_DATE('&dt'??'DD-MON-RR');

?????????????????У????SQL?????e?????????????????????????????????????????????????

DECLARE
         sql_stat  VARCHAR2(100);
         v_date    DATE :='&dt';
         v_empno   NUMBER :=7900;
         v_ename   tb_emp.ename%TYPE;
         v_sal     tb_emp.sal%TYPE;
        
       BEGIN
         sql_stat := 'SELECT ename??sal FROM tb_emp WHERE hiredate=' || chr(39) ||v_date|| chr(39);--chr(39)?????????
         EXECUTE IMMEDIATE sql_stat
         INTO v_ename??v_sal;
         DBMS_OUTPUT.PUT_LINE('Employee Name '||v_ename||'?? sal is '||v_sal);
       END;
 
       Enter value for dt: 1981-05-01
       old   3:   v_date    DATE :='&dt';
       new   3:   v_date    DATE :='1981-05-01';
       SELECT ename??sal FROM tb_emp WHERE hiredate='1981-05-01'
       Employee Name BLAKE?? sal is 2850
 
       PL/SQL procedure successfully completed.