oracle 將表名和字段名變為大寫


文章目錄

  • 前言
  • 一、批量將表名變為大寫
  • 二、批量將空間內所有表的所有字段名變成大寫
  • 三、將用戶空間的所有表名及所有字段變為大寫
  • 前言

    當使用powerdesigner創建數據庫時要注意大小寫。
    注:以下腳本在oracle 10g,11g上正確執行

    一、批量將表名變為大寫

     1 begin
     2    for c in (select table_name tn from user_tables where table_name <> upper(table_name)) loop
     3        begin
     4           execute immediate 'alter table "'||c.tn||'" rename to '||c.tn;
     5        exception
     6           when others then
     7              dbms_output.put_line(c.tn||'已存在');
     8        end;
     9    end loop; 
    10 end;

     

  • 二、批量將空間內所有表的所有字段名變成大寫

  •  1 begin
     2   for t in (select table_name tn from user_tables) loop
     3       begin
     4          for c in (select column_name cn from user_tab_columns where table_name=t.tn) loop
     5              begin
     6                 execute immediate 'alter table "'||t.tn||'" rename column "'||c.cn||'" to '||c.cn;
     7              exception
     8                 when others then
     9                    dbms_output.put_line(t.tn||'.'||c.cn||'已經存在');
    10              end;
    11          end loop;
    12       end;
    13   end loop; 
    14 end;

    三、將用戶空間的所有表名及所有字段變為大寫

  •  1 begin
     2    for t in (select table_name tn from user_tables where table_name <> upper(table_name)) loop
     3        begin
     4           for c in (select column_name cn from user_tab_columns where table_name=t.tn) loop
     5               begin
     6                  execute immediate 'alter table "'||t.tn||'" rename column "'||c.cn||'" to '||c.cn;
     7               exception
     8                  when others then
     9                     dbms_output.put_line(t.tn||'.'||c.cn||'已經存在');
    10               end;
    11           end loop;
    12       
    13           execute immediate 'alter table "'||t.tn||'" rename to '||t.tn;
    14           exception
    15              when others then
    16                 dbms_output.put_line(t.tn||'已存在');
    17        end;
    18    end loop; 
    19 end;

     


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM