2014-02-25 60 views
0

我對plpgsql有synatx問題。我想要做的就是用我的論點作爲if語句的條件。我想將過程合併爲一個過程。plpgsql在if語句中傳遞參數

CREATE OR REPLACE FUNCTION fn_name(arg1 int, arg2 date) 
returns text as 

$body$ 

DECLARE 

arg1 integer; 
arg2 date; 

Begin 
--where I am having the issue 

IF EXISTS (%,'%', arg1, arg2) 
    THEN 
    INSERT INTO some_table.table 
END IF; 

RETURN 'complete'; 
END; 
$body$ 
LANGUAGE plpgsql VOLATILE 

當我知道我有一個問題

IF EXISTS (%,'%', arg1, arg2) 
    THEN 

是否有這樣做的更清潔的方式,或者說,得到這個正常工作?

+0

你得到什麼錯誤? –

+0

錯誤:「%」處或附近的語法錯誤 –

+0

您在代碼中缺少BEGIN –

回答

0

也許你要檢查這些參數,如果他們是通過null

IF arg1 is not null and arg2 is not null THEN 
    --INSERT instruction 
END IF; 
+0

這絕對會訣竅。我仍然用本土語言表達自己的看法。謝謝! –