把表二中缺少的列补全
来源:互联网 发布:汉武大帝知乎 编辑:程序博客网 时间:2024/05/17 23:54
问题描述:
表一:ORDERS
表二:HIST_ORDERS
HIST_ORDERS是ORDERS的备份表,但是在ORDERS添加了某些列,此时需要在HIST_ORDERS添加相同的列,或者单纯是找出缺少的列
表一:ORDERS
表二:HIST_ORDERS
HIST_ORDERS是ORDERS的备份表,但是在ORDERS添加了某些列,此时需要在HIST_ORDERS添加相同的列,或者单纯是找出缺少的列
SET SERVEROUTPUT ONSET DEFINE OFF--put the log into fileSPOOL 2014-11-262.log ----1、ORDERS HIST_ORDERSDECLARE V_FROM_TABLE VARCHAR2(50) :='ORDERS'; V_TO_TABLE VARCHAR2(50):='HIST_ORDERS'; cursor crecord is select * from (select * from user_tab_columns where table_name=V_FROM_TABLE) where column_name not in (select column_name from user_tab_columns where table_name=V_TO_TABLE); col crecord%rowtype;BEGIN open crecord; dbms_output.put_line('Start to alter table '||V_TO_TABLE||':'); fetch crecord into col; while crecord%found loop if(col.data_type='TIMESTAMP(6)') then dbms_output.put_line('alter table '||V_TO_TABLE||' add '||col.column_name||' '||col.data_type); execute immediate 'alter table '||V_TO_TABLE||' add '||col.column_name||' '||col.data_type; elsif(col.data_type='NUMBER') then if(nvl(col.data_precision,-1)=-1 and nvl(col.data_scale,-1)=-1) then dbms_output.put_line('alter table '||V_TO_TABLE||' add '||col.column_name||' '||col.data_type); execute immediate 'alter table '||V_TO_TABLE||' add '||col.column_name||' '||col.data_type; else dbms_output.put_line('alter table '||V_TO_TABLE||' add '||col.column_name||' '||col.data_type||'('||col.data_precision||','||col.data_scale||')'); execute immediate 'alter table '||V_TO_TABLE||' add '||col.column_name||' '||col.data_type||'('||col.data_precision||','||col.data_scale||')'; end if; elsif(col.data_type='DATE') then dbms_output.put_line('alter table '||V_TO_TABLE||' add '||col.column_name||' '||col.data_type); execute immediate 'alter table '||V_TO_TABLE||' add '||col.column_name||' '||col.data_type; elsif(col.data_type='VARCHAR2') then dbms_output.put_line('alter table '||V_TO_TABLE||' add '||col.column_name||' '||col.data_type||'('||col.data_length||')'); execute immediate 'alter table '||V_TO_TABLE||' add '||col.column_name||' '||col.data_type||'('||col.data_length||')'; else dbms_output.put_line('Fail to add the column '||col.column_name||' '||col.data_type); dbms_output.put_line('You program have not handle this type!Please check!'); end if; fetch crecord into col; end loop; close crecord;END; /
0 0
- 把表二中缺少的列补全
- 缺少的书面
- 目前缺少的功能
- 找到缺少的数
- 找出缺少的数
- json的问题 --- 缺少“;”
- 缺少包的异常
- 缺少 CvvImage的问题
- 缺少的专注
- 寻找缺少的整数
- 寻找缺少的数字
- 缺少的字符串-LintCode
- 缺少
- 缺少
- 忘记的缺少的东西
- 强调的总是缺少的
- 穷人最缺少的是什么?
- 穷人最缺少的是什么?
- 复制备份表
- Windows Phone 8.1 驱动开发——GPIO 简介
- IOS线程数据篇12之Sqlite3其他属性:排列约束、外键约束、表连接
- michael kors australia gSPyc Ttlf UC71
- IoTivity Architecture (物联网架构)
- 把表二中缺少的列补全
- 漫步IOS--数组函数
- 基于MVC的前台ExtJs树型表格的批量数据操作实现
- sgu323 Aviamachinations
- sitemesh的使用
- 跟着实例学习java多线程1-为什么使用?
- git tag — 标签相关操作
- 作为一个iOS开发者,想知道作为一个Android开发者是一种怎样的体验
- VLC compile for Android