Du kan bruge dynamiske markører til at udføre dynamisk SQL kompileret fra en VARCHAR2-variabel:
DECLARE
w_sql VARCHAR2 (4000);
cursor_ INTEGER;
v_f1 NUMBER (6);
v_f2 NUMBER (2);
v_some_value_2_filter_4 NUMBER (2);
rc INTEGER DEFAULT 0;
BEGIN
-- join as many tables as you need and construct your where clause
w_sql :='SELECT f1, f2 from TABLE1 t1, TABLE2 t2, ... WHERE t1.f1 =' || v_some_value_2_filter_4 ;
-- Open your cursor
cursor_ := DBMS_SQL.open_cursor;
DBMS_SQL.parse (cursor_, w_sql, 1);
DBMS_SQL.define_column (cursor_, 1, v_f1);
DBMS_SQL.define_column (cursor_, 2, v_f2);
-- execute your SQL
rc := DBMS_SQL.EXECUTE (cursor_);
WHILE DBMS_SQL.fetch_rows (cursor_) > 0
LOOP
-- get values from record columns
DBMS_SQL.COLUMN_VALUE (cursor_, 1, v_f1);
DBMS_SQL.COLUMN_VALUE (cursor_, 2, v_f2);
-- do what you need with v_f1 and v_f2 variables
END LOOP;
END;
Eller du kan bruge udfør omgående , nemmere at implementere, hvis du blot skal kontrollere en værdi eller udføre og indsætte/opdatere/slette forespørgsel
w_sql :='select f1 from table where f1 = :variable';
execute immediate w_sql into v_f1 using 'valor1'
Her mere info om dynamiske markører:http://docs. oracle.com/cd/B10500_01/appdev.920/a96590/adg09dyn.htm