You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Give this Repository a ⭐️⭐️ Star ⭐️⭐️ for updates.
COPY PASTE ALL THE QUERIES ONE BY ONE IN SQLPLUS TO EXECUTE IT WITHOUT ANY ERROR
PL/SQL Functions
** Execute this command in sqlplus 1st **
TO display output in the screen – give the below command initially
set serveroutput on;
1) creates a simple procedure that displays the string Hello World!; on the screen when executed
CREATE OR REPLACE PROCEDURE display_hello_world IS
BEGINDBMS_OUTPUT.PUT_LINE('Hello World!');
END;
/
EXECUTE display_hello_world;
2) Create a procedure to find the minimum of two values. HINT - Procedure takes two numbers using the IN mode and returns their minimum using the OUT parameters
CREATE OR REPLACE PROCEDURE find_minimum (
num1 INNUMBER,
num2 INNUMBER,
min_num OUT NUMBER
) IS
BEGIN
IF num1 < num2 THEN
min_num := num1;
ELSE
min_num := num2;
END IF;
END;
/
DECLARE
num1 NUMBER :=10;
num2 NUMBER :=5;
min_num NUMBER;
BEGIN
find_minimum(num1, num2, min_num);
DBMS_OUTPUT.PUT_LINE('The minimum of '|| num1 ||' and '|| num2 ||' is '|| min_num);
END;
/
3) Create a procedure, to get cube of passed number.
CREATE OR REPLACE PROCEDURE get_cube (
num INNUMBER,
cube_num OUT NUMBER
) IS
BEGIN
cube_num := num * num * num;
END;
/
DECLARE
num NUMBER :=5;
cube NUMBER;
BEGIN
get_cube(num, cube);
DBMS_OUTPUT.PUT_LINE('The cube of '|| num ||' is '|| cube);
END;
/
4) Write a procedure to reverse a input string and check it is palindrome or not.
CREATE OR REPLACE PROCEDURE check_palindrome(input_string INVARCHAR2) IS
reversed_string VARCHAR2(4000);
BEGIN-- Reverse the input string
reversed_string := REVERSE(input_string);
-- Check if the reversed string is equal to the input string
IF input_string = reversed_string THEN
DBMS_OUTPUT.PUT_LINE('The input string is a palindrome.');
ELSE
DBMS_OUTPUT.PUT_LINE('The input string is not a palindrome.');
END IF;
END check_palindrome;
/
BEGIN
check_palindrome('level');
END;
/
5) Write a procedure to delete a specific row from the table already created.
CREATETABLEstudent4 (
id NUMBER(10) PRIMARY KEY,
name VARCHAR2(100) NOT NULL,
email VARCHAR2(100) UNIQUE,
phone VARCHAR2(20),
age NUMBER(3),
gender VARCHAR2(10),
address VARCHAR2(200)
);