rowed,Oracle 基礎"/>
oracle rowed,Oracle 基礎
Oracle基礎----臨時表和對象表
臨時表,只有當用戶向表中添加數據時,才會為其分配存儲空間,而且為臨時表分配的空間來自臨時表空間。
創建會話級別臨時表:
SYS AS SYSDBA on 2008-03-03 15:33:14 at ORCL>edit
已將file afiedt.buf寫入
1create global temporary table session_table(
2id number,
3op varchar2(50),
4op_date date)
5* on commit preserve rows
SYS AS SYSDBA on 2008-03-03 15:33:27 at ORCL>/
已建立表格.
創建事務級別臨時表。
SYS AS SYSDBA on 2008-03-03 15:34:50 at ORCL>edit
已將file afiedt.buf寫入
1create global temporary table transaction_table(
2 id number,
3op varchar2(50),
4op_date date)
5* on commit delete rows
SYS AS SYSDBA on 2008-03-03 15:34:59 at ORCL>/
已建立表格.
對象和對象表
對象類型和之前的自定義數據類型不同,它還可以為其定義函數和過程作爲其方法,個人侷的相當于java中的class
SYS AS SYSDBA on 2008-03-03 15:35:00 at ORCL>create or replace type person as object(
2name varchar2(10),
3sex char(2),
4date_of_birth date,
5native_place varchar2(100)
6);
7/
已建立類型.
對象類型的名稱必須是唯一的,屬性不可以是以下類型:
1: Long和long raw.
2: rowed
3:pl/sql特定類型,如:binary_integer,Boolean,%type,%rowtype等。
4:程序包中定義的數據類型。
構造函數:
SYS AS SYSDBA on 2008-03-03 15:59:13 at ORCL>declare
2person_one person;
3begin
4person_one:=person('d','d',date'181-09-02','bj');
5dbms_output.put_line(person_one.name);
6end;
7/
PL/SQL程序順利完成.
引用對象類型:
SYS AS SYSDBA on 2008-03-04 08:50:37 at ORCL>edit
已將file afiedt.buf寫入
1create table employee(
2individual_info person,
3emp_id number,
4* dep_Id number)
SYS AS SYSDBA on 2008-03-04 08:51:05 at ORCL>/
已建立表格.
SYS AS SYSDBA on 2008-03-04 08:52:53 at ORCL>edit
已將file afiedt.buf寫入
1declare
2person_one person;
3begin
4person_one:=person('liu','n',date'1982-08-01','bj');
5insert into employee(individual_info,emp_id,dep_id)
6values(person_one,123,45);
7* end;
SYS AS SYSDBA on 2008-03-04 08:55:08 at ORCL>/
PL/SQL程序順利完成.
SYS AS SYSDBA on 2008-03-04 08:55:12 at ORCL>select e.emp_id,e.individual_info.name from emplo
yee e;
EMP_ID INDIVIDUAL
---------- ----------
123 liu
在訪問對象中單獨的屬性時,必須使用表列名。
實例方法和類方法:
SYS AS SYSDBA on 2008-03-04 09:17:33 at ORCL>create or replace type person as object(
2name varchar2(10),
3sex char(2),
4date_of_birth date,
5native_place varchar2(100),
6member procedure change_name(name varchar2),
7static function new(v_name varchar2,v_sex char) return person);
8/
已建立類型.
SYS AS SYSDBA on 2008-03-04 09:20:14 at ORCL>create or replace type body person is
2member procedure change_name(name varchar2) is
3begin
4self.name:=name;
5end change_name;
6static function new(v_name varchar2,v_sex char) return person
7is
8begin
9return(person(v_name,v_sex,date'1982-2-12','shanghai'));
10end new;
11end;
12/
已建立類型主體.
SYS AS SYSDBA on 2008-03-04 09:33:12 at ORCL>declare
2person_one person;
3begin
4person_one:=person('liu','n',date'1982-01-1','beijing');
5person_one.change_name('lili');
6dbms_output.put_line(person_one.name);
7end;
8/
PL/SQL程序順利完成.
映射方法:
SYS AS SYSDBA on 2008-03-04 10:07:03 at ORCL>edit
已將file afiedt.buf寫入
1create or replace type body person is
2member procedure change_name(name varchar2) is
3begin
4self.name:=name;
5end change_name;
6static function new(v_name varchar2,v_sex char) return person is
7begin
8return(person(v_name,v_sex,date'1982-01-01','shanghai'));
9end new;
10map member function compare return date is
11begin
12return self.date_of_birth;
13end compare;
14* end;
SYS AS SYSDBA on 2008-03-04 10:09:40 at ORCL>/
已建立類型主體.
SYS AS SYSDBA on 2008-03-04 10:13:33 at ORCL>edit
已將file afiedt.buf寫入
1declare
2person_one person;
3person_two person;
4begin
5person_one:=person.new('liu','n');
6person_two:=person('wang','n',date'1982-2-2',null);
7if person_one
8dbms_output.put_line('liu');
9elsif person_one=person_two then
10dbms_output.put_Line('=');
11else
12dbms_output.put_line('wang');
13end if;
14* end;
15/
liu
PL/SQL程序順利完成.
排序方法:使用order代替 映射方法中的map,其餘一致。
在聲明order方法時,order方法的參數類型要和self類型一致,且只可以為函數。構造函數,MAP方法和ORDER方法在對象類型内只允許定義一次。
MAP方法和ORDER方法都有能力在sql或PL/SQL中,針對對象進行比較,當排序或者合併大量的對象時,MAP方法具有效率方面的優勢,因爲它把每個對象映射為單個標量值,然後根據標量值進行處理。
而order方法一次只能比較2個值,所以必須反復調用order方法才能夠處理比較大的數據集合。
繼承:
當一個子類對象的實例被賦給一個父類型的變量時,父類變量只可以訪問父類中定義的那一部份,因爲父類不知道子類增加的屬性。
在重寫(覆蓋)時一個方法時,子類賦給父類后,父類調用子類的方法。
来自 “ ITPUB博客 ” ,链接:/,如需转载,请注明出处,否则将追究法律责任。
更多推荐
oracle rowed,Oracle 基礎
发布评论