你好,游客 登录 注册 搜索
背景:
阅读新闻

Oracle和SQL SERVER的多字段赋值

[日期:2012-04-28] 来源:Linux公社  作者:friendliu [字体:大 中 小]
  1. create table tablea(id int,ip varchar(15),apps varchar(10))  
  2. insert into tablea select 23,'127.0.0.1','aaa'  
  3. go  
  4. declare @Variable1 varchar(15),@Variable2 varchar(10)  
  5. select @Variable1 = ip ,@Variable2 = apps from tablea where id = 23  
  6.   
  7. select @Variable1,@Variable2  
  8. /*  
  9. --------------- ----------   
  10. 127.0.0.1       aaa  
  11.   
  12. (1 行受影响)  
  13.   
  14. */  
  15. go  
  16. drop table tablea  
SQLSERVER的多字值赋值方式如上所示,直接SELECT就可以

但在Oracle的PLSQL下 select into 只能赋值单个变量,不能进行多变量同时赋值。

 如 : select count(*) into nb_count from t_khz where fzbh=V_fzbh;

多变量赋值一般采取游标FETCH的方式:

  1. cursor c_rw is  
  2.   select * from t_kh  
  3.   
  4.   r_rw c_rw%rowtype;  
  5. open c_rw;  
  6.   loop  
  7.     fetch c_rw into r_rw;  
  8.     exit when c_rw%notfound;  
  9. dbms_output.put_line(r_rw.khbh||'  '||r_rw.khxm||'  '||r_rw.yzbm);  
  10.  end loop;  
  11.   close c_rw;  
还有就一种方式就是用ROWTYPE
  1. -- Local variables here   
  2. i integer;  
  3.        v_kh t_kh%rowtype;  
  4. gin  
  5. -- Test statements here   
  6.   
  7.   
  8.      select * into v_kh from t_kh where rownum=1;  
  9.      dbms_output.put_line(v_kh.khbh||'  '||v_kh.khxm||'  '||v_kh.yzbm);  
  10.   
  11.   
  12.   
  13. d;  

更多Oracle相关信息见Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12

linux
相关资讯       Oracle入门教程 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款