欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Oracle數(shù)據(jù)庫自定義類型type的用法詳解

 更新時間:2023年07月18日 10:19:18   作者:梁萌  
這篇文章主要介紹了Oracle數(shù)據(jù)庫自定義類型type的用法詳解,Oracle?數(shù)據(jù)庫的概念和其它數(shù)據(jù)庫不一樣,這里的數(shù)據(jù)庫是一個操作系統(tǒng)只有一個庫,可以看作是?Oracle?就只有一個大數(shù)據(jù)庫,需要的朋友可以參考下

Oracle 基本概念

1. Oracle 數(shù)據(jù)庫

Oracle 數(shù)據(jù)庫是數(shù)據(jù)的物理存儲。這就包括(數(shù)據(jù)文件 ORA 或者 DBF、控制文件、聯(lián)機日志、參數(shù)文件)。其實 Oracle 數(shù)據(jù)庫的概念和其它數(shù)據(jù)庫不一樣,這里的數(shù)據(jù)庫是一個操作系統(tǒng)只有一個庫??梢钥醋魇?Oracle 就只有一個大數(shù)據(jù)庫

2. 實例

一個Oracle實例(Oracle Instance)有一系列的后臺進程(Backguound Processes)和內(nèi)存結(jié)構(gòu)(Memory Structures)組成。一個數(shù)據(jù)庫可以有 n 個實例。

3. 數(shù)據(jù)文件(dbf)

數(shù)據(jù)文件是數(shù)據(jù)庫的物理存儲單位。數(shù)據(jù)庫的數(shù)據(jù)是存儲在表空間中的,真正是在某一個或者多個數(shù)據(jù)文件中。而一個表空間可以由一個或多個數(shù)據(jù)文件組成,一個數(shù)據(jù)文件只能屬于一個表空間。一旦數(shù)據(jù)文件被加入到某個表空間后,就不能刪除這個文件,如果要刪除某個數(shù)據(jù)文件,只能刪除其所屬于的表空間才行。

4. 表空間

表空間是 Oracle 對物理數(shù)據(jù)庫上相關(guān)數(shù)據(jù)文件(ORA 或者 DBF 文件)的邏輯映射。一個數(shù)據(jù)庫在邏輯上被劃分成一到若干個表空間,每個表空間包含了在邏輯上相關(guān)聯(lián)的一組結(jié)構(gòu)。每個數(shù)據(jù)庫至少有一個表空間(稱之為 system 表空間)。
每個表空間由同一磁盤上的一個或多個文件組成,這些文件叫數(shù)據(jù)文件(datafile)。一個數(shù)據(jù)文件只能屬于一個表空間。 

emp表數(shù)據(jù)如下所示

定義object類型

create or replace type typeof_userinfo_row as object(
  user_id varchar2(50),
  user_name varchar2(50)
)

創(chuàng)建函數(shù)并將此類型作為返回值類型

create or replace function FUN_TEST
return typeof_userinfo_row
is
  FunctionResult typeof_userinfo_row;
begin
  FunctionResult:=typeof_userinfo_row(null,null);
  --將單條數(shù)據(jù)值插入到自定義類型的變量中
  SELECT e.empno,e.ename  INTO FunctionResult.user_id,FunctionResult.user_name
  FROM emp e where e.empno = '7499';
  RETURN(FunctionResult);
end FUN_TEST;

調(diào)用該函數(shù),并打印執(zhí)行結(jié)果

declare res typeof_userinfo_row;
begin
  res := FUN_TEST();
  dbms_output.put_line(res.user_id || ' ' || res.user_name);
end;

執(zhí)行結(jié)果

定義table類型

create or replace type typeof_userinfo_table is table of typeof_userinfo_row

創(chuàng)建函數(shù)并將此類型作為返回值類型

create or replace function FUN_TEST1
return typeof_userinfo_table
is
  FunctionResult typeof_userinfo_table;
begin
  --將多條記錄的值同時插入到自定義類型的變量中
  SELECT typeof_userinfo_row(empno,ename) BULK COLLECT INTO FunctionResult FROM emp e;
  RETURN(FunctionResult);
end FUN_TEST1;

調(diào)用該函數(shù),并打印執(zhí)行結(jié)果

declare 
res typeof_userinfo_table;
i NUMBER := 1;
begin
  res := FUN_TEST1();
  WHILE i <= res.LAST  LOOP
  	DBMS_OUTPUT.PUT_LINE(res(i).user_id || ' ' ||res(i).user_name);
		i := i + 1;
	END LOOP;
end;

執(zhí)行結(jié)果

到此這篇關(guān)于Oracle數(shù)據(jù)庫自定義類型type的用法詳解的文章就介紹到這了,更多相關(guān)Oracle的type內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論