0% found this document useful (0 votes)
14 views5 pages

Ans

Uploaded by

pranavsp2810
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)
14 views5 pages

Ans

Uploaded by

pranavsp2810
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/ 5

19.Write a PL/SQL program which accepts the customer_ID from the user.

If the

enters an invalid ID then the exception invalid_id is raised using exception

handling.

6M

Ans

DECLARE

c_id numeric(10);

invalid_id_Exception Exception;

BEGIN

c_id:=&c_id;

if(c_id<0) then

raise invalid_id_Exception;

end if;

EXCEPTION

WHEN invalid_id_Exception THEN

dbms_output.put_line('Invalid customer id');

END;

22.Write a PL/SQL code to print reverse of a number. 4 M

Ans

PL/SQL code to print reverse of a number:

declare

n number;
i number;

rev number:=0;

r number;

begin

n:=&n;

while n>0

loop

r:=mod(n,10);

rev:=(rev*10)+r;

n:=trunc(n/10);

end loop;

dbms_output.put_line('reverse is '||rev);

end;

23.Write SQL queries for following.

1) Create user named 'user1' having Password '1234

ii) Assign 'insert' and update' Privilege to 'userl".

ii) Remove update Privilege assigned to the userl.

iv) Assign the resource Pemission to userl.

6M

Ans

i. create user user1 identified by 1234;

ii. grant insert, update on system.emp to user1;


iii. revoke update on system.emp from user1;

iv. grant create session, unlimited tablespace, create table to user1;

17. Write a PL/SQL code to check whether specified employee is present in

Emp table or not. Accept empno from user. If employee does not exist

display message using exception handling.

Ans

PL/SQL Program:

declare

no emp.empno%type;

begin

no:=&no;

select empno into no from emp where empno=no;

dbms_output.put_line('Empno is present: '||no);

exception

when no_data_found then

dbms_output.put_line('Empno not present');

end;
21. Implicit Cursor Example:

Create customers table and have records. update the table and increase
salary of each customer by 5000

ans
DECLARE

total_rows number(2);

BEGIN

UPDATE customers

SET salary = salary + 5000;

IF sql%notfound THEN

dbms_output.put_line('no customers updated');

ELSIF sql%found THEN

total_rows := sql%rowcount;

dbms_output.put_line( total_rows || ' customers updated ');

END IF;

END;

23.Create explicit cursor .

Ans

DECLARE

c_id customers.id%type;

c_name customers.name%type;
c_addr customers.address%type;

CURSOR c_customers is

SELECT id, name, address FROM customers;

BEGIN

OPEN c_customers;

LOOP

FETCH c_customers into c_id, c_name, c_addr;

EXIT WHEN c_customers%notfound;

dbms_output.put_line(c_id || ' ' || c_name || ' ' || c_addr);

END LOOP;

CLOSE c_customers;

END;

1. Consider the following schema Depositor (ACC_no, Name, PAN, Balance).


Create a

view on Depositor having attributes(ACC_No,PAN) where balance is greater than

100000

Ans: create view v1

as

select ACC_No,PAN

from Depositor

where balance > 100000;

You might also like