--step1 disable constraint
begin
for i in (select uc.constraint_name, uc.table_name from user_constraints uc, all_tables tab where uc.OWNER='xx' and tab.OWNER='xx' and uc.table_name=tab.table_name)
LOOP
begin
execute immediate 'alter table '||i.table_name||' disable constraint '||i.constraint_name||'';
exception
when others then
dbms_output.put_line(i.table_name);
dbms_output.put_line(i.constraint_name);
end;
end loop;
end;
/ --step2: drop index
BEGIN
FOR ind IN
(SELECT ui.index_name FROM user_indexes ui, all_tables tab WHERE ui.TABLE_OWNER='xx' and tab.OWNER='xx' and ui.table_name=tab.table_name and INDEX_TYPE != 'LOB')
LOOP
BEGIN
execute immediate 'DROP INDEX '||ind.index_name;
exception
when others then
dbms_output.put_line(ind.index_name);
END;
END LOOP;
END;
/
COMMIT; --step3 update all coulmn
undefine schema_name;
declare
l_Err varchar2(200);
begin
for r in (select atc.table_name, atc.column_name, atc.data_length
from all_tab_columns atc, all_tables tab WHERE atc.owner=tab.OWNER and atc.table_name=tab.table_name
and atc.data_type = 'VARCHAR2'
and atc.char_used = 'B' --Indicates that the column uses BYTE length semantics (B) or CHAR length semantics (C)
-- and atc.table_name = 'INACTIVE_ACCOUNT' --TEST
and atc.owner = upper('&&schema_name'))
loop
begin
execute immediate 'alter table '|| upper('&&schema_name')
|| '.'
|| r.table_name
|| ' modify '
|| r.column_name
|| ' varchar2('
|| r.data_length
|| ' char)';
end;
commit;
end loop;
end;
/
COMMIT; --step4 create index
please refer in last part --step5 create index - run two times
begin
for i in (select uc.constraint_name, uc.table_name from user_constraints uc, all_tables tab where uc.OWNER='xx' and tab.OWNER='xx' and uc.table_name=tab.table_name)
LOOP
begin
execute immediate 'alter table '||i.table_name||' enable constraint '||i.constraint_name||'';
exception
when others then
dbms_output.put_line(i.constraint_name);
end;
end loop;
end;
/
COMMIT;
begin
for i in (select uc.constraint_name, uc.table_name from user_constraints uc, all_tables tab where uc.OWNER='xx' and tab.OWNER='xx' and uc.table_name=tab.table_name)
LOOP
begin
execute immediate 'alter table '||i.table_name||' enable constraint '||i.constraint_name||'';
exception
when others then
dbms_output.put_line(i.constraint_name);
end;
end loop;
end;
/
COMMIT;

sql for loop的更多相关文章

  1. Oracle PL/SQL之LOOP循环控制语句

    在PL/SQL中可以使用LOOP语句对数据进行循环处理,利用该语句可以循环执行指定的语句序列.常用的LOOP循环语句包含3种形式:基本的LOOP.WHILE...LOOP和FOR...LOOP. LO ...

  2. PL/SQL中LOOP循环控制语句

    在PL/SQL中可以使用LOOP语句对数据进行循环处理,利用该语句可以循环执行指定的语句序列.常用的LOOP循环语句包含3种形式:基本的LOOP.WHILE...LOOP和FOR...LOOP. LO ...

  3. [转载]Oracle PL/SQL之LOOP循环控制语句

    在PL/SQL中可以使用LOOP语句对数据进行循环处理,利用该语句可以循环执行指定的语句序列.常用的LOOP循环语句包含3种形式:基本的LOOP.WHILE...LOOP和FOR...LOOP. LO ...

  4. SQL Server loop - how do I loop through a set of records

    SQL Server loop - how do I loop through a set of records By using T-SQL and cursors like this : DECL ...

  5. pl/sql declare loop if

    -- 1.判断表是否存在,如果存在则drop表 -- 2.创建表 -- 3.插入1W条数据 -- 4.每1K条commit一次 declare v_table ):='STUDENT'; --表名 v ...

  6. PL/SQL块loop..各种循环练习

    --利用loop输出1到100的值并求和 ---loop exit end loop set serveroutput on; declare v_i ; v_sum ; begin loop )th ...

  7. [转]Dynamic SQL & Stored Procedure Usage in T-SQL

    转自:http://www.sqlusa.com/bestpractices/training/scripts/dynamicsql/ Dynamic SQL & Stored Procedu ...

  8. pl/sql tutorial

    http://plsql-tutorial.com/plsql-procedures.htm What is PL/SQL? PL/SQL stands for Procedural Language ...

  9. SQL根据B表内容修改A表内容,查询表中重复记录,删除掉重复项只保留一条

    以下sql是a,b两张表通过关联条件id修改a表值,如果b表有重复数据记录,选第一条更新,红色条件为附加限制条件,具体视情况而定: UPDATE a SETname = b.fname,pwd = b ...

随机推荐

  1. postman与soapui操作

    get和post请求的区别? get请求:直接在浏览器里直接调用就可以了,不用借助工具   向服务端获取数据的    数据是放在url里面 post请求:向服务端发送数据的     数据放在body里 ...

  2. php中美元符号是什么意思

    php中$符号是变量符号: 把$符号加上字符串,这个字符串就是一个变量名或对象名. 其实PHP采用的是C语言的语法,但是也有一些区别,$符号加上字符串,这就是一个变量名或对象名. 例如下面的代码:(推 ...

  3. 【HDOJ6655】Just Repeat(贪心)

    题意:A和B两个人玩游戏,分别有n和m张牌,A的第i张牌是a[i],B是b[i] 两人轮流出牌,如果一种编号的牌被其中一个人出了另一个人就不能出自己手中这个编号的牌 两人都按最优策略行动,问获胜者 思 ...

  4. hud 4347 The Closest M Points(KD-Tree)

    传送门 解题思路 \(KD-Tree\)模板题,\(KD-Tree\)解决的是多维问题,它是一个可以储存\(K\)维数据的二叉树,每一层都被一维所分割.它的插入删除复杂度为\(log^2 n\),它查 ...

  5. 学习笔记11 EF查询相当于sql 中的 where in

    两种写法 1. int[] Ids={1,2,3} DBContainer db=new DBContainer(); var list=db.表明.where(a=>Ids.Contains( ...

  6. (转)Window 中杀死指定端口 cmd 命令行 taskkill

    Windows平台   两步方法 :  1 查询端口占用,2 强行杀死进程 netstat -aon|findstr "8080" taskkill /pid 4136-t -f ...

  7. IDEA 服务启动报:No buffer space available (maximum connections reached): connect的解决方案。

    错误提示:严重: Error starting endpointjava.io.IOException: Unable to establish loopback connectionat sun.n ...

  8. crazyflie四轴飞行器

    源地址:http://www.bitcraze.se/2013/02/pre-order-has-started/ Crazyflie是一个开源的纳米四旋翼 来几张靓照 开发平台是开源的,所以原理图和 ...

  9. Note-Git:Git 笔记

    ylbtech-Note-Git:Git 笔记 1.返回顶部 ·  Git 分支管理: 主干/master.热修正/hotfix.预生产/release.开发develop.个人1(个人.小团队)/f ...

  10. python如何判断1个列表中所有的数据都是相等的?

    方法一: 元素两两比较,如果有数据不同,则r的值变为false #!/usr/bin/python a=[22,22,22,22] b = len(a) r=True for i in range(b ...