当前位置: 首页 > news >正文

替换全库关键字procedure

create or replace procedure STR_REPLACE_ALL(oldStr in varchar2,newStr in varchar2) is

TABLE_NAME VARCHAR2(45);--表名

COLUMN_NAME VARCHAR2(100);--字段名

SQL_STR VARCHAR2(200);--动态执行的SQL

type cur_type is ref cursor;--定义游标类型

cursor_columns cur_type;--查询字段游标

cursor cursor_tables is--查询表游标

select table_name from user_tables;

begin

open cursor_tables;

loop

--遍历所有的数据库表

fetch cursor_tables into TABLE_NAME;

exit when cursor_tables%notfound;

DBMS_OUTPUT.put_line(TABLE_NAME);

--遍历当前表所有字符型字段

SQL_STR := 'select COLUMN_NAME from user_tab_columns where TABLE_NAME='''||TABLE_NAME||''' and DATA_TYPE in (''CHAR'',''VARCHAR2'')';

open cursor_columns for SQL_STR;

loop

fetch cursor_columns into COLUMN_NAME;

exit when cursor_columns%notfound;

--DBMS_OUTPUT.put_line('---'||COLUMN_NAME);

--替换更新当前字段

SQL_STR := 'update '||TABLE_NAME||' set '||COLUMN_NAME||' =replace('||COLUMN_NAME||','''||oldStr||''','''||newStr||''')';

--DBMS_OUTPUT.put_line(SQL_STR);

EXECUTE IMMEDIATE SQL_STR;

commit;

end loop;

end loop;

end STR_REPLACE_ALL;

http://www.sczhlp.com/news/9231/

相关文章:

  • 安装MySQL
  • 银河麒麟OS安装Oracle
  • OI集训 Day25
  • 3
  • Linux 配置jdk
  • Selenium三大等待机制深度解析:从原理到实战(小白也能懂)
  • Keepalived 部署主备切换
  • 软工8.10
  • [Python][Go]比较两个JSON文件之间的差异
  • 2012年9月安全公告网络研讨会问答与幻灯片集锦
  • rsync——备机说明
  • Luogu P3029 [USACO11NOV] Cow Lineup S
  • 8.10总结
  • 1960 - 2021 年全国气象数据分享
  • 实用指南:Apache Ignite Data Streaming 案例 StreamWords
  • 后缀数组 SA
  • Day39
  • 深度Ritz方法的全面误差分析
  • 给自己放假一天吧
  • matlab draw curves with shadows
  • 牛客周赛 Round 104
  • 「学习笔记」tarjan
  • 题解:CF1720E Misha and Paintings
  • tryhackme--Anonymous靶场wp
  • 记录Linux下beep命令不发声
  • 5335 | CASIO卡西欧官方网站
  • 基于Flask + Vue3 的新闻数据分析平台源代码+数据库+采用说明,爬取今日头条新闻数据,采集与清洗、数据分析、建立数据模型、数据可视化
  • Java创建图形化界面
  • 前端常见面试题
  • 升级openssh以及openssl