Beruflich Dokumente
Kultur Dokumente
Amit Daharwal
IT Specialist – IBM Academic Initiative
2
IBM DB2 9
3
IBM DB2 9
6
IBM DB2 9
Examples -
SELECT * FROM staff;
SELECT * FROM staff
FETCH FIRST 10 ROWS ONLY;
SELECT name, salary
FROM staff;
SELECT DISTINCT dept, job
FROM staff;
SELECT name, salary + comm AS pay
FROM staff;
7
IBM DB2 9
15
IBM DB2 9
16
IBM DB2 9
17
IBM DB2 9
18
IBM DB2 9
INSERT Statement
The INSERT statement is used to add new rows to a
table or a view.
Examples:
INSERT INTO staff VALUES
(1212,'Cerny',NULL,'Sales',3)
UPDATE Statement
The UPDATE statement is used to change the data in
a table or a view.
For example:
UPDATE staff SET dept = NULL
WHERE ename LIKE ‘A%’
UPDATE staff SET (dept, sal)=(51, 7000)
WHERE id = 750
UPDATE employees SET (dept) =
(SELECT deptname FROM department
WHERE deptno = 1)
20
IBM DB2 9
DELETE Statement
The DELETE statement is used to delete entire rows
of data from a table.
For example:
21
IBM DB2 9
Savepoints
A savepoint lets you selectively roll back a subset of actions
that make up a UOW without losing the entire transaction.
do some work;
savepoint s1 on rollback retain cursors
do some more work;
savepoint s2 on rollback retain cursors
do even more work;
savepoint s3 on rollback retain cursors
wrap it up;
roll back to savepoint s1;
23
IBM DB2 9
What is XML?
XML was designed to structure, store and to send
data/information.
At its core XML is text formatted in the form of tags and text
that follow a well-defined set of rules.
<? xml version=“1.0” ?>
This text may be stored/represented in: <purchaseOrder id=‘12345” secretKey=‘4x%$^’>
<customer id=“A6789”>
<name>John Smith Co</name>
<address>
A normal file stored on disk <street>1234 W. Main St</street>
<city>Toledo</city>
<state>OH</state>
A message being sent over HTTP <zip>95141</zip>
</address>
</customer>
<itemList>
A character string in a programming language <item>
<partNo>A54</partNo>
<quantity>12</quantity>
A CLOB (character large object) in a database </item>
<item>
<partNo>985</partno>
<quantity>1</quantity>
Any other way textual data can be used </item>
</itemList>
</purchaseOrder>
24
IBM DB2 9
25
IBM DB2 9
26
IBM DB2 9
27
IBM DB2 9
XML specifications
DTD
describes
supersedes XML
document
s
XSD describes
uses
searches searches transforms
XQuery XPath
XSLT
uses
uses
uses
28
IBM DB2 9
29
IBM DB2 9
30
IBM DB2 9
XPath Expressions
31
IBM DB2 9
32
IBM DB2 9
33
IBM DB2 9
XML Facilities
XML data type for columns
create table s1.t1 (c1 int, c2 xml)
Language bindings for XML type in programming languages
cobol, c, java, etc..
XML indexes
create ix1 on s1.t1(c2) generate keys using pattern ‘/dept/emp/@empno’
An XML schema/DTD repository
Support for XQuery as a primary language as well as:
Support for SQL within XQuery
Support for XQuery with SQL
Support for new SQL/XML functions
Performance, scale, and everything else they expect from a
DBMS
34
IBM DB2 9
35
IBM DB2 9
38
IBM DB2 9
XML Functions
XMLQUERY(). function that enables you to execute an XQuery
expression from within an SQL context. It returns an XML
value, which is an XML sequence. This sequence can be
empty or it can contain one or more items.
XMLTABLE(). returns a table from the evaluation of XQuery
expressions; XQuery expressions normally return values as a
sequence, however, XMLTABLE() allows you to execute an
XQuery expression and return values as a table instead.
XMLEXISTS(). If it returns an empty sequence, XMLEXISTS
returns FALSE; otherwise, TRUE is returned. The XMLEXISTS
predicate can be used in the WHERE clauses of UPDATE,
DELETE, and SELECT statements.
39
IBM DB2 9
UPDATE customer
SET custinfo = XMLPARSE (DOCUMENT ‘<name>Jane
Doe</name>’ PRESERVE WHITESPACE)
WHERE empno = 11;
40
IBM DB2 9
41
IBM DB2 9
42
IBM DB2 9
44
IBM DB2 9
45
IBM DB2 9
46
IBM DB2 9
47
IBM DB2 9
49
IBM DB2 9
Grazie Hebrew
Italian
Gracias
Spanish
Russian
Obrigado
Thank
Portuguese
Arabic
Merci
French
Traditional Chinese
You English
Danke
German
Thai
Simplified Chinese Tamil
Japanese Korean
50