3
A
回答
6
做試試這個:
declare p_count NUMBER;
select count(1) int p_count
from ALL_TAB_COLUMNS
where OWNER = '<SCHEMA_NAME>'
and TABLE_NAME = '<TABLE_NAME>'
and COLUMN_NAME = '<COLUMN_NAME>';
IF p_count = 0 THEN
--add your column
END IF;
最終(根據權限)可以使用user_tab_columns
。
+1
pl/sql語法不正確。 如果沒有BEGIN,則不能使用DECLARE –
1
直視USER_TAB_COLUMNS表來檢查列上存在,並相應地
2
如果您只是想添加一列,如果它不存在,只需發出一個ALTER TABLE ADD (mycolumn ...);
。如果語句引發異常(ORA-01430: column being added already exists in table
),則列已經存在,您可以忽略該異常。
2
或者,您也可以忽略錯誤:
declare
column_exists exception;
pragma exception_init (column_exists , -01430);
begin
execute immediate 'ALTER TABLE db.tablename ADD columnname NVARCHAR2(30)';
exception when column_exists then null;
end;
/
的
相關問題
- 1. 如果不存在則表
- 2. Python - 如果列表元素不存在則排除變量
- 3. 如果存在SQL,則更改列
- 4. 如果列表項存在不追加,但改變FONTCOLOR
- 5. 如果搜索結果不存在,則隱藏表格
- 6. 如何修改表格以放置列(如果存在)?
- 7. 如何更改表添加列如果列不存在於cassadra?
- 8. 檢查列是否已經存在,如果不是,則在sqlite中更改表
- 9. 如果存在行,則更新列,如果不存在則插入行
- 10. 如果值有變化,則更改表格字段顏色
- 11. 如果表格不存在,則循環跳過
- 12. 如果記錄不存在,則插入表格
- 13. 如果密鑰存在於散列中,則改變散列的值
- 14. Python:如果列表中不存在文件,則創建文件
- 15. 改變則selectedItem的風格在列表框中
- 16. PHP如果表格表格行存在
- 17. Google電子表格:如果存在一個或多個文本變量,則更改單元格顏色
- 18. 如果存在空格,則表示標題爲Nowrap表頭,但如果這會打破布局,則不會。
- 19. 如何動態創建表格並在列不存在時更改表格
- 20. 如果變量不在列表
- 21. 如果列不存在,Mysql會選擇另一個表格
- 22. 如果變量不存在?
- 23. 條件格式:如果存在文本,則突出顯示列
- 24. 如果表不存在,則在另一個表上選擇
- 25. 如果不存在,則追加。如果存在,增加計數
- 26. 如何使用正則表達式,如果輸出格式改變
- 27. 的javascript:如果用戶名存在,則無法提交表格
- 28. MySQL - 如果存在特定值,則加入表格並添加
- 29. Amazon Redshift:如果存在表格,則丟棄
- 30. 如果存在值,則顯示錶格行
可能重複[?如何檢查是否列在PL/SQL將它添加到現有的表之前存在(http://stackoverflow.com/questions/6351823 /如何檢查是否存在先於將其添加到現有表中的pl-sql) –