我正在使用sqlplus代码和plsql,我在plsql中的程序工作正常,但是当我在sql中执行程序时,我遇到了一些错误报告。 继承我的代码:
set serveroutput on;
DECLARE
ENDDATE DATE;
BEGIN
SELECT SOME_DATE INTO ENDDATE FROM HEADER WHERE ID=1182446;
IF ENDDATE >= TO_DATE('18-MAY-13') THEN
EXECUTE SOMEPROCEDURE(1182446);
END IF;
END;
Error report -
ORA-06550: line 8, column 8:
PLS-00103: Encountered the symbol "SOMEPROCEDURE" when expecting one of the following:
:= . ( @ % ;
The symbol ":=" was substituted for "SOMEPROCEDURE" to continue.
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
答案 0 :(得分:1)
IF ENDDATE >= TO_DATE('18-MAY-13') THEN EXECUTE SOMEPROCEDURE(1182446); END IF;
由于您在匿名PL / SQL块中调用该过程,因此不需要 EXECUTE
命令,因为它是 SQL *加命令而不是PL / SQL。
您只需将程序调用为:
IF ENDDATE >= TO_DATE('18-MAY-13') THEN
SOMEPROCEDURE(1182446);
END IF;
如果您想在 SQL * Plus 中单独执行该程序,则可以使用 EXECUTE 或 EXEC 命令。
例如,
在SQL * Plus中:
SQL> CREATE OR REPLACE
2 PROCEDURE get_emp(
3 emp_no IN emp.empno%type,
4 dept_no OUT emp.deptno%type )
5 AS
6 BEGIN
7 SELECT deptno INTO dept_no FROM emp WHERE empno = emp_no;
8 END;
9 /
Procedure created.
SQL> var dno number
SQL> var eno number
SQL> exec :eno := 7369
PL/SQL procedure successfully completed.
SQL> EXEC get_emp(:eno, :dno);
PL/SQL procedure successfully completed.
SQL> print dno
DNO
----------
20
SQL>
如果你想在另一个PL / SQL块中调用该过程,那么你可以这样做:
匿名PL / SQL块:
SQL> set serveroutput on
SQL> DECLARE
2 dt DATE;
3 dept_no NUMBER;
4 BEGIN
5 SELECT hiredate INTO dt FROM emp WHERE empno = 7369;
6 IF dt < SYSDATE THEN
7 get_emp(7369, dept_no);
8 DBMS_OUTPUT.PUT_LINE('Department number is '||dept_no);
9 END IF;
10 END;
11 /
Department number is 20
PL/SQL procedure successfully completed.