Professional Documents
Culture Documents
Present By:
By Ajay Shankar Khare
Technical Consultant DB2 –IBM Academic Initiative
WEBTEK LABS PVT LTD
ajay@webteklabs.com
2
IBM DB2 9
3
IBM DB2 9
4
IBM DB2 9
To change data.
- DELETE
5
IBM DB2 9
- FROM TABLE(S)
- WHERE condition
- GROUP BY column
- HAVING condition
- ORDER BY column
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
Example
Given the following Query:
8
IBM DB2 9
Example
SELECT quantity,
CASE WHEN itemcode = '099' THEN 'SILVER'
WHEN itemcode = '788' THEN 'GOLD'
WHEN itemcode = '899' THEN 'PLATINUM'
ELSE 'ERROR'
END
FROM supplier
Query:
Output
SUPPLIER 3,SILVER
------------------------------------------
QUANTITY ITEMCODE
4,SILVER
3 099 1,PLATINUM
4 099
1 788 1,ERROR
1 899 5,SILVER
5 009
3 788 3,GOLD
1 899 1,PLATINUM
10
IBM DB2 9
- IN and NOT IN
11
IBM DB2 9
12
IBM DB2 9
15
IBM DB2 9
17
IBM DB2 9
18
IBM DB2 9
19
IBM DB2 9
20
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)
TAB1
C1 C2
Query:
__ __________ Insert all rows found in table TAB2
1 Antarctica
2 Africa
into table TAB1.
3 Asia
4 Australia
Command:
TAB2 INSERT INTO tab1 SELECT cx, cy
CX CY
---- ---------
FROM tab2
5 Europe
6 North America
7 South America
22
IBM DB2 9
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)
23
IBM DB2 9
DELETE Statement
The DELETE statement is used to delete entire rows
of data from a table.
For example:
24
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 A;
do some more work;
savepoint B;
do even more work;
savepoint C;
wrap it up;
roll back to savepoint B;
26
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>
27
IBM DB2 9
28
IBM DB2 9
29
IBM DB2 9
30
IBM DB2 9
XML specifications
DTD
describes
supersedes XML
documents
XSD describes
uses
searches searches transforms
XQuery XPath
XSLT
uses
uses
uses
31
IBM DB2 9
32
IBM DB2 9
33
IBM DB2 9
34
IBM DB2 9
XPath Expressions
35
IBM DB2 9
36
IBM DB2 9
37
IBM DB2 9
XML Facilities
XML data type for columns
- create 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
38
IBM DB2 9
39
IBM DB2 9
42
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.
43
IBM DB2 9
UPDATE customer
SET custinfo = XMLPARSE (DOCUMENT ‘<name>Jane
Doe</name>’ PRESERVE WHITESPACE)
WHERE empno = 11;
44
IBM DB2 9
45
IBM DB2 9
46
IBM DB2 9
48
IBM DB2 9
49
IBM DB2 9
50
IBM DB2 9
51
IBM DB2 9
52
IBM DB2 9
53
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
54