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 に答える