Pages

Wednesday, February 19, 2014

PL/SQL Reference. Useful Commands, Examples.

========================
GENERAL
========================
SELECT INTO Multiple Columns
UPDATE Multiple Columns
How to see Procedure Code
How to see Package Body and Declaration
How to compile Package Body and Declaration
How to see Compilation Errors
How to see Compilation Date
Error PLS-00904: insufficient privilege to access object package


SELECT INTO Multiple Columns

SELECT col_a, col_b, col_c
  INTO var_a, var_b, var_c
FROM MY_TABLE

WHERE col_d = val_d;

UPDATE Multiple Columns

UPDATE MY_TABLE
  SET col_a = val_a,
      col_b = val_b,
      col_c = val_c
WHERE 
col_d = val_d;


How to see Procedure Code

SELECT text
FROM USER_SOURCE

WHERE NAME = 'MY_PROCEDURE'
  AND TYPE = 'PROCEDURE'
ORDER BY LINE;

How to see Package Body and Declaration

SET HEADING OFF
SET PAGESIZE 999
SET LINESIZE 120
SPOOL my_package;

SELECT *
FROM USER_SOURCE

WHERE NAME = 'MY_PACKAGE'
  AND TYPE = 'PACKAGE'
ORDER BY LINE;

SELECT *
FROM USER_SOURCE

WHERE NAME = 'MY_PACKAGE'
  AND TYPE = 'PACKAGE BODY'
ORDER BY LINE;

How to compile Package Body and Declaration
ALTER PACKAGE MY_PACKAGE COMPILE SPECIFICATION;
ALTER PACKAGE MY_PACKAGE COMPILE BODY;

How to see Compilation Errors
SELECT * FROM USER_ERRORS;

How to see Compilation Date

SELECT last_ddl_time
FROM USER_OBJECTS

WHERE object_name = 'MY_PROCEDURE'
  AND object_type = 'PROCEDURE'
ORDER BY last_ddl_time;

Error PLS-00904: insufficient privilege to access object package
To execute a procedure or function, you must be the owner, have the EXECUTE privilege for the procedure or function (or for the package to which it belongs, if applicable), or have the EXECUTE ANY PROCEDURE privilege.

If the procedure is part of a package, the GRANT is for the whole package! 
It is not possible to grant execute permission for just one procedure inside a package.

As Procedure owner, run:
GRANT EXECUTE ON MY_USER.MY_PROCEDURE TO SOME_USER;

As Package owner, run:
GRANT EXECUTE ON MY_USER.MY_PACKAGE TO SOME_USER

No comments:

Post a Comment