0

我想编写一个程序来执行以下删除

i want to delete from x_table and y_table where id=select id from z_table where obj_id="1234" also at the same time i want to delete 
from user_table id = select id from z_table where obj_id="1234" and user_id != in (select user id from main_table)

in short i want to delete the rows from 3 tables x_table,y_table and user_table for the given obj_id and for user_table i want to alsocheck if user_id is not in other main_table
4

1 回答 1

1

试试这个过程。请注意,这是记事本认证的版本 :) 我没有在 Oracle 上编译它,因为我的个人机器上没有它。看看有没有效果。。

CREATE
OR REPLACE PROCEDURE testproc(inputVar IN number)

AS

BEGIN

EXECUTE IMMEDIATE 'DELETE FROM TABLE_X WHERE ID = (SELECT ID FROM TABLE_Z WHERE OBJ_ID=:num)' USING IN inputVar;

EXECUTE IMMEDIATE 'DELETE FROM TABLE_Y WHERE ID = (SELECT ID FROM TABLE_Z WHERE OBJ_ID=:num)' USING IN inputVar;

EXECUTE IMMEDIATE 'DELETE FROM TABLE_USER WHERE ID = (SELECT ID FROM TABLE_Z WHERE OBJ_ID=:num) AND USER_ID NOT IN (SELECT USER_ID FROM MAIN_TABLE)' USING IN inputVar;

COMMIT;

EXCEPTION

WHEN
OTHERS

THEN

dbms_output.put_line
(SQLERRM);

END;
于 2012-06-14T16:13:12.903 回答