我正在尝试在Oracle APEX 4.1中创建页面进程。具体来说,当此页面上的按钮正在处理提交页面时,我希望此PL / SQL查询能够正常工作。我对PL / SQL没有多少了解,我正在寻找如何解决这个问题。
我希望查询执行的操作:
我希望这个页面进程循环遍历EMPLOYEE表中我在APEX数据库中的每一行。对于每一行,我想将用户名,组和密码移动到它们自己的变量中,然后使用APEX_UTIL_CREATE_USER进程创建APEX用户。我希望这与表中的每个员工一起完成。
我并不清楚这个PL / SQL有什么问题,因为我以前从未使用它。我非常感谢任何人都可以给我这个帮助。我将在下面显示查询和错误消息。
PL / SQL查询:
PROCEDURE deploy_employee
(EMP_USERNAME IN EMPLOYEE)
IS
BEGIN
FOR indx IN NVL (EMP_USERNAME.FIRST, 0)
.. NVL (EMP_USERNAME.LAST, -1)
LOOP
emp_user EMPLOYEE.EMP_USERNAME%TYPE;
emp_pass EMPLOYEE.EMP_PASSWORD%TYPE;
emp_group EMPLOYEE.EMP_GROUP%TYPE;
BEGIN
BEGIN
select EMP_USERNAME into emp_user from EMPLOYEE;
select EMP_PASSWORD into emp_pass from EMPLOYEE;
select EMP_GROUP into emp_group FROM EMPLOYEE;
EXCEPTION
WHEN NO_DATA_FOUND THEN
emp_user := NULL;
emp_pass := NULL;
emp_group := NUL;
END;
APEX_UTIL.CREATE_USER(
p_user_name => emp_user,
p_web_password => emp_pass,
p_user_group => emp_gorup,
);
END;
END LOOP;
END deploy_employee;
错误讯息:
1 error has occurred ORA-06550: line 2, column 1: PLS-00103:
Encountered the symbol "PROCEDURE" when expecting one of the
following: ( begin case declare end exception exit for goto if loop
mod null pragma raise return select update while with <an identifier>
<a double-quoted delimited-identifier> <a bind variable> << continue
close current delete fetch lock insert open rollback savepoint set sql
execute commit forall merge pipe purge The symbol "declare" was
substituted for "PROCEDURE" to continue. ORA-065
页码为2.
我再次非常感谢我能获得的任何帮助。
答案 0 :(得分:2)
您的手术存在多个问题。
PLS-00103
。有关CREATE PROCEDURE statement创建独立存储过程或调用规范的更多详细信息,请参阅文档。
员工中的EMP_USERNAME
EMP_USERNAME IN EMPLOYEE.EMP_USERNAME%TYPE
FOR indx IN NVL(EMP_USERNAME.FIRST,0).. NVL(EMP_USERNAME.LAST,-1)
你可以这样做:
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.
现在,让我们测试一下,看看:
SQL> set serveroutput on
SQL> EXEC deploy_emp(7369);
SMITH
PL/SQL procedure successfully completed.
SQL>
答案 1 :(得分:0)
使用CREATE PROCEDURE
创建新的存储过程或EXEC <proc name>
执行它
答案 2 :(得分:0)
如果您在页面处理中执行了所有操作,则无需创建过程。将此代码放在页面流程的源代码中:
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;