日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Oracle自定义类型

發布時間:2025/3/8 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Oracle自定义类型 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Oracle自定義類型可以通過type/create type來聲明或者創建

一,四種創建方式

1.1,使用create type創建object類型

create or replace type obj_type as object(id number,name varchar2(50 byte),birthday date);

1.2,使用create type創建table類型

create or replace type table_type as table of obj_type;

創建table類型要依賴于object類型,就是as table of后面接object類型。

1.3,使用type創建object類型

declaretype obj_type is record(id number,name varchar2(50 byte),birthday date); begindbms_output.put_line(''); end;

1.4,使用type創建table類型

declaretype obj_type is record(id number,name varchar2(50 byte),birthday date);type table_type is table of obj_type; begindbms_output.put_line(''); end;

區別是create可以獨立執行,create后面用as

type只能在語句塊中執行,type后面用is

二,Oracle數組類型或者說list類型

oracle有這樣的一種方式,可以動態的將object變量添加到一個table變量中

create or replace type obj_type as object(id number,name varchar2(50 byte),birthday date);create or replace type table_type as table of obj_type;declarev_table table_type:=table_type(); beginv_table.extend;v_table(1):=obj_type(1,'lipiao',to_date('19970807','yyyymmdd'));v_table.extend;v_table(2):=obj_type(2,'cc',to_date('19951018','yyyymmdd'));for item in (select * from table(v_table)) loopdbms_output.put_line('id:'||item.id||',name:'||item.name||',birthday:'||item.birthday);end loop; end;

這種方式需要每次先extend方法擴展一個object,然后給object賦值。

這種方法可以將table變量轉換成游標。

?

下面這種方式可以自動擴展object,在19c版本測試可以使用,11g不行

declare type obj_type is record(student_id number,student_name varchar2(20 byte),student_birthday date); type table_type is table of obj_type index by binary_integer; student_table table_type:=table_type(); student obj_type; i number; beginstudent_table.student_id:=100;student_table.student_name:='lipiao';student_table.student_birthday:=to_date('19970807','yyyymmdd'); student_table(1):=student; student_table.student_id:=200;student_table.student_name:='cc';student_table.student_birthday:=to_date('19951018','yyyymmdd'); student_table(2):=student;i:=student_talbe.first; loopexit when i is null;dmbs_output.put_line(student_table(i).student_name);i:=student_table.next(i); end loop; end;

?

總結

以上是生活随笔為你收集整理的Oracle自定义类型的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。