2017-10-26 3 views
0

Ich habe eine procedure A, die als Parameter eine Select-Anweisung übernimmt, aber ich möchte, dass meine Auswahl dynamisch sein.Oracle Plsql dynamische wählen Sie als Parameter

Proc A (query); 


Proc B is 
Declare 
-- try 1 using variables 
q varchar2(200):= 'select xy from table where col =' || var ; 

-- try 2 using bind 
q varchar2(200):= 'select xy from table where col = :v' ; 

Begin 

-- here i want to be able to define a variable based on certain conditions and my string q will take the variable. 

A(q); 

End; 

Ist das möglich? Kann jemand bitte helfen?

+0

Schauen Sie sich einfach "Related" Abschnitt auf der rechten Seite dieser Seite. Sie werden viele solche Antworten finden, die Ihnen helfen werden. –

Antwort

1
CREATE OR REPLACE PROCEDURE Proc_A (in_query varchar) 
IS 
BEGIN 
    execute immediate in_query; 
END; 
/

CREATE OR REPLACE PROCEDURE Proc_B 
IS 
    col_val varchar2(60) := 'Lady Gaga'; 
    q varchar2(200):= 'select * from test_table where char_col =''' || col_val || ''''; 
Begin 
    Proc_A(q); 
End; 
/

begin 
    Proc_B; 
end; 

Aber offensichtlich für Auswahlen müssen Sie die Ergebnismenge abholen. DMLs (einfügen/löschen/...) funktionieren wie beschrieben.