search
HomeDatabaseMysql TutorialOracle复合数据类型示例

--Recode数据类型 declare v_deptinfo scott.dept%rowtype; type dept_record is RECORD( v1 scott.dept.deptno%type, v2 sc

--Recode数据类型

declare

v_deptinfo scott.dept%rowtype;

type dept_record is RECORD(

  v1 scott.dept.deptno%type,

  v2 scott.dept.dname%type,

  v3 scott.dept%rowtype--可以声明ROWTYPE类型

);

v_deptrecord dept_record;

begin

--一下的赋值方式错误:因为V3是ROWTYPE类型,而查询的一行记录有五列,给v3赋值时会发生类型不匹配

select deptno,dname,t.* into v_deptrecord from dept t where deptno=10;

--解决方法:可以对v1,v2赋值后,,再写另外一条语句对v3赋值。

dbms_output.put_line(v_deptrecord.v3.dname||' '||v_deptrecord.v3.deptno);

end;


--索引表1

declare

type my_index_table1 is table of scott.dept.dname%type--可以使任意数据类型,代表此索引表所存储数据的类型。

index by binary_integer;

my1 my_index_table1;

c number(2);

begin

select count(*) into c from dept;

for i in 1..c loop

  select dname into my1(i) from

   (select rownum rn,t.* from dept t) x

     where x.rn=i;

end loop;

--每个集合都有COUNT属性,代表此集合存储的有效元素总个数。

for i in 1..my1.count loop

  dbms_output.put_line(my1(i));

end loop;

end;


--索引表2

declare

type my_index_table1 is table of scott.dept.dname%type

index by varchar2(20);--Oracle 9i以上的版本,索引表的下表可以为3中数据类型(BINARY_INTEGER、PLS_INTEGER、VVARCHAR2(length));

my1 my_index_table1;

begin

select loc into my1('南昌') from dept where deptno=10;

dbms_output.put_line(my1('南昌'));

end;


--嵌套表1

declare

type my_index_table1 is table of scott.dept.dname%type;

my1 my_index_table1:=my_index_table1(null,null,null,null);--初始化可以使用null值

begin

select dname into my1(1) from dept where deptno=10;

select dname into my1(2) from dept where deptno=20;

select dname into my1(3) from dept where deptno=30;

select dname into my1(4) from dept where deptno=40;

--嵌套表删除元素后,下标依然存在,依然可以重新进行赋值.

my1.delete(3);

dbms_output.put_line(my1.count);

select dname into my1(3) from dept where deptno=30;

dbms_output.put_line(my1.count);

for i in 1..my1.count loop

  dbms_output.put_line(my1(i));

end loop;

end;


--嵌套表2

create type phone_type is table of varchar2(20);

create table employee (

   eid number(4),

   ename varchar2(10),

   phone phone_type

) nested table phone store as phone_table;


insert into employee

values(1,'xx',phone_type('0791-111','123454545'));


insert into employee

values(2,'xx',phone_type('0791-111','123454545','saaasf'));

--变长数组

declare

type my_index_table1 is varray(3) of scott.dept.dname%type;

my1 my_index_table1:=my_index_table1('a','b','c');--初始化

begin

select dname into my1(1) from dept where deptno=10;

select dname into my1(3) from dept where deptno=20;

for i in 1..my1.count loop

  dbms_output.put_line(my1(i));

end loop;

end;


--记录表2

declare

--自定义RECORD可以存放自己想要的列,脱离了ROWTYPE的死板,可以灵活的自定义存放哪些列。

type dept_record is RECORD(

  v1 scott.dept.deptno%type,

  v2 scott.dept.dname%type,

  v3 scott.dept.loc%type

);

type my_index_table1 is table of dept_record

index by binary_integer;

my1 my_index_table1;

c number(2);

--查询出dept表中的所有数据并放进自定义的数据类型

begin

-先查询出表中的记录总数,以记录总数作为循环条件对dept表、以rownum作为WHERE条件对dept表进行逐条查询并存贮进自定义数据类型

select count(*) into c from dept;

for i in 1..c loop

  select x.deptno,x.dname,x.loc into my1(i) from

   (select rownum rn,t.* from dept t) x

     where x.rn=i;

end loop;

--循环输出my1类型中的v2字段在DEPT表中代表的数据;

for i in 1..my1.count loop

  dbms_output.put_line(my1(i).v2);

end loop;

end;

更多Oracle相关信息见Oracle 专题页面 ?tid=12

linux

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
C程序用于找到一个数的最大质因子C程序用于找到一个数的最大质因子Aug 27, 2023 am 10:09 AM

PrimeFactor−Innumbertheory,theprimefactorsofapositiveintegeraretheprimenumbersthatdividethatintegerexactly.Theprocessoffindingthesenumbersiscalledintegerfactorization,orprimefactorization.Example−Primefactorsof288are:288=2x2x2x2x2

全球数字虚拟币交易平台排行榜前十(2025权威排名)全球数字虚拟币交易平台排行榜前十(2025权威排名)Mar 06, 2025 pm 04:36 PM

2025年全球数字虚拟币交易平台竞争激烈,本文根据交易量、安全性、用户体验等指标,权威发布2025年全球十大数字虚拟币交易平台排行榜。OKX凭借强大的技术实力和全球化运营策略居首,Binance以高流动性和低费用紧随其后。Gate.io、Coinbase、Kraken等平台凭借各自优势稳居前列。榜单涵盖Huobi、KuCoin、Bitfinex、Crypto.com和Gemini等交易平台,各有特色,但投资需谨慎。选择平台需考虑安全性、流动性、费用、用户体验、币种选择及监管合规性等因素,理性投资

币圈十大交易所2025年最新 数字货币app排行榜前十币圈十大交易所2025年最新 数字货币app排行榜前十Feb 27, 2025 pm 06:33 PM

虚拟货币十大交易平台排行榜(2025年最新): 币安:全球龙头,高流动性,监管受关注。 OKX:庞大用户基数,支持多种币种,提供杠杆交易。 Gate.io:资深交易所,多种法币支付方式,提供多种交易对和投资产品。 Bitget:衍生品交易所,高流动性,低费用。 火币:老牌交易所,支持多种币种和交易对。 Coinbase:美国知名交易所,受监管严格。 Phemex等等。

十大数字货币交易平台 数字货币交易平台top10榜单最新十大数字货币交易平台 数字货币交易平台top10榜单最新Mar 17, 2025 pm 05:57 PM

十大数字货币交易平台:1. OKX,2. Binance,3. Gate.io,4. Huobi Global,5. Kraken,6. Coinbase,7. KuCoin,8. Bitfinex,9. Crypto.com,10. Gemini,这些交易所各具特色,用户可根据安全性、费用、币种选择、用户界面和客户支持等因素选择适合自己的平台。

数字货币app十大交易平台 炒币正规平台app推荐数字货币app十大交易平台 炒币正规平台app推荐Mar 07, 2025 pm 06:51 PM

本文推荐十个数字货币交易App:1. OKX;2. Binance;3. Gate.io;4. Huobi Global;5. Kraken;6. Coinbase;7. KuCoin;8. Crypto.com;9. Bitfinex;10. Poloniex。选择平台需考虑安全性、流动性、交易费用、币种选择、用户界面、客服支持及法规合规性等因素,谨慎评估风险,切勿盲目跟风。

靠谱的数字货币平台有哪些 十大正规数字货币交易平台2025靠谱的数字货币平台有哪些 十大正规数字货币交易平台2025Mar 17, 2025 pm 05:45 PM

靠谱的数字货币平台包括:1. OKX,2. Binance,3. Gate.io,4. Huobi Global,5. Kraken,6. Coinbase,7. KuCoin,8. Bitfinex,9. Crypto.com,10. Gemini,这些交易所各具特色,用户可根据安全性、费用、币种选择、用户界面和客户支持等因素选择适合自己的平台。

全球十大虚拟币交易平台app正版下载安装教程全球十大虚拟币交易平台app正版下载安装教程Mar 12, 2025 pm 05:33 PM

本文提供Binance、OKX、Gate.io、Huobi Global(火币)、Coinbase、KuCoin(库币)、Kraken和Bitfinex等主流数字货币交易平台的安卓和苹果手机APP下载方法。无论是安卓用户还是苹果用户,都能轻松找到对应平台的官方APP下载链接,并按照步骤完成安装。 文章详细指导了在各自官网或应用商店搜索下载,并针对安卓系统安装APK文件的特殊步骤做了说明,方便用户快速便捷地下载使用。

十大数字货币app交易平台 top10虚拟货币app2025排行榜十大数字货币app交易平台 top10虚拟货币app2025排行榜Mar 13, 2025 pm 07:00 PM

十大虚拟币交易平台排名依次为:1. OKX;2. Binance;3. Gate.io;4. Huobi Global;5. Kraken;6. Coinbase;7. KuCoin;8. Crypto.com;9. Bitfinex;10. Gemini。 排名基于平台流动性、币种选择、安全性、用户体验、手续费及合规性等因素综合考量,但仅供参考,投资需谨慎,风险自担。

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft