oracle和SQLSERVER的多字段赋值

create table tablea(id int,ip varchar(15),apps varchar(10))
insert into tablea select 23,'127.0.0.1','aaa'
go
declare @Variable1 varchar(15),@Variable2 varchar(10)
select @Variable1 = ip ,@Variable2 = apps from tablea where id = 23

select @Variable1,@Variable2
/*
--------------- ----------
127.0.0.1       aaa

(1 行受影响)

*/
go
drop table tablea

SQLSERVER的多字值赋值方式如上所示,直接SELECT就可以

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

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

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

cursor c_rw is
  select * from t_kh

  r_rw c_rw%rowtype;
open c_rw;
  loop
    fetch c_rw into r_rw;
    exit when c_rw%notfound;
dbms_output.put_line(r_rw.khbh||'  '||r_rw.khxm||'  '||r_rw.yzbm);
 end loop;
  close c_rw;

还有就一种方式就是用ROWTYPE

  -- Local variables here
  i integer;
         v_kh t_kh%rowtype;
begin
  -- Test statements here


       select * into v_kh from t_kh where rownum=1;
       dbms_output.put_line(v_kh.khbh||'  '||v_kh.khxm||'  '||v_kh.yzbm);



end;



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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值