Professional Documents
Culture Documents
12 Ordbms
12 Ordbms
SQL-2 (SQL:1992)
SQL-3 (SQL:1999).
computational completeness.
((Abstraction))
(Encapsulation)
(Inheritance)
SQL-3
.
:
((distinct types)
y
)
(Structured types)
(distinct types)
,
y ..
integer,
integer varchar .
db2
,
(.., integer, date).
10
11
(, )
(, )
CREATE TABLE Business1
(Name varchar(20) not null primary key,
key
Headcount integer);
CREATE TABLE Person1
P
1
(Name varchar(20) not null primary key,
age integer);
12
,
.
insert into business1 values ('Jack', 20);
i
insert
t iinto
t person1
1 values
l
('J k' 35);
('Jack',
35)
13
.
select b.*, p.*
from person1 p, business1 b
where
h
p.name = b
b.name ;
14
15
(
(, )
(, ).
b_name_type
varchar(20)
( )
p_name_type
varchar(20).
CREATE TABLE Business2
(Name b_name_type not null primary key,
Headcount headcount_type);
yp );
CREATE TABLE Person2
(Name p_name_type
p name type not null primary key,
key
age int);
16
,
.
insert into business2 values ('Jack'
( Jack , 20);
insert into person2 values ('Jack', 35);
17
.
select b.*,
b * p.*
p*
from person2 p, business2 b
where p.name = b.name ;
18
19
20
.
.
.
y
y
.
.
y
21
(Attributes)
(Att ib t )
y (Methods)
y
.
:
22
y :
HisNurse Nurse;
HisNurse REF(Nurse);
23
Person
Employee
BusinessUnit
Student
Address_t
Manager
Architect
Brazil_addr_t
Germany_addr_t
US_addr_t
24
25
CREATE TYPE
( )
.
VARCHAR(13).
.
.
26
27
28
UNDER
. Germany_addr_t
Germany addr t
Address_t
.
29
30
31
32
Dept
p REF(BusinessUnit
(
_t))
. Dept
BusinessUnit_t
33
34
35
36
37
BusinessUnit
BusinnessUnit_t.
BusinessUnit BusinessUnit_t
(Oid)
(Oid).
"" Oid
REF IS ... USER GENERATED
"Oid"
.
38
Oid
.
39
40
41
, U User Defined , H
Reference,
42
43
.
.
E l
Employee
S i lN
SerialNum
Employee.
Employee
Employee2 Employee_t Dept
.
.
44
varchar(13). O default
.
45
46
.
.
47
.
address . ,
.
48
Employee_t('d') .
BusinessUnit_t(1)
.
49
Person
Employee
50
51
ONLY
employee
Employee
52
Anna
Manager_t
Architect_t
53
..
54
55
56
57
58
CREATE TYPE ALTER
TYPE.
:
ALTER TYPE Manager_t
ADD METHOD total_salary()
RETURNS integer
LANGUAGE SQL;
59
60
61
62
63
CREATE METHOD
.
:
y ,
y SQL.
SQL
64
CREATE METHOD _
(_1
(
1 1,
1 ))
RETURNS __ FOR ___
RETURN SQL
SQL-command
command
65
:
CREATE METHOD total_salary()
RETURNS integer FOR Manager_t
RETURN select SELF..Salary + SELF..Bonus from manager;
66
67
:
( )
_
y()
select name, DEREF(oid)..total_salary()
from Manager;
68
Manager_t
ALTER TYPE Manager_t
M
t ADD METHOD comparesalary
l
( l manager_t)
(sal
t)
RETURNS integer
LANGUAGE SQL;
69
70
71
1
1.
:
DROP METHOD TOTAL_SALARY FOR MANAGER_T;;
.
2.
,,
72
.
:
1.
Java, C
2. SQL
SQL return
3. Sourced
73
y ,
y ,
y .
74
75
Java code
import java
java.sql.*;
sql *;
import java.lang.*;
import COM.ibm.db2.app.*;
class DB2Appl1 extends UDF {
public static int testUDF(int value1, int value2) {
try {
return(value1 & value2);
}
catch(Exception e) {
return(0);
( );
}
}
}
class directory
c:\Program Files\IBM\SQLLIB\FUNCTION
76
SELECT name, BitAnd(110,headcount)
Bi A d(110 h d
)
FROM Business1;
77
78
79
80
Java code
import java
java.sql.*;
sql *;
import java.lang.*;
import COM.ibm.db2.app.*;
class DB2Appl2 extends UDF {
public static String concatstrings(String value1, String value2) {
String value3 = value1 + value2;
return value3;
}
}
81
create table personexample(
code integer not null primary key,
Surname varchar(20),
Name varchar(20));
( ));
insert into personexample values (1,'Obama', 'Barak');
insert into personexample values (2
(2,'Bush'
Bush , 'George');
George );
SELECT name
name, concat(name,surname)
concat(name surname)
FROM personexample;
.
82
83
SQL Return
. Select
.
84
85
create
t table
t bl a((
aname char(20) not null primary key,
afield date);
insert into a values ('John', '1/1/1970'),
('George', '1/6/1980');
select aname, agef(afield)
from a;
86
87
88
SOURCE
: Head_Max
max
o
H d
Head_count
t
integer.
i t
CREATE FUNCTION Head_MAX(Headcount
(
_type)
yp )
RETURNS Headcount_type
SOURCE SYSIBM.max(INTEGER);
SELECT Head_Max(Headcount) as max
FROM Business2
.
89
90
RDBMS ,
ORDBMS
RDBMS
92
.
.
y ORDBMS SQL3, SQL2
y OODBMS OQL
SQL
93
ORDBMS DBMS
.
OODBMS
.
,
,
OO
OODBMS
S
DBMS
S
, ORDBMS
DBMS.
94