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

RDBMS Practical 5

This ise rdbms notes.

Uploaded by

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

RDBMS Practical 5

This ise rdbms notes.

Uploaded by

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

Practical No -5

Write a PL-SQL code snippet to illustrate the implementation of Function.

The PL/SQL Function is very similar to PL/SQL Procedure. The main difference between procedure and a
function is, a function must always return a value, and on the other hand a procedure may or may not return
a value. Except this, all the other things of PL/SQL procedure are true for PL/SQL function too.

Syntax to create a function:

DELIMITER $$

CREATE [OR REPLACE] FUNCTION function_name(

param1,

param2,…

RETURNS datatype

[NOT] DETERMINISTIC

BEGIN

-- statements

END $$

DELIMITER ;

Here:

• Function_name: specifies the name of the function.


• [OR REPLACE] option allows modifying an existing function.
• A deterministic function always returns the same result for the same input parameters whereas a non-
deterministic function returns different results for the same input parameters.
If you don’t use DETERMINISTIC or NOT DETERMINISTIC, MySQL uses the NOT
DETERMINISTIC option by default.

Name : Aatif Nayeem


Roll no : 18DCS003
CREATING A FUNCTION

DELIMITER $$

CREATE OR REPLACE FUNCTION StudentFeeLevel(fee int(25))

RETURNS VARCHAR(25)

DETERMINISTIC

BEGIN

DECLARE FeeLevel VARCHAR(25);

IF fee > 7000 THEN

SET FeeLevel = 'HIGH';

ELSEIF fee < 7000 THEN

SET FeeLevel = 'LOW';

END IF;

RETURN (FeeLevel);

END$$

DELIMITER ;

Name : Aatif Nayeem


Roll no : 18DCS003
Output

SHOWING FUNCTION STATUS

SHOW FUNCTION STATUS

WHERE db = 'pl/sql_4

Output

Name : Aatif Nayeem


Roll no : 18DCS003
CALLING STORED FUNCTION

SELECT

student_id,

student_name,

student_dept,

fee,

StudentFeeLevel(fee)

FROM

student

ORDER BY

student_id;

Name : Aatif Nayeem


Roll no : 18DCS003
Output

Name : Aatif Nayeem


Roll no : 18DCS003

You might also like