错误方式:[注 S1='12','22','31' S2='K','Z' ]
CREATE OR REPLACE FUNCTION FUN_TEST(S1 VARCHAR2,
S2 VARCHAR2)
RETURN VARCHAR2 IS
RETRUEN_STR VARCHAR2(4000); -- 最终返回的字符
V_SQL VARCHAR2(1000); -- 生成的SQL
BEGIN
SELECT WM_CONCAT(T.AS1) INTO RETRUEN_STR
FROM TABLE1 T
WHERE T.AA01 IN (S1) AND T.BB01 IN (S2 )';
EXECUTE IMMEDIATE V_SQL
INTO RETRUEN_STR;
RETURN RETRUEN_STR;
END FUN_TEST;
-------------------------------------------------------------------------------
变量不可以直接放在sql语句中作为条件后的参数,需要将变量和sql进行拼接,然后再执行拼接后的语句,如下:
正确方式:
CREATE OR REPLACE FUNCTION FUN_TEST(S1 VARCHAR2,
S2 VARCHAR2)
RETURN VARCHAR2 IS
RETRUEN_STR VARCHAR2(4000); -- 最终返回的字符
V_SQL VARCHAR2(1000); -- 生成的SQL
BEGIN
V_SQL := 'SELECT WM_CONCAT(T.AS1)
FROM TABLE1 T
WHERE T.AA01 IN (' || S1 ||
') AND T.BB01 IN (' || S2 || ')';
EXECUTE IMMEDIATE V_SQL
INTO RETRUEN_STR;
RETURN RETRUEN_STR;
END FUN_TEST;