- 浏览: 414276 次
- 性别:
- 来自: 南京
文章分类
最新评论
-
xiang37:
wwwang89 写道这位大哥,你好!很感谢你分享的文章,写的 ...
iPhone调用java的webService -
wwwang89:
这位大哥,你好!很感谢你分享的文章,写的很好,适合我们新手学习 ...
iPhone调用java的webService -
QQ371496669:
能否具体讲解一下为什么StringBuilder的长度会不一样 ...
StringBuilder与StringBuffer相比为什么不是线程安全的 -
Sky_257:
请问 能用abap查询sap服务器的配置、会话、队列、spo ...
使用JCo远程调用SAP系统函数 -
xiang37:
vebasan 写道此句代码的单词有错(标红色的):prop. ...
最简单的EJB示例
DBMS_SQL
Oracle lets you to write stored procedures and anonymous PL/SQL blocks that use dynamic SQL. Dynamic SQL statements are not embedded in your source program; rather, they are stored in character strings that are input to, or built by, the program at runtime. This enables you to create more general-purpose procedures. For example, dynamic SQL lets you create a procedure that operates on a table whose name is not known until runtime.
CREATE OR REPLACE PROCEDURE copy ( source IN VARCHAR2, destination IN VARCHAR2) IS id_var NUMBER; name_var VARCHAR2(30); birthdate_var DATE; source_cursor INTEGER; destination_cursor INTEGER; ignore INTEGER; BEGIN -- Prepare a cursor to select from the source table: source_cursor := dbms_sql.open_cursor; DBMS_SQL.PARSE(source_cursor, 'SELECT id, name, birthdate FROM ' || source, DBMS_SQL.native); DBMS_SQL.DEFINE_COLUMN(source_cursor, 1, id_var); DBMS_SQL.DEFINE_COLUMN(source_cursor, 2, name_var, 30); DBMS_SQL.DEFINE_COLUMN(source_cursor, 3, birthdate_var); ignore := DBMS_SQL.EXECUTE(source_cursor); -- Prepare a cursor 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, :birthdate_bind)', DBMS_SQL.native); -- Fetch a row from 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); DBMS_SQL.COLUMN_VALUE(source_cursor, 3, birthdate_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); DBMS_SQL.BIND_VARIABLE(destination_cursor, ':birthdate_bind', birthdate_var); ignore := DBMS_SQL.EXECUTE(destination_cursor); ELSE -- No more rows to copy: EXIT; END IF; END LOOP; -- Commit and close 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); END IF; IF DBMS_SQL.IS_OPEN(destination_cursor) THEN DBMS_SQL.CLOSE_CURSOR(destination_cursor); END IF; RAISE; END; /
例如,动态SQL可以让你创建一个程序上的表的名称,直到运行时才知道。
当然动态SQL有还有一种可以使用动态游标的方式来实现,但是在Oracle Froms里面不支持,改用上面的方式即可。
It's from http://www.csee.umbc.edu/portal/help/oracle8/server.815/a68001/dbms_sql.htm
DECLARE vc_msg BINARY_INTEGER; vc_istry VARCHAR2(1); vc_tempSql VARCHAR2(200); my_cur integer; num integer; vc_mrn VARCHAR2(5); BEGIN my_cur := dbms_sql.open_cursor; --创建游标 vc_tempSql := 'select t.mrn from temp_pl_m_asf t where t.asfno = 1000000001'; dbms_sql.parse(my_cur, vc_tempSql, 1); dbms_sql.define_column(my_cur,1,vc_mrn,5); num := dbms_sql.execute(my_cur); loop if dbms_sql.fetch_rows(my_cur) > 0 then begin dbms_sql.column_value(my_cur, 1, vc_mrn); end; else exit; end if; end loop; dbms_sql.close_cursor(my_cur); END;创建动态游标
发表评论
-
[转]Oracle聚簇表
2014-08-07 23:59 1208Oracle 支持两种类型的聚簇:索引聚簇和哈希聚簇 ... -
创建DBLINK
2015-04-11 15:20 0create shared public databas ... -
SQL语句
2013-01-06 12:26 879Case When的用法; SQLSTATE = 2100 ... -
双层游标循序,导致ORA-01001错误的解决方法
2012-03-23 15:19 2626下面的代码是双层游标循环: EXEC SQL ... -
Oracle中dual表的用途
2011-11-03 11:19 879dual是一个虚拟表, ... -
SQL游标中Order By的使用限制
2011-10-26 11:29 1621在创建游标的SELECT语句中使用了Order By子句 ... -
Oracle数据库小知识
2011-09-28 15:09 1177在oralce中,我们有时误删了某些数据或者删除了某些表;这 ... -
NVARCHAR2和VARCHAR2的区别
2011-09-08 15:04 863VARCHAR2是Oracle提供的特定数据类型,Oracle ... -
Oracle新建用户、角色,授权,建表空间
2011-08-26 09:20 885转载 Oracle数据库 ... -
Oracle 数据类型及存储方式
2011-06-24 12:39 1782it's from http://www.iteye.com/ ... -
Oracle SQL 内置函数大全(三)
2011-05-23 09:51 66561.MAX(DISTINCT|ALL) 求最大值,A ... -
Oracle SQL 内置函数大全(二)
2011-05-23 09:46 69131.SIGH 返回双曲正弦的值 SQL ... -
Oracle SQL 内置函数大全(一)
2011-05-23 09:42 811it's from http://www.gissky.com ... -
ORACLE解锁
2011-05-09 09:57 628select object_name as 对象名称,s ... -
dbcp的properties文件保存一下
2011-01-26 15:08 1158#连接设置 jdbc.driverClassName= ... -
Mysql 的 Cascade/Restrict/No action
2011-01-12 10:05 2408外键约束对子表的含义: 如果在父表中找不到候选键,则不允 ... -
sql 语句复习
2010-11-11 13:43 8051.select distinct name from ... -
查看mssql版本
2010-11-11 13:42 10501.查看版本及补丁号select server ... -
左连接与右连接的区别
2010-11-11 13:40 1072左联时,会全显左表的数据,如果右表没有满足的条件的数据为N ... -
脏读、不可重复读、幻影读的理解
2010-11-11 13:40 28061 脏读:当事务1修改了一条记录,没有提交时,事务2读取了该记 ...
相关推荐
oracle中DBMS_SQL的使用,详细讲解oracle DBMS_SQL的使用办法
oracle dbms_sql的使用方法,非常使用
Oracle动态SQL之DBMS_SQL系统包的使用.pdf
DBMS_XPLAN是Oracle提供的一个用于查看SQL计划,包括执行计划和解释计划的包;在以前查看SQL执行计划的时候,我都是使用set autotrace命令,不过现在看来,DBMS_XPLAN包给出了更加简化的获取和显示计划的方式。 这5...
ORACLE数据库封装过程DBMS_SQL的应用.pdf
PLSQL开发过程中,动态使用DBMS_SQL[借鉴].pdf
dbms_sql.parse(l_cursor,'select bus_type as 流程名称,st_center as 结算中心,st_department as 编制部门,bus_desc 流程描述 from xact.tafct23',dbms_sql.native); dbms_sql.describe_columns(l_cursor,l_colcnt,...
亲测有效 通过此版本可以把oracle时区版本调整到为最新版本,一般配合时区补丁使用 可以参考...脚本里有说明 先运行upg_tzv_check.sql再运行upg_tzv_apply.sql
一个自己开发的dbms系统,实现自己的sql语句编译解析
java写的数据库 SQL解析器 分客户端和后端底层实现
使用C语言实现的数据库管理系统。 支持简单类 SQL语言。
Oracle SQL执行计划分析器功能的创建3步曲: ...如果出现没权限访问GV$SQL_PLAN_MONITOR这些对象,请先用sys用户赋值。 3 最后,编译XYG_ALD_SESS_PKG的包体。完工! (XYG_ALD_SESS_PKG_BODY.sql)
简单得说,通过dbms_random包调用随机数的方法大致有4种: 1、dbms_random.normal 这个函数不带参数,能返回normal distribution的一个number类型,所以基本上随机数会在-1到1之间。 简单测试了一下,产生100000...
Java连接Oracle数据库实例 实现SQL*PLUS功能 带JDBC驱动 适合初学者学习参考
Oracle_SQL注入果断分享
SQL Server是由Microsoft开发和推广的关系数据库管理系统(DBMS),它最初是由Microsoft、Sybase和Ashton-Tate三家公司共同开发的,并于1988年推出了第一个OS/2版本。Microsoft SQL Server近年来不断更新版本,1996...
全面介绍了PL/SQL语言的包、触发器、动态SQL、外部例程、对象、集合等基本概念,而且还集中讨论了Oracle8...6) 使用动态SQL语言在运行时创建并执行SQL和PL/SQL语句。 7) 允许数据库管道与警告之间进行交互会话,等等。
DBMS_SQL.PARSE(P_CursorID,CreateStr,DBMS_SQL.NATIVE); --步骤3:执行语句 P_NUMRows:=DBMS_SQL.EXECUTE(P_CursorID); exception when others then CatchError:=SQLERRM; rollback; commit; --步骤4...
DBMS_RANDOM是Oracle提供的一个PL/SQL包,用于生成随机数据和字符。它具有以下函数。 其中,initialize,random,terminate函数在Oracle11g中已不推荐使用,主要用于向后兼容。下面对各个函数进行举例说明 1. ...
NULL 博文链接:https://wushuangyan26.iteye.com/blog/1307514