Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

(PL/SQL-DDL) DBMS_SQL.PARSE, Execute Immediate Insufficient Privileges

SudhanshuMay 19 2002 — edited Sep 11 2007
(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;
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 19 2002
Added on May 19 2002
7 comments
1,598 views