Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

ASSIGNMENT 3

NAME – APURBA GHOSH


BRANCH – CSE-‘A’ (3RD YEAR, 6TH SEM)
ROLL NO. – 23
UNIVERSITY ROLL NO . – 12500117096
SUBJECT – DBMS
SUBJECT CODE – CS-601
ANSWERS –

1.(SOLUTION)

1. DECLARE
2.     N NUMBER;
3.     M NUMBER;
4. BEGIN
5.     DBMS_OUTPUT.PUT_LINE('ENTER A NUMBER');
6.     N:=&NUMBER;    
7.     DBMS_OUTPUT.PUT_LINE('ENTER A NUMBER');
8.     M:=&NUMBER;
9. IF N<M THEN
10.     DBMS_OUTPUT.PUT_LINE(''|| N ||' IS GREATER THAN '|| M
||'');
11. ELSE
12.     DBMS_OUTPUT.PUT_LINE(''|| M ||' IS GREATER THAN '|| N
||'');
13. END IF;
14. END;
15. /
2.(SOLUTION)

Following are the three ways used to pass parameters to procedure.

1. IN parameter
It indicates that the parameter will accept a value from the user.

2. Out parameter
It indicates that the parameter will return a value to the user.   

3. IN OUT
It indicates that the parameter will either accept a value from the user or return a
value to the user.

Example: Stored procedure using In and Out mode.


This procedure computes the square of a passed value.
This example shows how same parameter is used to accept a value and then
return another result.

1. DECLARE
2.    a number;
3. PROCEDURE squareNum(x IN OUT number) IS
4. BEGIN
5.  x := x * x;
6. END;
7. BEGIN
8. a:= 2;
9.  squareNum(a);
10.  dbms_output.put_line(' Square of (2): ' | |  a);
11.END;
12./

Output:
Square of (2): 4
3.(SOLUTION)

A stored procedure to accept a INOUT parameter (genericParam), construct the


output message and assign back to the same parameter name(genericParam)
again.

CREATEORREPLACEPROCEDUREprocOneINOUTParameter(genericParam
INOUT VARCHAR2)
IS
BEGIN

genericParam :='Hello'||genericParam;

END;
/
Copy

Run it

DECLARE
genericParam VARCHAR2(100) :='Apurba Ghosh';
BEGIN
procOneINOUTParameter(genericParam);
DBMS_OUTPUT.PUT_LINE(genericParam);
END;
/
Copy

Output

Hello Apurba Ghosh

You might also like