2010-07-08 157 views

回答

3

您將需要使用動態SQL來構建相應的查詢參數如下:

PROCEDURE myproc (p1 VARCHAR2) IS 
    l_sql LONG; 
    l_cursor SYS_REFCURSOR; 
BEGIN 
    l_sql := 'SELECT a, b, c FROM table1'; 
    IF p1 IS NOT NULL THEN 
     l_sql := l_sql || ' JOIN table2 ON table2.x = table1.x'; 
    END IF; 
    l_sql := l_sql || ' WHERE table1.y = :bind1'; 
    OPEN l_cursor FOR l_sql USING 123; 
    ... 
END; 
相關問題