PLSQL 定義record記錄,plsqlrecord記錄

來源:互聯網
上載者:User

PLSQL 定義record記錄,plsqlrecord記錄

1. PLSQL基本使用

註:1. 三段 declare 

            Begin

                Exception

                  End;

2. 聲明:emp.ename%type;和欄位的屬性相同。

3. begin: select 帶查詢自動 into儲存變數。

4. 條件陳述式:

(1)if then

                語句;

         End if;

  (2)When then

語句;

 

declare

v_ename emp.ename%type;

e_meet_scott exception;

begin

  select enameinto v_enamefrom empwhere emp.empno=7788;

  dbms_output.put_line('WHO?||v_ename');

  if v_ename='SCOTT'then

    raise e_meet_scott;

  endif;

exception

    when e_meet_scottthen

      dbms_output.put_line('AAAA,scott@@@@@');

end;

2. 記錄

2.1自訂記錄:

註:1.自訂結構體:

        Declare 結構體名字 is record(

        欄位1,

        欄位2);

        執行個體化結構體 結構體;

    2. ‘’||’’  連接字串。

declare

type emp_basic_recordisrecord(

     empno emp.empno%type,

     empname emp.ename%type,

     empjob emp.job%type

     );

 emp_basic_info emp_basic_record;

begin

  select empno,ename,jobinto emp_basic_infofrom emp

  where empno=7788;

  dbms_output.put_line('姓名:'|| emp_basic_info.empname);

end;

2.2 rowtype記錄

註:1,使用rowtype建立記錄。記錄的欄位名和原有的欄位相同。

2. 建立多個rowtype,可以方便同時處理不同的記錄

declare

emp_detail_info emp%rowtype;

begin

 

  select empno,ename,jobinto emp_detail_info.empno

  ,emp_detail_info.ename,emp_detail_info.jobfrom emp

  where empno=7788;

  dbms_output.put_line('姓名'||emp_detail_info.ename);

 


PLSQL中,定義一個RECORD類型變數r1 table1%rowtype,怎將table1表中的一條記錄放到r1中,並且在r1中得

select table1.clo1,table1.clo2,table1.clo3 into r1.clo1,r1.clo2,r1.clo3 from table1
變數r1 是一個記錄類型哦,r1 的結構和表table1 的結構完全一樣,記錄類型一次只能接受一條資料哦, 你再啟動並執行時候添加一個限制條件,保證查出來的記錄數只有一條,大概就這樣了,不懂再問
 
彙編 記錄record 的使用 教

當處理的資料項目較少,並且每個資料項目用幾位二進位就可以表示時,就可以用record來定義,將這些資料項目放在一個位元組或者兩個位元組中。
比如student record name:4,sex:1
name寬度為4個二進位位,sex為1個,總寬度小於等於8,組譯工具將用1個位元組表示記錄。若總寬度超過8但是小於等於16,就用兩個位元組表示。

如果想找到其中的某個欄位的具體值,則會用到移位值運算和屏蔽運算。

比如這樣定義資料區段:
data segment
s record a:4,b:1
s1 s <3,1>
s2 s <10,0>
data ends
那麼記憶體中是這樣分配的:
ds:0 07——這裡的07,就是s1的值
ds:1 14——這裡的14,就是s2的值。

mov bl,s1 ;取s1
mov al,mask a ;屏蔽運算,al中存放的就是欄位a的屏蔽碼,即該欄位各位均為1,其他各位均為0,即1EH
and bl,al ;s1的欄位a的值就在bl中存放了,但是還不是3,因為它右邊還有欄位b的一個位。於是還要進行移位元運算。
mov cl,a ;a欄位在記錄中的位置,即需要移動的位元。
shr bl,cl ;此時bl中的值為s1中a欄位的值——3

可以用下面這個程式分析一下,彙編串連後,用debug運行調試一下。
assume cs:code,ds:data
data segment
s record a:4,b:1
s1 s <3,1>
s2 s <10,0>
data ends
code segment
start: mov ax,data
mov ds,ax
mov al,mask a
mov bl,s1
and bl,al
mov cl,a
shr bl,cl
mov ax,4c00h
int 21h
code ends
end start

建議看看組合語言教材中相關的內容。
 

相關文章

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.