oracle–批量刪除部分表,將某一列拼接成字元串
- 2019 年 10 月 10 日
- 筆記
1、查詢要批量刪除的表
SELECT * FROM USER_TABLES
SELECT 'DROP '||'TABLE ' || TABLE_NAME ||' ;' ,1 FROM USER_TABLES WHERE TABLE_NAME LIKE 'T_DIM%';
2、創建臨時表
CREATE TABLE tab_xn_ddd (names varchar2(100),idd number(2));
3、將要刪除的表結果插入到資料庫中
insert into hos_tab_xn_ddd SELECT 'DROP '||'TABLE ' || TABLE_NAME ||' ;' ,1 FROM USER_TABLES WHERE TABLE_NAME LIKE 'T_DIM%';
4、將結果拼接成字元串
select idd, replace(to_char(wm_concat(names)),',','') from hos_tab_xn_ddd group by idd;
5、刪除臨時表
DROP table tab_xn_ddd ;
問題:1、結果沒有使用換行
製表符 chr(9) 換行符 chr(10) 回車符 chr(13)
select ' update ' || table_name || ' set VALID_STATE =''0A'';'||chr(13)||' commit;' from user_tables
2、如果不重要可以直接刪除表空間,重新創建
沒有英漢互譯結果 請嘗試網頁搜索