(PL/SQL-DDL) DBMS_SQL.PARSE, Execute Immediate Insufficient Privileges
(SQL -DDL) DBMS_SQL.PARSE, Execute Immediate Insufficient Privileges
In PL/SQL block (Oracle 9i) I am trying to execute a DDL statement 'create view...' the part of the code given below (Code-1)
PROBLEM:
-------
When I compile Code-1 PL/SQL block to generate the procedure - it gets compiled properly and procedure gets generated. However when I try to execute the procedure using :
SQL> EXECUTE CALCULATE_COMMISSION(101);
... it give an error of insufficient privileges. I had tried using EXECUTE IMMEDIATE --- same error message was displayed.
Exception:
---------
I was surprised because when I made an anonymous block given below(Code-2) It works fine and I get the desired results. However I want to use procedure - becuase I need to call if from forms!
Code-1 (Named Block - Procedure)
================================
CREATE OR REPLACE PROCEDURE CALCULATE_COMMISSION
(empid IN employees.employees_id%TYPE)
IS
i NUMBER;
cursor_test INTEGER;
BEGIN
cursor_test := DBMS_SQL.OPEN_CURSOR;
DBMS_SQL.PARSE(cursor_test, ' CREATE OR REPLACE VIEW emp_htree
AS
SELECT employee_id, manager_id, level "LEVEL_ID"
FROM employees
START WITH employee_id='||to_char(empid)||'
CONNECT BY PRIOR manager_id=employee_id',
DBMS_SQL.NATIVE);
i := DBMS_SQL.EXECUTE(cursor_test);
DBMS_SQL.CLOSE_CURSOR(cursor_test);
/* .....the calculation code
...
...
*/
END;
Code-2 (Anonymous PL/SQL Block)
===============================
DECLARE
i NUMBER;
cursor_test INTEGER;
BEGIN
cursor_test := DBMS_SQL.OPEN_CURSOR;
DBMS_SQL.PARSE(cursor_test, ' CREATE OR REPLACE VIEW emp_htree
AS
SELECT employee_id, manager_id, level "LEVEL_ID"
FROM employees
START WITH employee_id='||&a||'
CONNECT BY PRIOR manager_id=employee_id',
DBMS_SQL.NATIVE);
-- a is a bind variable in this block
i := DBMS_SQL.EXECUTE(cursor_test);
DBMS_SQL.CLOSE_CURSOR(cursor_test);
/* .....the calculation code
...
...
*/
END;