PLSQL_动态语句的解析(概念)

2014-06-02 Created By BaoXinjian

1. 最简单例子


(1).SQL 

 1 DECLARE
 3     l_sql_text VARCHAR (1000); 
 5     TYPE c_type_wip_entity IS REF CURSOR; 
 7     c_wip_entity c_type_wip_entity; 
 9     r_wip_entity wip_entities%ROWTYPE; 
11 BEGIN 
13     l_sql_text :='select * from wip_entities' 
15                    || ' where wip_entity_id in ('|| ''''|| '2363' || ''','' '|| '2462'|| ''')';
16 
17     DBMS_OUTPUT.put_line (l_sql_text);
19     OPEN c_wip_entity FOR l_sql_text; 
21     LOOP 
23    FETCH c_wip_entity INTO r_wip_entity; 
25         EXIT WHEN c_wip_entity%NOTFOUND; 
27         DBMS_OUTPUT.put_line ('Job Name-->' || r_wip_entity.wip_entity_name); 
29     END LOOP; 
31 END;

(2).DBMS Output

 

 

2. 动态语句结合批处理


(1).SQL 

 1 DECLARE 
 3     i NUMBER; 
 5     l_sql_text VARCHAR (1000); 
 7     TYPE c_type_wip_entity IS TABLE OF wip_entities%ROWTYPE; 
 9     c_wip_entity c_type_wip_entity; 
11     p_wip_entity_id NUMBER := 2363; 
13 BEGIN 
15     l_sql_text := 'select * from wip_entities where wip_entity_id = :wip_entity_id'; 
17     EXECUTE IMMEDIATE l_sql_text 
19     BULK COLLECT INTO c_wip_entity 
21         USING p_wip_entity_id; 
23     FOR i IN 1 .. c_wip_entity.COUNT 
25     LOOP 
27         DBMS_OUTPUT.put_line (c_wip_entity (i).wip_entity_name); 
29     END LOOP;
31 END;

(2).DBMS Output

 

 

3. 动态更新语句


(1).SQL 

 1 DECLARE 
 3     l_sql_text VARCHAR (1000); 
 5 BEGIN 
 7     l_sql_text := 'update cux_wf_demo_documents set note= ' || '''Test''' || ' where document_id= :document_id'; 
 9     EXECUTE IMMEDIATE l_sql_text 
11         USING 1; 
13     DBMS_OUTPUT.put_line (l_sql_text); 
15 END;

(2).DBMS Output

 

 

Thanks and Regarads

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值