我有Sql Queries,由于它会影响程序包的性能。 ln_trans_type_id是声明的变量。
UPDATE invoice_table xai
SET process_flag = 'E',
error_description = 'Invoice Number Does not Exists '
WHERE xai.process_flag = 'N'
AND NOT EXISTS (
SELECT 1
FROM ra_customer_trx_all rct
WHERE rct.org_id = 1001
AND rct.trx_number = xai.invoice_number
AND rct.cust_trx_type_id = ln_trans_type_id
);
请检查并提出建议。
答案 0 :(得分:0)
如果您在包中声明一个变量(如tempVar
),并稍后传递以进行更新
SELECT 1 into tempVar FROM
ra_customer_trx_all rct , invoice_table xai
WHERE rct.org_id = 1001 AND rct.trx_number = xai.invoice_number AND rct.cust_trx_type_id = ln_trans_type_id
答案 1 :(得分:0)
没有执行计划,我们只能猜测。您应该将性能与NOT IN进行比较,但要确保子查询不返回任何NULL值,否则您将不会获得任何匹配。
UPDATE invoice_table xai
SET process_flag = 'E',
error_description = 'Invoice Number Does not Exists '
WHERE xai.process_flag = 'N'
AND xai.invoice_number
NOT IN (
SELECT rct.trx_number
FROM ra_customer_trx_all rct
WHERE rct.org_id = 2326
AND rct.trx_number is not null -- important!
AND rct.cust_trx_type_id = ln_trans_type_id
);