Oracle Copy Table source 功能简介
来源:互联网 发布:淘宝代销怎么刷单 编辑:程序博客网 时间:2024/06/07 00:22
CREATE OR REPLACE PROCEDURE copy(Source IN VARCHAR2,
Destination IN VARCHAR2) IS
id_var temp_table.num_col%type;
name_var temp_table.char_col%type;
source_cursor INTEGER;
destination_cursor INTEGER;
ignore INTEGER;
BEGIN
source_cursor := dbms_sql.open_cursor;
DBMS_SQL.PARSE(source_cursor,
'SELECT NUM_COL, CHAR_COL FROM ' || source,
DBMS_SQL.native);
DBMS_SQL.DEFINE_COLUMN(source_cursor, 1, id_var);
DBMS_SQL.DEFINE_COLUMN(source_cursor, 2, name_var, 2000);
ignore := DBMS_SQL.EXECUTE(source_cursor);
-- Prepare acursor to insert into the destination table:
destination_cursor := DBMS_SQL.OPEN_CURSOR;
DBMS_SQL.PARSE(destination_cursor,
'INSERT INTO ' || destination ||
' VALUES (:id_bind, :name_bind)',
DBMS_SQL.native);
-- Fetch a rowfrom the source table and insert it into the destination table:
LOOP
IF DBMS_SQL.FETCH_ROWS(source_cursor) > 0 THEN
--get column values of the row
DBMS_SQL.COLUMN_VALUE(source_cursor, 1, id_var);
DBMS_SQL.COLUMN_VALUE(source_cursor, 2, name_var);
--Bind the row into the cursor that inserts into the destination table. You
--could alter this example to require the use of dynamic SQL by inserting an
--if condition before the bind.
DBMS_SQL.BIND_VARIABLE(destination_cursor, ':id_bind', id_var);
DBMS_SQL.BIND_VARIABLE(destination_cursor,':name_bind', name_var);
ignore :=DBMS_SQL.EXECUTE(destination_cursor);
ELSE
--No more rows to copy:
EXIT;
END IF;
END LOOP;
-- Commit andclose all cursors:
COMMIT;
DBMS_SQL.CLOSE_CURSOR(source_cursor);
DBMS_SQL.CLOSE_CURSOR(destination_cursor);
EXCEPTION
WHEN OTHERS THEN
IF DBMS_SQL.IS_OPEN(source_cursor) THEN
DBMS_SQL.CLOSE_CURSOR(source_cursor);
Dbms_Output.put_line(ignore);
END IF;
IF DBMS_SQL.IS_OPEN(destination_cursor) THEN
DBMS_SQL.CLOSE_CURSOR(destination_cursor);
Dbms_Output.put_line(ignore);
END IF;
RAISE;
END;
#######################################
下面存储过程例子通过传送源代码和目标表,然后从原始表拷贝数据行到目标表。
create table temp_table_1 as select * from temp_table where 1=3;
目标表temp_table_1的列类型和temp_table完全一样,这是为了测试该存储过程的使用规则
########################################
SQL> execcopy('temp_table','temp_table_1'); --temp_table是目标数据插入到1表中
PL/SQL proceduresuccessfully completed
Executed in 0.016 seconds- Oracle Copy Table source 功能简介
- Oracle flashback table简介
- Oracle Pipelined Table Functions简介
- Oracle Pipelined Table Functions简介
- Oracle 的drop table if exists功能
- oracle copy
- 新手入门 介绍ORACLE的Copy命令和create table,insert into的比较
- 新手入门 介绍ORACLE的Copy命令和create table,insert into的比较
- ORACLE的Copy命令和create table,insert into的比较
- ORACLE的Copy命令和create table,insert into的比较
- ORACLE的Copy命令和create table,insert into的比较
- ORACLE的Copy命令和create table,insert into的比较
- ORACLE的Copy命令和create table,insert into的比较
- ORACLE的Copy命令和create table,insert into的比较
- oracle 中 Flashback table功能恢复某个表数据!!
- oracle copy 与postgresql copy
- Lua中table的copy
- Zero Copy 简介
- 第一个PROC程序
- MongoDB学习笔记(二) 通过samus驱动实现基本数据操作
- 解决windown.close 在firefox不能关闭的问题
- 中移动“飞聊”28日正式发布 飞信官网可下载
- 【JSF】Richfaces复选框树(Checkbox tree)的权限分配的解决方案
- Oracle Copy Table source 功能简介
- ActionScript移动项目组件开发(1):可滚动的容器
- JDBC数据源(DataSource)的简单实现
- C++开源项目推荐之一
- css样式表中应用html注释
- reporting services 问题-rsServerConfigurationError-已解决
- SQL语句优化(01)
- C#凯撒密码的原理与实现
- Java集合----LinkedHashMap的实现原理