Oracle Practical Program - 240625 - 100611-1
Oracle Practical Program - 240625 - 100611-1
SQL> /
Enter value for emp_no: 104
Enter value for emp_name: Deva
Enter value for designation: Senior_Clerk
Enter value for gender: M
Enter value for age: 32
Enter value for date_of_join: 30-MAR-2000
Enter value for salary: 20100
old 1: insert into employee
values(&Emp_No,'&Emp_Name','&Designation','&Gender',&Age,'&Date_of_Join',&Salary)
new 1: insert into employee values(104,'Deva','Senior_Clerk','M',32,'30-MAR-2000',20100)
1 row created.
SQL> select * from employee;
****
SQL> create table emp_table(
2 empno number,
3 DOB date);
*****
Comparison and Logical operators
SQL> select * from employee where age <= 30 and age > 20;
Group Commands
SQL> select empno from employee union all select empno from emp_table;
SQL> select empno from employee minus select empno from emp_table;
Sort Commands
SQL> select * from employee order by gender;
*******
1 row created.
SQL> /
Enter value for product_number: 002
Enter value for product_name: Pencil
Enter value for price: 5
old 1: insert into inventory values(&Product_Number,'&Product_Name',&Price)
new 1: insert into inventory values(002,'Pencil',5)
1 row created.
SQL> /
Enter value for product_number: 003
Enter value for product_name: Scale
Enter value for price: 8
old 1: insert into inventory values(&Product_Number,'&Product_Name',&Price)
new 1: insert into inventory values(003,'Scale',8)
1 row created.
SQL> /
Enter value for product_number: 004
Enter value for product_name: Box
Enter value for price: 25
old 1: insert into inventory values(&Product_Number,'&Product_Name',&Price)
new 1: insert into inventory values(004,'Box',25)
1 row created.
PL/SQL (Type “ed” which open notepad, clear all the content, type the following pl/sql
and save the file with “.sql” extension, )
declare
cursor c is select prono,proname,rate from inventory;
pno inventory.prono%type;
pname inventory.proname%type;
prate inventory.rate%type;
begin
open c;
dbms_output.put_line('******* Price List after the updation of Rate*********');
dbms_output.put_line('Product No Product Name Rate');
dbms_output.put_line('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~');
loop
fetch c into pno,pname,prate;
prate := prate + ((prate*20)/100);
update inventory set rate = prate where prono = pno;
dbms_output.put_line(to_char(pno,'999')||' '||trim(pname)||' '||to_char(prate,'9999.99'));
exit when c%notfound;
end loop;
end;
/
Table altered.
1 row updated.
1 row updated.
1 row updated.
SQL> update inventory set noi = 25 where prono = 004;
1 row updated.
SQL> /
Enter value for product_no: 002
Enter value for prodct_name: DVD
Enter value for price: 18
Enter value for stock_in_hand: 100
1 row created.
SQL> /
Enter value for product_no: 003
Enter value for prodct_name: Pendrive
Enter value for price: 350
Enter value for stock_in_hand: 10
1 row created.
trig.sql
create or replace trigger t1 after insert or update on trans for each row
declare
cursor c1 is select * from master where pno = :new.p_no;
begin
for i in c1 loop
if i.stock < :new.no_pro_sold then
raise_application_error(-20001,'No.of Product more than stock, error');
end if;
end loop;
end;
/
SQL> @e:\trig.sql
Trigger created.
1 row created.
P_NO NO_PRO_SOLD
---------- -----------
1 20
4. Bank Account Management – Exception Handling
Aim
Write a PL/SQL to raise the following Exception in Bank Account Management table
when deposit amount is zero.
Algorithm
1. Start the process.
2. Create a PL/SQL procedure to handle the Exception
3. Check the deposit amount is greater than zero
4. If yes then allow transaction
5. Else decline the transaction with Exception
6. Terminate the process.
Table created.
bank.sql
declare
zero_deposit exception;
cust bank%rowtype;
begin
cust.accno := &Account_no;
cust.c_name := '&Customer_Name ';
cust.acc_type := '&Account_Type ';
cust.dep_amt := &Deposit_amount;
if cust.dep_amt <= 0 then
raise zero_deposit;
else
insert into bank values(cust.accno,cust.c_name,cust.acc_type,cust.dep_amt);
end if;
exception
when zero_deposit then
dbms_output.put_line('*******Deposit Amount cannot be zero*****');
end;
/
SQL> set serveroutput on
SQL> @e:\bank.sql
Enter value for account_no: 2
old 5: cust.accno := &Account_no;
new 5: cust.accno := 2;
Enter value for customer_name: Arun
old 6: cust.c_name := '&Customer_Name ';
new 6: cust.c_name := 'Arun ';
Enter value for account_type: Saving
old 7: cust.acc_type := '&Account_Type ';
new 7: cust.acc_type := 'Saving ';
Enter value for deposit_amount: 12000
old 8: cust.dep_amt := &Deposit_amount;
new 8: cust.dep_amt := 12000;
SQL> /
Enter value for account_no: 3
old 5: cust.accno := &Account_no;
new 5: cust.accno := 3;
Enter value for customer_name: Balu
old 6: cust.c_name := '&Customer_Name ';
new 6: cust.c_name := 'Balu ';
Enter value for account_type: current
old 7: cust.acc_type := '&Account_Type ';
new 7: cust.acc_type := 'current ';
Enter value for deposit_amount: 8500
old 8: cust.dep_amt := &Deposit_amount;
new 8: cust.dep_amt := 8500;
SQL> @e:\bank.sql
Enter value for account_no: 4
old 5: cust.accno := &Account_no;
new 5: cust.accno := 4;
Enter value for customer_name: Chandru
old 6: cust.c_name := '&Customer_Name ';
new 6: cust.c_name := 'Chandru ';
Enter value for account_type: saving
old 7: cust.acc_type := '&Account_Type ';
new 7: cust.acc_type := 'saving ';
Enter value for deposit_amount: 0
old 8: cust.dep_amt := &Deposit_amount;
new 8: cust.dep_amt := 0;