0% found this document useful (0 votes)
46 views11 pages

Wa0007.

The document describes experiments involving SQL commands to create tables, insert data, update data, and create triggers. In EXP 11, a table is created to store customer account information. Data is inserted for 3 customers and selected to view all records. A PL/SQL block is used to check if a given account number exists and print the associated balance. In EXP 12, an employees table is created and populated. A cursor is used in a PL/SQL block to update salaries for employees in the 'research' department and print the names and salaries. In EXP 13, a clg table is created and data inserted. A cursor is used to copy records from clg to a new clg1 table

Uploaded by

cseclbrce
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views11 pages

Wa0007.

The document describes experiments involving SQL commands to create tables, insert data, update data, and create triggers. In EXP 11, a table is created to store customer account information. Data is inserted for 3 customers and selected to view all records. A PL/SQL block is used to check if a given account number exists and print the associated balance. In EXP 12, an employees table is created and populated. A cursor is used in a PL/SQL block to update salaries for employees in the 'research' department and print the names and salaries. In EXP 13, a clg table is created and data inserted. A cursor is used to copy records from clg to a new clg1 table

Uploaded by

cseclbrce
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

EXP 11,12,13

EXP 11:
create table cust(accountno number(9),name char(10),balance number(6));

Table created.

SQL> insert into cust values(&accountno,'&name',&balance);


Enter value for accountno: 39507848
Enter value for name: sandeep
Enter value for balance: 3000
old 1: insert into cust values(&acountno,'&name',&balance)
new 1: insert into cust values(39507848,'sandeep',3000)

1 row created.

SQL> /
Enter value for accountno: 39509443
Enter value for name: sita
Enter value for balance: 5000
old 1: insert into cust values(&acountno,'&name',&balance)
new 1: insert into cust values(39509443,'sita',5000)

1 row created.

SQL> /
Enter value for accountno: 39509556
Enter value for name: sharath
Enter value for balance: 10000
old 1: insert into cust values(&acountno,'&name',&balance)
new 1: insert into cust values(39509556,'sharath',10000)

1 row created.

SQL> select * from cust;

ACCOUNTNO NAME BALANCE


---------- ---------- ----------
39507848 sandeep 3000
39509443 sita 5000
39509556 sharath 10000

SQL> set serveroutput on;


SQL> declare
accno cust.accountno%type:=&accountno;
bal cust.balance%type;
begin
select balance into bal from cust where accountno=accno;
if sql% notfound then
dbms_output.put_line('no record found');
else
dbms_output.put_line('record found');
dbms_output.put_line(accno||'has balance of'||bal||'balance');
end if;
end;
/
Enter value for accountno: 39507848
old 2: accno cust.accountno%type:=&accountno;
new 2: accno cust.accountno%type:=39507848;
record found
39507848has balance of3000balance

PL/SQL procedure successfully completed.


SQL> /
Enter value for accountno: 39509943
old 2: accno cust.accountno%type:=&accountno;
new 2: accno cust.accountno%type:= 39509943;
record found
39509943has balance of5000balance

PL/SQL procedure successfully completed.


EXP 12:
SQL>create table employees(sid varchar(3),ename varchar(10),depts char(15),salary
number(8));

Table created.

SQL> insert into employees values('&sid','&ename','&depts',&salary);


Enter value for sid: 220
Enter value for ename: sam
Enter value for depts: research
Enter value for salary: 10000
old 1: insert into employees values('&sid','&ename','&depts',&salary)
new 1: insert into employees values('220','sam','research',10000)

1 row created.

SQL> /
Enter value for sid: 320
Enter value for ename: smith
Enter value for depts: research
Enter value for salary: 20000
old 1: insert into employees values('&sid','&ename','&depts',&salary)
new 1: insert into employees values('320','smith','research',20000)

1 row created.
SQL> /
Enter value for sid: 420
Enter value for ename: james
Enter value for depts: it
Enter value for salary: 30000
old 1: insert into employees values('&sid','&ename','&depts',&salary)
new 1: insert into employees values('420','james','it',30000)

1 row created.

SQL> select * from employees;

SID ENAME DEPTS SALARY


--- ---------- --------------- ----------
220 sam research 10000
320 smith research 20000
420 james it 30000

SQL> set serveroutput on;


declare
name employees.ename%type;
sa employees.salary%type;
dept employees.depts%type;
cursor c1 is select ename,salary from employees where depts='research';
begin
open c1;
update employees set salary=salary+((salary)*1.5) where depts='research';
loop
fetch c1 into name,sa;
exit when c1 % notfound;
dbms_output.put_line(name||'having sal'||sa);
end loop;
close c1;
end;
/
samhaving sal10000
smithhaving sal20000

EXP 13:
SQL> create table clg(id number(2),dept char(5),course char(10));

Table created.

SQL> insert into clg values(&id,'&dept','&course');


Enter value for id: 11
Enter value for dept: it
Enter value for course: btech
old 1: insert into clg values(&id,'&dept','&course')
new 1: insert into clg values(11,'it','btech')

1 row created.

SQL> /
Enter value for id: 12
Enter value for dept: cse
Enter value for course: pg
old 1: insert into clg values(&id,'&dept','&course')
new 1: insert into clg values(12,'cse','pg')

1 row created.

SQL> /
Enter value for id: 13
Enter value for dept: mech
Enter value for course: ug
old 1: insert into clg values(&id,'&dept','&course')
new 1: insert into clg values(13,'mech','ug')

1 row created.

SQL> select * from clg;

ID DEPT COURSE
---------- ----- ----------
11 it btech
12 cse pg
13 mech ug
SQL> create table clg1(id number(2),course char(10));

Table created.

set serveroutput on;


declare
id clg.id%type;
co clg.course%type;
cursor c2 is select id,course from clg;
begin
open c2;
loop
exit when c2 % notfound;
fetch c2 into id,co;
insert into clg1 values(id,co);
end loop;
close c2;
end;
/
PL/SQL procedure successfully completed.

SQL> select * from clg1;

ID COURSE
---------- ----------
11 btech
12 pg
13 ug
13 ug
EXP 14:
SQL> create table account (acct_num number(5), amount number(5));

Table created.

SQL> insert into account values(&acct_num,&amount);


Enter value for acct_num: 2341
Enter value for amount: 3000
old 1: insert into account values(&acct_num,&amount)
new 1: insert into account values(2341,3000)

1 row created.

SQL> /
Enter value for acct_num: 2612
Enter value for amount: 5000
old 1: insert into account values(&acct_num,&amount)
new 1: insert into account values(2612,5000)

1 row created.

SQL> /
Enter value for acct_num: 7896
Enter value for amount: 4000
old 1: insert into account values(&acct_num,&amount)
new 1: insert into account values(7896,4000)
1 row created.

SQL> select * from account;

ACCT_NUM AMOUNT
---------- ----------
2341 3000
2612 5000
7896 4000
set serveroutput on;
create trigger updcheck1 before update on account
for each row
begin
if new.amount < 0 then
set new.amount = 0;
elseif new.amount > 100 then
set new.amount = 100;
end if;
end;
/

You might also like