Oracle記錄型別(record 使用

2022-06-17 13:42:12 字數 1202 閱讀 4550

record——儲存單行多列結構的資料.

type語句定義記錄型別的語法形式:

type 記錄名 is

record

(field1_name data_type

[not null][

:=|default value],

…fieldn_name data_type

[not null][

:=|default value

]);

【例項】定義乙個記錄型別rec_product,並使用該記錄變數儲存產品編號為1的產品的編號、名稱、單價、單位數量

declare

type rec_product

isrecord

(prod_id

number

, prod_name nvarchar2(

40),

quant_perunit nvarchar2(

20),

unit_price

number(38,3

) );

r_prod rec_product;

begin

select

productid, productname, quantityperunit,unitprice

into

r_prod

from

products

where productid=1;

dbms_output.put_line(r_prod. prod_id);

dbms_output.put_line(r_prod. prod_name);

dbms_output.put_line(r_prod. quant_perunit);

dbms_output.put_line(r_prod. unit_price);

end;

注意:乙個pl/sql record必須包含乙個或多個字段:這些欄位的資料型別可以是標量型別、record型別或pl/sql表型別。

一般在pl/sql塊中從表中取出一行進行處理時用pl/sql record。

select語句查詢的列值的數量與順序,必須與建立記錄型別變數中定義的字段數量和順序相匹配。

乙個記錄型別的變數僅僅能儲存從資料庫中查詢出的一行記錄,若查詢出了多行記錄。就會出現錯誤。

Oracle資料型別記錄

如果你要做迴圈的記數器,可以使用pls integer.pls interger,binary integer,number中,pls integer速度最快。binary integer 與 pls integer 都是整型型別.概述在oracle8中定義了 標量 scalar 復合 compos...

Oracle資料庫(五) 記錄型別

記錄型別變數只能儲存一行資料,如果select語句返回多行就會錯。基於表的記錄型別 用表名加 rowtype屬性的方法可以宣告乙個記錄型別,該記錄型別的每個欄位都和表中的一列相互對應並且語句相同的名字 one book book rowtype 基於游標的記錄型別 可以對顯示宣告的游標或者游標變數加...

ORACLE 新增記錄 更新記錄

開發中偶爾需要新增一條記錄或修改一條記錄的幾個字段,語法中有微妙的區別。由於不是經常寫,久不寫就忘記了,而又要重新查詢或除錯。新增記錄語法 新增記錄 仿照已有表記錄 insert into t x t t.field 1,t.field 2,t.field 3,t.field 4,t.field 5...