You are on page 1of 34

Data Manipulation Language (DML) Statement

1. SELECT Command

Syntax:
Select <coloumn_name> From <table_name>

Example:

Table Store_Info
Store_name Sale Date
Los Angeles 1500 Jan-05-1999
San Diego 250 Jan-07-1999
Los Angeles 300 Jan-08-1999
Boston 700 Jan-081999

Select Store_name From Store_Info;

Result
Store_name
Los Angeles
San Diego
Los Angeles
Boston

2. DISTINCT Command

Select Store_name From Store_Info;


Result
Los Angeles
San Diego
Boston

1
3. Where Clause
Syntax
Select <column_name> FROM <table_name> WHERE
<condition>
Example:
Select all stores with sales above 1,000 in table Store_Info

Select Store_name from Store_Info Where Sales > 1000;


RESULT
Store_name
Los Angeles

4. OR & AND

Select all stores with sales greater than 1000 or all stores with sales less than
500 but greater than 275 in table Store_Info
Table Store_Info
Store_name Sale Date
Los Angeles 1500 Jan-05-1999
San Diego 250 Jan-07-1999
San Francisco 300 Jan-08-1999
Boston 700 Jan-081999

Select Store_name From Store_Info where Sales>1000 OR (Sales <500


AND Sales>275);

RESULT
Store_name
Los Angeles
San Francisco

5. IN
IN operator allow you to specify multiple values in the where clause

Syntax
Select <column_name> FROM <table_name> WHERE
<column_nmae> IN (‘value1’, ‘value2’……);

2
Example;
To Select all records from Los Angeles and San Francisco in
table Store_Info

Select * FROM Store_Info Where Store_name IN (‘Los Angeles’ ,


‘San Francisco’);
RESULT:

Store_name Sale Date


Los Angeles 1500 Jan-05-1999
San Diego 250 Jan-07-1999

6. BETWEEN

Between keyword allows for selecting a range

Syntax
Select <column_name> FROM <table_name> WHERE
<column_nmae> BETWEEN ‘value1’ AND ‘value2’;

Example;
To select all sales between Jan, 6, 1999 and Jan, 10, 1999 in table
Store_Info

Select * FROM Store_Info WHERE Date BETWEEN ‘JAN-06-1999’


AND ‘JAN-10-1999’;

RESULT:
Store_name Sale Date
Los Angeles 1500 Jan-05-1999
San Diego 250 Jan-07-1999
San Francisco 300 Jan-08-1999
Boston 700 Jan-081999

3
7. LIKE
Like is another keyword that is used in WHERE clause. LIKE allows
you to do search used on a pattern rather than specifying exactly what is
desired or spell out a range.

Syntax
Select <column_name> FROM <table_name> WHERE
<column_nmae> LIKE {PATTERN}

Example
We want to find all stores whose name contain ‘an’.

Select * FROM Store_Info WHERE Store_name LIKE ‘%an%’;

RESULT;
Store_name Sale Date
Los Angeles 1500 Jan-05-1999
San Diego 250 Jan-07-1999
San Francisco 300 Jan-08-1999

8. ORDER BY

Order By keyword is used to get the list of output in particular order like in
ascending order or descending order. By default Order By arrange the list in
ascending order.

Syntax

Select <column_name> FROM <table_name> WHERE <condition>


Order By <column_name>

Example

List the content of table Store_Info by Sale in descending order. 4

4
Table Store_Info
Store_name Sale Date
Los Angeles 1500 Jan-05-1999
San Diego 250 Jan-07-1999
San Francisco 300 Jan-08-1999
Boston 700 Jan-081999

Select Store_name, Sale, Date from Sale_Info ORDER BY Sale DESC;

Result:
Store_name Sale Date
Los Angeles 1500 Jan-05-1999
Boston 700 Jan-081999
San Francisco 300 Jan-08-1999
San Diego 250 Jan-07-1999

9. ARITHMETIC FUNCTIONS
• SUM
• COUNT
• MAX
• MIN
• SUM

SYNTAX for using functions is;


Select <function type> (“colum_name”) FROM
“table_name”
SUM
If we want to get the sum of all sales from table Store_Info
Store_name Sale Date
Los Angeles 1500 Jan-05-1999
Boston 700 Jan-081999
San Francisco 300 Jan-08-1999
San Diego 250 Jan-07-1999

5
Select Sum(sale) from Store_Info;

Result:
Sum (sale)
2750

COUNT

Count function is use to count the no of records in the table.

Select COUNT (Store_name) from Store_Info;

Result:
Count (Store_name)
4

Max

Max function is use to find the maximum values of a particular column.

Select MAX(Sale) from Store_Info;

Result:
MAx(Sale)
1500

MIN

Max function is use to find the maximum values of a particular column.

Select MIN(Sale) from Store_Info;

Result:
MIN(Sale)
250

AVG

6
Select AVG(Sale) from Store_Info;

Result:
AVG(Sale)
687.5

10. GROUP BY

GROUP BY clause ids used to group or categorize the data.


GROUP BY clause is used when we selecting multiple columns
from a table and at least one arithmetic operator appear in the
select statement.

Syntax
Select “column_name1”, Aggregate function (“column_name2”)
FROM “table name”
GROUP BY “column_name1”

Query: Select the total salary of each store in table Store_Info

Table Store_Info
Store_name Sale Date
Los Angeles 1500 Jan-05-1999
San Diego 250 Jan-07-1999
Los Angeles 300 Jan-08-1999
Boston 700 Jan-081999
San Diego 750 Jan-09-1999

Select Store_name, SUM(Sale) FROM Store_Info GROUP BY


Store_name;

7
RESULT:
Store_name SUM(Sale)
Los Angeles 1800
San Diego 1000
Boston 700

11. HAVING CLAUSE


The HAVING Clause was added to SQL because the WHERE
keyword could not be used with aggregate functions .
Syntax
Select “column_name1”, Aggregate function (“column_name2”)
FROM “table name”
GROUP BY “column_name1”
HAVING Aggregate function (“column_name2”) OPERATOR
VALUE

Query: Select the total salary of each store in table Store_Info


where total sum salary of each store is greater than 1500

Table Store_Info
Store_name Sale Date
Los Angeles 1500 Jan-05-1999
San Diego 250 Jan-07-1999
Los Angeles 300 Jan-08-1999
Boston 700 Jan-081999
San Diego 750 Jan-09-1999

Select Store_name, SUM(Sale) FROM Store_Info GROUP BY


Store_name HAVING SUM(Sale)>1500;

RESULT:
Store_name SUM (Sale)
Los Angeles 1800

8
12. INSERT

Insert Command is used to add rows of data into table

Syntax
INSERT INTO table name VALUES (value1, value2, value3,
…………….)
Or
INSERT INTO table name (column1, column2, column3)
VALUES (value1, value2, value3,…………….)

Ex:
If we want to insert a row into following table.

Table Store_Info
Store_name Sale Date
Los Angeles 1500 Jan-05-1999
San Diego 250 Jan-07-1999
Los Angeles 300 Jan-08-1999
Boston 700 Jan-081999
San Diego 750 Jan-09-1999

Query:

INSERT INTO Store_Info Values (‘ABC’, 2000, ‘Feb-10-2000’);

Or

INSERT INTO Store_Info (Store_name, Sale, Date) Values (‘ABC’, 2000,


‘Feb-10-2000’);

9
RESULT:

Store_name Sale Date


Los Angeles 1500 Jan-05-1999
San Diego 250 Jan-07-1999
Los Angeles 300 Jan-08-1999
Boston 700 Jan-081999
San Diego 750 Jan-09-1999
ABC 2000 Feb-10-2000

• Inserting through parameter substitution

Example:
INSERT INTO Store_Info VALUES (&Store_Info, &Sale, &Date);

The output is:


Enter value for Store_Info: ‘XYZ’
Enter value for Sale: 1700
Enter value for Date: ‘June-20-2002’

Result:

Store_name Sale Date


Los Angeles 1500 Jan-05-1999
San Diego 250 Jan-07-1999
Los Angeles 300 Jan-08-1999
Boston 700 Jan-081999
San Diego 750 Jan-09-1999
ABC 2000 Feb-10-2000
XYZ 1700 June-20-2002

10
13. UPDATE

The UPDATE statement is used to update the exiting record in a


table.

SYNTAX:

UPDATE table_name SET column1=value1, column2=value2 ……..


WHERE < condition >

Ex:

UPDATE Store_Info SET SALE = 1800 WHERE Store_name = ‘XYZ’

Result:

Store_name Sale Date


Los Angeles 1500 Jan-05-1999
San Diego 250 Jan-07-1999
Los Angeles 300 Jan-08-1999
Boston 700 Jan-081999
San Diego 750 Jan-09-1999
ABC 2000 Feb-10-2000
XYZ 1800 June-20-2002

14. DELETE COMMAND

Delete command is used to delete rows from the table.

SYNTAX

DELETE FROM < table_name > WHERE < condition>

11
Example:

To delete all records in table Store_Info.

SQL> DELETE Store_Info;

EX:

Delete all records Los Angeles store from table Store_Info.

Store_name Sale Date


Los Angeles 1500 Jan-05-1999
San Diego 250 Jan-07-1999
Los Angeles 300 Jan-08-1999
Boston 700 Jan-081999
San Diego 750 Jan-09-1999
ABC 2000 Feb-10-2000
XYZ 1800 June-20-2002

QUERY:

SQL> DELETE FROM Store_Info WHERE Store_name= ‘Los


Angeles’;

RESULT:

Store_name Sale Date


San Diego 250 Jan-07-1999
Boston 700 Jan-081999
San Diego 750 Jan-09-1999
ABC 2000 Feb-10-2000
XYZ 1800 June-20-2002

12
DATA DEFINITION LANGUAGE
(DDL) STATEMENTS

1. CREATE STATEMENT

The CREATE statement is used to create schema objects of database.

SYNTAX

CREATE TABLE table_name (


Column_name data_type [column_constraint],
Column_name data_type [column_constraint], …
[table_constraint]
)

EXAMPLE

CREARTE TABLE ITEM (


Srial_no number(4),
Item_name varchar2(20),
Price number (4),
Tax number(2),
Category varchar2 (20)
)

RESULT:

SQL> DESC ITEM;

Srial_no Item_name Price Tax Category

13
2. ALTER COMMAND

ALTER TABLE statement is used to change the structure of the exiting


table like to add a column or change the definition of the exiting column
or constraint.

SYNTAX

ALTER TABLE <table_name >


[ADD <column_name>]
[MODIFY <column name>]
[DROP < option >]

EXAMPLE:
(1) Add a new column Total_Amount in table ITEM.

SQL > ALTER TABLE ITEM ADD (Total_amount number (10));

Srial_no Item_name Price Tax Category Total_Amount

(2) To modify Price column of table ITEM by increasing its width to 6.

SQL > ALTER TABLE ITEM Modify Price number(6);

3. DROP CAMMAND
Drop the column Tax of table ITEM.

SQL> Alter table ITEM DROP Column Tax;


RESULT:
Srial_no Item _name Price Category Total_Amount

14
3. RENAME CAMMAND

The rename statement is used to give new name to the exiting table.

SYNTAX

RENAME < Old table_name> to < New table_name>

Ex: Rename the table ITEM to MENU.

SQL> Rename ITEM to MENU;

Table renamed.

4. TRUNCATE STATEMENT

Truncate statement is used to delete the record from a table but data can not
be recovered with truncate statement.

SYNTAX

Truncate Table < table_name>

EX:

SQL > Truncate Table ITEM;

15
DATA TRANSACTION CONTROL
(DCL) STATEMENT

1. COMMIT STATEMENT

The COMMIT statement is used to make a transaction’s changes permanent.

SYNTAX:

COMMIT;

2. ROLLBACK STATEMENT

The ROLLBACK statements used to und changes in transactions,


either since the transaction started or since a savepoint.

SYNTAX:

ROLLBACK;

3. SAVEPOINT STATEMENT

The SAVEPOINT statement is used to set point to which transaction can be


rolled back.

SYNTAX:

SAVEPOINT < savepoint>;

16
DATA CONTROL LANGUAGE
(DCL) STATEMENT

1. GRANT STATEMENT

The GRANT statement is used to grant privileges to the users.

SYNTAX;

GRANT <privileges > on <object name> to <user>


<With grant option>;
Ex:

To give user ‘Mona’ the privileges to update the column Price in table
ITEM.

SQL>GRANT UPDATE(Price) on ITEM to Mona;

Privilege granted.

2. REVOKE STATEMENT

The revoke statement is used to cancel database privileges from user.

SYANTAX:
REVOKE<privileges> on <object name> from <user>;

Ex:
To revoke the privilege we give to use Mona.
SQL>REVOKE UPDATE (Price) on ITEM from Mona;

17
SUB QUERIES
It is possible to embed a SQL statement within another . When this is
done on the WHERE or the HAVING statements, we have a subquery
construct.

EXAMPLE:

(1) To find the details of all the employees who work in the same
department as that of SCOTT.

SQL> SELECT * from emp where (select deptno from emp where
ename= ‘SCOTT’);

(2) Select the highest paid employee of each department.

QUERY:

Select deptno, ename, salary from emp E1 where salary= (Select


Max(salary) from emp where deptno =E1.deptno) order by deptno;

E1 emp
deptno ename salary
10 EDWARD 5000
10 JOHN 3000
20 SMITH 1000
20 SCOTT 7000
20 FORD 3000
30 BLAKE 2850 deptno ename salary
10 EDWARD 5000
10 JOHN 3000
20 SMITH 1000
20 SCOTT 7000
20 FORD 3000
30 BLAKE 2850

18
RESULT:

deptno ename salary


10 EDWARD 5000
20 SCOTT 7000
30 BLAKE 2850
PL/ SQL PROGRAMS

1. CONDITIONAL CONTROL

• If-then statement

Syntax:
If <condition> THEN
Sequence of statement
End if;

Ex:
1. write a PL/SQL program that will accept an account number from
user, check if users balance is less than maximum balance, only than
deduct Rs.100/- from the balance. The process s fired on the
ACCT_MSTR table.

DECLARE
mCUR_BAL number(11,2);
mACCT_NO varchar2 (7);
mFINE number(4) := 100;
mMIN_BAL constant number(7,2) :=5000.00;
BEGIN
mACCT_NO :=&mACCT_NO;
Select CURBAL INTO mCUR_BAL from ACCT_MSTR where
ACCT_NO= mACCT_NO;
IF mCUR_BAL<mMIN_BAL THEN
UPDATE ACCT_NO SET CURBAL=CURBAL-mFINE WHERE
ACCT_NO= mACCT_NO
END IF;

19
END

OUTPUT:
Enter value for mACCt_NO: ‘SB9’
Old 11: mACCT_NO := &mACCt_NO;
New 11: mACCT_NO:= ‘SB9’;
PL\SQL procedure successfully completed
• If-then-else
Syntax:

If<condition>then
Sequence of statement1;
Else
Sequence of statement2;
End if;

Ex;
If a>b then
Dbms_output.put_line (‘a is greater’);
Else
Dbms_output.put_line (‘b is greater’);

End if;

• If-then –elseif
Syntax:

If <condition1>then
Statemaents1;
Elseif<conditin2>then;
Statements2;
Else
Statements3;

20
End if;

2. ITERATIVE CONTROL

• Simple loop statements


Syntax:

Loop
Sequence of statements;
End loop;

.
1. Create a simple loop such that a message is displayed when a loop
exceeds a particular value.

DECLARE
i number :=0;

BEGIN
LOOP
i:=i+2;
EXIT WHEN i>10;
END LOOP;
Dbms_output.putline(“Loop exited as the value of i has reached’ ||
to_char(i));
END;

Output:

Loop exited as the value of i has reached 12


PL\SQL procedure successfully completed

21
• While loop statement

Syntax:
While<condition>loop
Sequence of statement
End loop

Ex:
1. To illustrate a pl/sql block to block to print the desired
multiplication table.

Declare
Table number:=&enter_table_of;
Count number;=1;
Result number;
Begin

While count<=5 loop


Result=table*count;

Dbms_output.put_line(table| |’*’| |count| |’=’| |result);


Count:=count+1;
End loop;

End;

Output:

Enter_table_of 5

22
5*1=5
5*2=10
5*3=15
5*4=20
5*5=25

Pl/sql procedure successfully completed

2. write a PL\SQL code block to calculate the area of the circle for a
value of radius varying from 3 to 7. Store the radius and the
corresponding values of calculated area in an empty table names
AREAS, consisting of two columns Radius and Area.

Create table AREAS (Radius number(50 ,Area number(14,2));

DECLARE

PI constant number(4,2): = 3.14;


Radius number(5);
Area number(14,2);

BEGIN
Radius: =3;
WHILE Radius<=7
LOOP
AREA: = PI * power(Radius,2);
INSERT INTO AREAS values(Radius, Area);
Radius: =Radius+1;
END LOOP;
END

OUTPUT
Table NAME: AREAS
Radius Area
3 28.26
4 50.24
5 78.5
6 113.04

23
7 153.86

• For - loop statement

Syntax:

For <counter>in [reverse] <lower bound> .. <higher bound>loop


Sequence of statements;
End loop;

Ex:
write a PL/SQL block of code for inverting 5639 to 9365.

DECLARE

given_number varchar(5):= 5639;


str_length number(2);
inverted_number varchar(5);

BEGIN
str_length: = length(given_number);

FOR cntr IN REVERSE 1..str_length

LOOP
Inverted_number := inverted_number || substr(given_number,cntr,1);
END LOOP;

Dbms_output.putline(‘The Given number is’ || given_number);


Dbms_output.putline(‘The Inverted number is’ || inverted_number);
END;

OUTPUT:
The Given number is 5639

24
The Inverted number is 9365

3. SEQUENTIAL CONTROL

• goto statement
Syntax:
GOTO < codeblock name>
Example:

Write a PL/SQL block of code to achieve the following : if there are no


transactios taken place in the last 365 days then mark inactive , and
record the account number, the opening date and the type of account in
the INACTIVE_ACCT_MSTR.

Table Name: INACTIVE_ACCT_MSTR table


ACCT_NO OPNDT TYPE

Create table INACTIVE_ACCT_MSTR (ACCT_NO varchar2(10,


OPNDT DATE varchar2(2));

DECLARE
mACCT_NO varchar2(10);
mANS varchar varchar2(3);
mOPEN date;
mTYPE varchar2(2);

BEGIN
mACCT_NO:=& mACCT_NO;
Select ‘Yes’ INTO mANS from TRANS_MSTR where
ACCT_NO:= mACCT_NO Group by ACCT_NO HAVING
MAX(SYSDATE-DT)>365;

IF Mans = ‘Yes’ THEN

25
GOTO mark_status;
ELSE
dbms_output.putline(‘ Account number:’|| mACCT_NO || ‘is active’);
END IF;

<<MARK STATUS>>
UPDATE ACCT_MSTR SET STATUS = ‘T’ WHERE
ACCT_NO= mACCT_NO;

SELECT OPNDT ,TYPE INTO mOPNDT ,mTYPE from ACCT_MSTR


where ACCT_NO= mACCT_NO;

INSERT INTO INACTIVE_ACCTMSTR(ACCT_NO ,OPNDT ,TYPE)


VALUES(mACCT_NO , mOPNDT ,mTYPE);

dbms_output.putline(‘ Account number:’|| mACCT_NO || ‘is marked as in


active’);

END;

Pl/sql code first fetches the Accout number from the user into a variable
mACCT_NO. It then verifies using an sql statement, whether any
transaction are performed within last 365 days.

If they are ,then a message stating “Account Number_is active” is displayed.

But if there are no transactions performed in last 365 days then a value
“Yes” is stored in a variable named mANS.

Based on the vaue held in this variable the ACCT_MSTR table is updated
by setting the value held in the field STATUS to I.

This is followed by an insert statement , which inserts the account number


the opening date and the type of that account in the
INACTV_ACCT_MSTR table.

Finally a message stating “ Accounting Number_is marked as inactive” is


displayed.

26
CURSOR

• IMPLICIT CURSOR

EXAMPLE:
The bank manager of Darya Ganj branch decides to activate all those
accounts, which were previously marked as inactive for performing no
transaction in lats 365 days. Write a pl/sql block to update the status
of accounts . Display an appropriate message based on number of
rows affected by the update fired

DECLARE
Rows_Affected char(4);
BEGIN
UPDATE ACCT_MSTR SET STATUS= ‘A’ WHERE STATUS =
‘S’ AND BRANCH_NO IN (SELECT BRANCH_NO FROM
BRANCH_MSTR WHERE NAME = ‘Darya Ganj’);

Rows_affected := TO_CAHR(SQL%ROWCOUNT);

IF QL%ROWCOUNT >0 THEN


Dbms_output.put_line(Rows_Affected || ‘Account(s) Activated
Successfully’);
ELSE
dbms_output.put_line(‘Currently there exit no Inactive Account in
the Darya Ganj Branch’);
END IF
END

OUTPUT
2 Account (s) Activated Successfully
PL/SQL procedure successfully completed.

27
.
• EXPLICIT CURSOR

EXAMPLE:

Write a pl/sql block that will display the customer anme , the fixed
deposit number and the fixed deposit amount of the first 5 customers
holding highest amount in fixed deposit.

DECLARE
CURSOR Crsr_HiFD IS SELECT FNAME || ‘ ‘ || LNAME , FD_NO,AMT
FROM CUST_MSTR C, ACCT_FD_CUST_DTLS F
WHERE C.CUST_NO=A.CUST_NO AND
A.ACCT_FD_NO=F.FD_SER_NO
ORDER BY AMT Desc ;

Str_NMAE varchar2(50);
Str_FD_NO FD_DTLS.FD_NO%type;
num_AMT FD_DTLS.AMT%type;

BEGIN
OPEN Crsr_HiFD;
dbms_output.put_line(‘Name FD No. Amount’);
dbms_output.put_line(‘………………………’);
LOOP
FETCH Crsr_Hifd INTO str_NAME ,str_FD_NO, num_AMT;
EXIT WHEN(Crsr_HiFD%ROWCOUNT-1)=5 OR Crsr_HiFd
%NOTFOUND;
dbms_output.put_line(‘str_Name|| ‘ ‘ || str_ FD No.|| ‘ ‘||num_AMT);
END LOOP;
END

OUTPUT :
Name FD No. Amount
Chriselle F1 15000

28
Mamta F1 15000
Ashwini F7 15000
Chhaya F3 10000
Chhaya F4 10000
PL/SQL procedure successfully completed.

TRIGGERS

Eg:
1. Write a database trigger on the TRANS_MSTR that
checks the account number for which the transaction
is begin performed is a valid account number.
CREATE OR REPLACE TRIGGER TRANS_CHECK
BEFORE INSERT ON TRANS_MSTR FOR EACH ROW
DECLARE
v_CNT_ACCT_NO VARCHAR2(10);
v_CURBAL NUMBER(10);
BEGIN
SELECT COUNT(ACCT_NO) INTO v_CNT_ACCT_NO
FROM ACCT_MSTR WHERE
ACCT_NO=:new ACCT_NO;
IF v_CNT_ACCT_NO=0 THEN
RAISE_APPLICATION_ERROR(-20000,’The
Account number is invalid.’);
END IF;
IF :new.AMT<=0 THEN
RAISE_APPLICATION_ERROR(-20001,’The Transaction
amount cannot be negative or zero.’);

29
END IF;

SELECT CURBAL INTO v_CURBAL FROM ACCT_MSTR


WHERE ACCT_NO=:new.ACCT_NO;
IF v_CURBAL<:new.AMT AND :new DR_CR=’W’ THEN
RAISE_APPLICATION_ERROR(-20002,’The amount of
withdrawal cannot exceed the balance held in the
account’);
END IF;
END;
Output:
Trigger Created.
INSERT INTO TRANS_MSTR
(TRANS_NO,ACCT_NO,DT,TYPE,PARTICULAR,
DR_CR,AMT,BALANCE) VALUES(‘T32’,’15-DEC-
2003’,’B’,’Initial Payment’,’D’,-2,500);
INSERT INTO
TRANS_MSTR(TRANS_NO,ACCT_NO,DT,TYPE,PARTICULAR,DR_
CR, AMT, BALANCE)
*
ERROR at line 1:
ORA-20001: The Transaction amount cannot be negative or
zero.
ORA-06512: at “DBA_BANKSYS.TRANS_CHECK”, line 16
ORA-04088: error during execution of trigger
‘DBA_BANKSYS.TRANS_CHECK’

30
EX: 2. Create a system that must keep track of
records that are being deleted or updated in custmstr
and place modified records in auditcust table.
Create table custmstr(no varchar2(5),name varchar2(7),dob
date);
Table created;
Create table auditcust (custno varchar2(8),name
varchar2(7),dob date,operation varchar2(5).odate
date);
Table created;
Create trigger audit_trail
after update or delete on custmstr for each row
declare
oper varchar2(8);
begin
if updating then
oper:=’update’;
else
oper:=’delete’;
end if;

31
insert into auditcust values(
:old.no,:old.name,:old.dob,oper,user,sysdate);
end;

Output:
trigger created;
observations:
select * from custmstr;
output
NO NAME dob
Cr76 john 18-08-89
Cr56 aline 21-08-90
Update custmstr set dob=25-09-90 where
name=’john’;
Select * from auditcust;
NO NAME dob operation odate
---------- ------------------------- --------------- ----------
Cr76 john 18-08-89 update 30-10-10

32
INDEX

1. DATA MANIPULATIONS

SELECT

DISTINCT

WHERE Clause

OR & AND

IN Operator

BETWEEN

LIKE

ORDER BY

Arthmetic Functions

• SUM()

• COUNT()

• The MAX() Function

• MIN() Function

• AVG() Function

GROUP BY

INSERT

UPDATE

DELETE

2. DATA DEFINITIONS LANGUAGE(DDL)

33
CREATE

ALTER

DROP

RENAME

TRUNCATE

3. DATA TRANSACTION CONTROL LANGUAGE(TCL)

COMMIT

ROLLBACK

SAVEPOINT

4. DATA CONTROL LANGUAGE(DCL)

GRANT

REVOKE

5. SUB QUERIES
6. PL/SQL PROGRAMS
7. CURSORS
8. TRIGGERS

34

You might also like