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、如果不重要可以直接删除表空间,重新创建

tab_xn_ddd 详细X

没有英汉互译结果 请尝试网页搜索