0% found this document useful (0 votes)
54 views3 pages

Assignment 8dbms

The document contains 5 questions related to PL/SQL code. Question 1 displays customer details for a customer with ID of 2. Question 2 displays customer details for a customer selected by the user. Question 3 updates the branch number for an employee selected by the user. Question 4 updates inactive customer accounts to active status if they have not performed transactions in the last 365 days. Question 5 contains a PL/SQL block that withdraws then deposits an amount, checks the total balance of all accounts, and rolls back the deposit if the total balance exceeds Rs. 200,000.

Uploaded by

subham
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
0% found this document useful (0 votes)
54 views3 pages

Assignment 8dbms

The document contains 5 questions related to PL/SQL code. Question 1 displays customer details for a customer with ID of 2. Question 2 displays customer details for a customer selected by the user. Question 3 updates the branch number for an employee selected by the user. Question 4 updates inactive customer accounts to active status if they have not performed transactions in the last 365 days. Question 5 contains a PL/SQL block that withdraws then deposits an amount, checks the total balance of all accounts, and rolls back the deposit if the total balance exceeds Rs. 200,000.

Uploaded by

subham
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 3

Question 1:-

Write a PL/SQL to display the Customer details of customer with id =2.


Query
set serveroutput on;
declare
r_customer customers%rowtype;
begin
select * into r_customer from customers where cust_id=2;
dbms_output.put_line(‘Customer Name: ‘||r_customer.cust_first_name||’’||
r_customer.cust_last_name); dbms_output.put_line(‘Phone No: ‘||
r_customer.cust_main_phone_number); dbms_output.put_line(‘Phone No: ‘||
r_customer.cust_email);
end;
Output:

Question:-2
Write a PL/SQL to display the Customer details of customer which user wants.
Query
set serveroutput on;
declare
r_customer customers%rowtype;
begin
select * into r_customer from customers where cust_id=2;
dbms_output.put_line(‘Customer Name: ‘||r_customer.cust_first_name||’’||
r_customer.cust_last_name); dbms_output.put_line(‘Phone No: ‘||
r_customer.cust_main_phone_number); dbms_output.put_line(‘Phone No: ‘||
r_customer.cust_email);
end;
Output:
Question:-3
The bank manager has decided to transfer employees across branches. Write a PL/SQL block to accept
an employee number and the branch number followed by updating the branch number of that employee
to which he belongs appropriately. Display an appropriate message using SQL%FOUND based on the
existence of the record in the EMP_MSTR table. Display .an appropriate message using SQL
%NOTFOUND based on the non- existence of the record in the EMP_MSTR table.
Query
set serveroutput on;
declare
begin
update employees_176 set branch=&branch where
employee_id=&employee_id;
if sql%found then
dbms_output.put_line(‘Employee Successfully transferred’); else
dbms_output.put_line(‘Employee not found’); end if;
end;
Output:-

Question:-4
The bank manager of Junagadh branch decides to activate all those accounts, which were previously
marked as inactive for performing no transactions in last 365 days. Write a PL/SQL block to update
the status of accounts. Display an appropriate message based on the number of rows affected by the
update fired.
Query
set serveroutput on; declare
v_rowcount number; begin
update customers_176 set cust_valid=’A’ where
cust_valid=’I’; v_rowcount:=sql%rowcount;
dbms_output.put_line(v_rowcount|| ‘accounts activated successfully’);
end;
Output:-
Question:-5
Write a PL/SQL block of code that first withdraws an amount of Rs. 1000. Then deposits an amount of Rs.
1,40,000. Update the current balance. Then check to see that the current balance of ALL the accounts in the
bank does not exceed Rs. 2,00,000. If the balance exceeds, then undo the deposit just made. (Hint: create
EMP_MSTR table before writing this block)
Query:-
create table trans_mstr
(
trans_no varchar2(5),
acct_no varchar2(5),
dt date,
type varchar2(2),
particular varchar2(15),
dr_cr varchar2(2),
amt number(8),
balance number(9)
);
create table acct_mstr(acct_no varchar2(5),curbal number(10));
insert into acct_mstr values('ca10',8000);
insert into acct_mstr values('ca11',80000);

DECLARE
mbal number(8,2);
BEGIN
insert into trans_mstr values('t100','ca10','04-jul-2004','c','telephone','w',1000,31000);
update acct_mstr set curbal=curbal-1000 where acct_no='ca10';

savepoint no_update;
insert into trans_mstr values('t101','ca10','04-jul-2004','c','deposite','s',140000,171000);
update acct_mstr set curbal=curbal+140000 where acct_no='ca10';
select sum(curbal) into mbal from acct_mstr;

if mbal>200000 then
rollback to savepoint no_update;
end if;
commit;
END;

Output:-

You might also like