P. 1
SQL Material

SQL Material

|Views: 354|Likes:
Published by Sravan Kumar

More info:

Published by: Sravan Kumar on Nov 23, 2011
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

08/02/2014

pdf

text

original

There are four types of multiple inert statements

Unconditional insert statement
Pivoting insert statement
Conditional insert statement
Insert first statement

Unconditional Insert Statement

SQL> SELECT ENAME, COMM, SAL, DEPTNO, MGR, COALESCE (COMM, SAL,
DEPTNO, MGR) COAL FROM EMP;

ENAME COMM SAL DEPTNO MGR COAL
--------------- ---------- ---------- ---------- ----------
ss ss 1234 6810.91 20 7902 1234
allen 746.5 196867.32 30 7698 746.5
WARD 1244.16 153802.68 30 7698 1244.16
JONES 855945.6 20 7839 855945.6
MARTIN 3483.65 153802.68 30 7698 3483.65
BLAKE 855945.6 30 7839 855945.6
CLARK 855945.6 10 7839 855945.6
SCOTT 641959.2 20 7566 641959.2
TURNER 0 184563.24 30 7698 0
ADAMS 129461.88 20 7788 129461.88
JAMES 111807.6 30 7698 111807.6
FORD 66870.77 20 7566 66870.77
phani 20000 10000 90 9822 20000

Siva Kumar HVK

198

This statement enables to you insert data in multiple tables
using a single insert statement.

To understand this query consider the three tables from
Annexure

To insert the data into two tables

Example1(pname,title,salary)
Example2(pname,course,cost)

Insert all
Into example1 values(pname,title,salary)
Into example2 values(pname,course,cost)
Select p.pname,title,course,cost,salary from programmer
p,software s, studies st
Where p.pname = s.pname and s.pname = st.pname;

Conditional Insert statement

It inserts the data into the table only when condition is
satisfied.
Assume there are three tables with structure
(table1,table2,table3)
Empno.ename,job,sal,deptno

We can load the data conditionally into three tables by using
following statement

SQL> insert all

When deptno = 10 then
Insert into table1 values(empno,ename,job,sal,deptno);
When deptno = 20 then
Insert into table2 values(empno,ename,job,sal,deptno);
When deptno = 30 then
Insert into table3 values(empno,ename,job,sal,deptno);
Select empno,ename,sal,deptno from emp

Siva Kumar HVK

199

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->