0
A
回答
6
你可以做這樣的事情:
DECLARE v_exist PLS_INTEGER;
BEGIN
SELECT COUNT(*) INTO v_exist
FROM user_tables
WHERE table_name = 'YOURTABLEHERE';
IF v_exist = 1 THEN
EXECUTE IMMEDIATE 'DROP TABLE YOURTABLEHERE';
END IF;
1
像
select count(*) from user_tables
where table_name= :table name
或
select count(*) from dba_tables
where owner = :table owner
and table_name = :table name
或嚴厲的選擇:
begin execute immediate 'drop table table_name';
exception when others then null;
end;
1
我一直在使用以下步驟來照顧這:
create or replace procedure drop_table_if_exists (p_table_name varchar2)
is
it_exist number;
begin
select count(*)
into it_exists
from user_tables
where table_name = p_table_name
;
if it_exists >= 1 then
execute immediate 'drop table '||p_table_name;
end if;
end;
/
exec drop_table_if_exists ('TABLE_TO_DROP');
4
DECLARE
eTABLE_OR_VIEW_DOES_NOT_EXIST EXCEPTION;
PRAGMA EXCEPTION_INIT(eTABLE_OR_VIEW_DOES_NOT_EXIST, -942);
BEGIN
EXECUTE IMMEDIATE 'DROP TABLE SCHEMA.WHATEVER';
EXCEPTION
WHEN eTABLE_OR_VIEW_DOES_NOT_EXIST THEN
NULL;
END;
分享和享受。
相關問題
- 1. 我想一個錶行從舊錶移動到另一個,並刪除該行
- 2. 當我刪除一個鏈表時,得到一個錯誤的輸出
- 3. 我想刪除幾個SQLite表(不刪除)並得到確認
- 4. Python的索引到一個列表,並得到一個錯誤,我不應該得到
- 5. 我刪除了一個文件,並且Xcode給出了一個鐺錯誤
- 6. 錯誤,當我從一個鏈表中刪除一個節點
- 7. 我得到一個錯誤
- 8. 我得到一個錯誤
- 9. 我得到一個編譯錯誤:6不在列表中
- 10. Postgresql:創建一個表並刪除(如果存在)
- 11. 返回一個錯誤並且不刪除條目
- 12. FireDAC TFDScript錯誤試圖刪除一個不存在的表
- 13. 我在cmd上得到一個錯誤,即build.xml不存在
- 14. 我得到在一個「如果」語句syntaxt錯誤,而在pythoneverywhere.com
- 15. 我一直得到一個-1700錯誤
- 16. 我得到一個SQL錯誤在PHP
- 17. 我得到一個錯誤,在PHP
- 18. 我得到一個錯誤,當我嘗試在泊塢窗刪除圖像
- 19. 當我不應該得到一個值錯誤
- 20. 我應該刪除一個版本,如果它有很大的錯誤?
- 21. 我已經安裝了Maven 3.2.3,並且我試圖導入一個項目到eclipse。我得到這個錯誤
- 22. 通知正在被刪除,如果我從我自己得到一個新的
- 23. 我得到一個錯誤,我不知道如何解決它
- 24. 刪除工作表(如果它存在並製作一個新工作表)
- 25. 你如何刪除一個mysql表如果表名存儲爲一個變量?
- 26. 我得到一個不是一個聲明錯誤
- 27. 我得到一個「這不是一個函數」錯誤
- 28. 我有一個解析錯誤,我不能得到我的頭
- 29. 刪除列表項,如果不在另一個列表中 - python
- 30. 將兩個列表合併在一起,並且如果它存在於另一個值上,則取一個值
existing = exists – Hogan 2010-01-12 21:52:58
獲取錯誤不是世界的盡頭 - 如果表不存在,您可以使用異常處理程序處理錯誤。 – 2010-01-13 06:30:50
[Oracle:If Table Exists]的可能重複(http://stackoverflow.com/questions/1799128/oracle-if-table-exists) – 2012-06-27 04:44:10