我需要动态添加where子句参数。
GETRESULTSET:='SELECT PARENT_PARTYID,PARTY_ID,PRODUCT_ID,PRODUCT_STATUS,BILLING_TYPE,CRMTIMESTAMP,UPDATEDTIMESTAMP,UPDATEDBY FROM ENT_MAP_CUST_PRODUCT WHERE PARENT_PARTYID=:PARENT_PARTYID';
IF(PRODUCT_ID IS NOT NULL) THEN
GETRESULTSET := GETRESULTSET || ' AND PRODUCT_ID=:PRODUCT_ID ';
END IF;
IF(PRODUCT_STATUS IS NOT NULL) THEN
GETRESULTSET := GETRESULTSET || ' AND PRODUCT_STATUS=:PRODUCT_STATUS ';
END IF;
IF(BILLING_TYPE IS NOT NULL) THEN
GETRESULTSET := GETRESULTSET || ' AND BILLING_TYPE=:BILLING_TYPE ';
END IF;
现在我需要批量收集到集合类型:
execute immediate GETRESULTSET bulk collect into V_PARTY_TBL USING <<>> ?
现在在运行时我不知道where子句的形成,所以如何在USING
语句的execute immeditate
子句中处理它。
答案 0 :(得分:2)
添加一个包含所有三个参数的where子句:
and (PRODUCT_ID IS NULL or PRODUCT_ID=:PRODUCT_ID )
and (PRODUCT_STATUS IS NULL or PRODUCT_STATUS=:PRODUCT_STATUS)
and (BILLING_TYPE IS NULL or BILLING_TYPE=:BILLING_TYPE)
然后
execute immediate your_query
into your_result
using p_product_id,
p_product_status,
p_billing_type;
答案 1 :(得分:0)
添加永久参数集的最简单方法:
def execFiles(files):
for file_name in files:
exec(open(file_name).read())
>>> execFiles(["a.py", "b.py", "c.py"])
但通常你的任务表明你更喜欢错误的方式。您正在尝试全程采购&#39;接近并面临其中一个令人讨厌的缺点。