BEGIN
EXECUTE IMMEDIATE 'drop table mytable1';
EXECUTE IMMEDIATE 'drop table mytable2';
EXECUTE IMMEDIATE 'drop table mytable3';
EXCEPTION
WHEN OTHERS THEN
NULL;
END;
正常工作的最簡單的方法。
如果你問我,應該避免使用exception when others then null
。如果你想檢查一個表是否存在 - 查詢USER_TABLES
DECLARE
V_EXISTS NUMBER;
BEGIN
SELECT 1 INTO V_EXISTS FROM USER_TABLES WHERE TABLE_NAME = 'TEST';
IF V_EXISTS = 1 THEN
EXECUTE IMMEDIATE 'DROP TABLE TEST';
END IF;
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('Table not found');
END;
REGd中:你的評論,如果你仍然想去關於你的問題使用方法,在外面匿名塊把它包
BEGIN
BEGIN
EXECUTE IMMEDIATE 'drop table mytable1';
EXCEPTION
WHEN OTHERS THEN
NULL;
END;
BEGIN
EXECUTE IMMEDIATE 'drop table mytable2';
EXCEPTION
WHEN OTHERS THEN
NULL;
END;
BEGIN
EXECUTE IMMEDIATE 'drop table mytable3';
EXCEPTION
WHEN OTHERS THEN
NULL;
END;
END;
結果:
SQL> BEGIN
2
3 BEGIN
4 EXECUTE IMMEDIATE 'drop table mytable1';
5 EXCEPTION
6 WHEN OTHERS THEN
7 NULL;
8 END;
9
10 BEGIN
11 EXECUTE IMMEDIATE 'drop table mytable2';
12 EXCEPTION
13 WHEN OTHERS THEN
14 NULL;
15 END;
16
17 BEGIN
18 EXECUTE IMMEDIATE 'drop table mytable3';
19 EXCEPTION
20 WHEN OTHERS THEN
21 NULL;
22 END;
23
24 END;
25
26/
PL/SQL procedure successfully completed.
SQL>
'那FO的最簡單方法r我檢查一個表是否存在/不存在於oracle中 - 您可以查詢'USER_TABLES' /'DBA_TABLES' /'ALL_TABLES' – Sathya
另外,爲什麼在存儲過程中使用DDL? – Sathya