Oracle數(shù)據(jù)庫自定義類型type的用法詳解
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)文章
查找oracle數(shù)據(jù)庫表中是否存在系統(tǒng)關(guān)鍵字的方法
遇到列說明無效的報錯情況,這是由于數(shù)據(jù)庫列名起的不好引起的,名字用到了數(shù)據(jù)庫的關(guān)鍵字2014-07-07Navicat連接Oracle數(shù)據(jù)庫報錯:Oracle library is not&nb
這篇文章主要介紹了解決Navicat連接Oracle數(shù)據(jù)庫提示oracle library is not loaded的問題,本文通過圖文結(jié)合的形式給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2024-06-06Oracle SQL性能優(yōu)化系列學(xué)習(xí)一
Oracle SQL性能優(yōu)化系列學(xué)習(xí)一...2007-03-03