oracle的引用型變數和記錄型變數程式舉例

來源:互聯網
上載者:User

標籤:oracle

--引用型變數--開啟oracle的輸出口--set serveroutput ondeclare    --定義引用型變數,查詢並列印1232的姓名和薪水    --pename varchar2(20);--這2句和下面的2句效果一致    --psal number;    pename emp.ename%type;    psal emp.sal%type;begin    --得到1232的姓名和薪水    --賦值的方式有:=和into    select ename,sal into pename,psal from emp where empno=122;        --列印姓名和薪水    dbms_output.put_line(pename||'的薪水是'||psal);        end;/    

記錄型變數程式舉例:

--記錄型變數:取表中的一行的類型作為變數的類型,--可以把記錄型變數理解成一個數組,而數組中的每一個元素代表每一列--舉例 rec是記錄的簡寫,row是行,type是類型,就是行類型 -- emp_rec emp%rowtype;--記錄型變數分量的引用 -- emp_rec.ename:='ADAMS';  --使用記錄變數,查詢並列印123的姓名和薪水 --set serveroutput on declare     --定義記錄型變數:注意代表一行     emp_rec emp%rowtype; begin    --得到123一行的資訊        select * into emp_rec from emp where empno=123;        --列印姓名和薪水    dbms_output.put_line(emp_rec.ename||'的薪水是'||emp_rec.sal);   end;   --/


著作權聲明:本文為博主原創文章,未經博主允許不得轉載。

oracle的引用型變數和記錄型變數程式舉例

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.