0

I'm currently making a package to use grants as a safegaurd, I want to make a search procedure that searches for rows that contain a name/value column like bellow:

PROCEDURE "SEARCH"(P_COLUMN IN VARCHAR2(30), P_VALUE IN MYTABLE.{P_COLUMN}%TYPE, 
                   P_REFCUR OUT SYS_REF_CURSER) IS
-- VARIABLES DECLARATION
BEGIN
    -- SOME LOGIC FOR VALIDATION
    OPEN P_REFCUR FOR
        SELECT * FROM MYTABLE WHERE {P_COLUMN} = P_VALUE;
END "SEARCH";

How can I define the P_VALUE's type in procedure's signature and create the where clause where the column (P_COLUMN) is a variable string.

1 Answer 1

0

Simply put your command into quotes. Apart from that you should use bind variables.

OPEN P_REFCUR FOR
    'SELECT * FROM MYTABLE WHERE '||P_COLUMN||' = :val' USING P_VALUE;

And remove any curling brackets {}, they are not used in Oracle PL/SQL.

1
  • Thanks a lot! It will be great to know if it is possible to use a trick in procedure signature too. I already defined P_VALUE IN VARCHAR2 as many types can be cast from VARCHAR2.
    – Tala
    Nov 11, 2014 at 13:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.