PL/SQL process: issue with wording

柔情痞子 提交于 2019-12-02 09:37:21

There are multiple issues with your procedure.

  1. You are missing the CREATE keyword, and that's the root cause for the compile time error. PLS-00103.

See the documentation for more details on CREATE PROCEDURE statement to create a standalone stored procedure or a call specification.

EMP_USERNAME IN EMPLOYEE

  1. The data type declaration for the IN parameter is incorrect. You need to do it as:
EMP_USERNAME IN EMPLOYEE.EMP_USERNAME%TYPE
  1. The FOR LOOP is syntactically incorrect.

FOR indx IN NVL (EMP_USERNAME.FIRST, 0) .. NVL (EMP_USERNAME.LAST, -1)

You could do it as:

SQL> CREATE OR REPLACE
  2  PROCEDURE deploy_emp(
  3      i_emp emp.empno%type)
  4  IS
  5    emp_user VARCHAR2(50);
  6  BEGIN
  7    FOR indx IN
  8    (SELECT ename FROM emp
  9    )
 10    LOOP
 11      BEGIN
 12        BEGIN
 13          SELECT ename INTO emp_user FROM emp WHERE empno = i_emp;
 14        EXCEPTION
 15        WHEN NO_DATA_FOUND THEN
 16          emp_user := NULL;
 17        END;
 18      END;
 19    END LOOP;
 20    dbms_output.put_line(emp_user);
 21  END deploy_emp;
 22  /

Procedure created.

SQL> sho err
No errors.

Now, let's test it and see:

SQL> set serveroutput on
SQL> EXEC deploy_emp(7369);
SMITH

PL/SQL procedure successfully completed.

SQL>

use CREATE PROCEDURE to create a new stored procedure or EXEC <proc name> to execute it

If you whant do all this in a page process, you don't need to create procedure. Put this code in the source of your page process:

BEGIN
  FOR indx IN (
    select *
     from EMPLOYEE
  ) LOOP
      APEX_UTIL.CREATE_USER(
        p_user_name    => indx.EMP_USERNAME,
        p_web_password => indx.EMP_PASSWORD,
        p_user_group => indx.EMP_GROUP,
      );
  END LOOP;
END;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!