Oracle和SQL SERVER的多欄位賦值

來源:互聯網
上載者:User

  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.bkjia.com/topicnews.aspx?tid=12

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.