0% found this document useful (0 votes)
2K views

PL-SQL Basic Programs

The document contains 12 examples of PL/SQL code blocks demonstrating various programming concepts like: 1) Displaying messages and concatenating strings 2) Performing mathematical operations and accepting user input 3) Conditional logic to determine even/odd numbers, positive/negative numbers, and letter grades 4) Finding the largest of three numbers, reversing a number, and calculating factorials 5) Using exceptions and implicit cursors to retrieve and display employee details
Copyright
© Attribution Non-Commercial (BY-NC)
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)
2K views

PL-SQL Basic Programs

The document contains 12 examples of PL/SQL code blocks demonstrating various programming concepts like: 1) Displaying messages and concatenating strings 2) Performing mathematical operations and accepting user input 3) Conditional logic to determine even/odd numbers, positive/negative numbers, and letter grades 4) Finding the largest of three numbers, reversing a number, and calculating factorials 5) Using exceptions and implicit cursors to retrieve and display employee details
Copyright
© Attribution Non-Commercial (BY-NC)
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/ 2

1) Display a Message using a simple PL/SQL begin Dbms_output.

put_line('Have a nice day'); end; 2) Display a Message with a String Variable using PL/SQL declare message varchar2(30) := 'Welcome to PL/SQL Programming'; begin dbms_output.put_line(message); end; 3) Write PL/SQL block that perform Sum of two numbers and displays it using concatenation Operator. declare a integer:=25; b integer:=32; c integer; begin c := a+b; dbms_output.put_line('a + b = ' || c); end; 4) Write a PL/SQL block that perform sum of two numbers with reading values from keyboard. declare a integer:=:a; b integer:=:b; c integer; begin c := a+b; dbms_output.put_line('a = ' || a); dbms_output.put_line('b = ' || b); dbms_output.put_line(a || ' + ' || b || ' = ' || c); end; 5) Write a PL/SQL block to find a given number is even or odd. declare num integer:=:num; begin if (mod(num,2)=0) then dbms_output.put_line( num || ' is even number.'); else dbms_output.put_line( num || ' is odd number.'); end if; end;

6) Write a PL/SQL block to read a number and print the number is zero/positive/negative. declare num integer := :num; begin if (num > 0) then dbms_output.put_line( num || ' is positive.'); elsif (num < 0) then dbms_output.put_line( num || ' is negetive.'); else dbms_output.put_line( num || ' is equal to zero.'); end if; end; 7) Write a program to print the grade with reading the marks. declare marks integer := :marks; begin if (marks >= 70) then dbms_output.put_line('You got Distinction'); elsif (marks >= 60) then dbms_output.put_line('You got First Class'); elsif (marks >= 50) then dbms_output.put_line('You got Second Class'); elsif (marks >= 35) then dbms_output.put_line('You got Third Class'); else dbms_output.put_line('You failed in the Subject'); end if; end; 8) Write a program to print the biggest of three numbers. declare a integer := :a; b integer := :b; c integer := :c; begin if ( a > b ) then if ( a > c) then dbms_output.put_line( a || ' is the biggest number '); else dbms_output.put_line( c || ' is the biggest number '); end if; else if ( b > c) then dbms_output.put_line( b || ' is the biggest number ');

else dbms_output.put_line( c || ' is the biggest number '); end if; end if; end; 9) Write a program to print the reverse of a given number. DECLARE num1 integer; num2 integer; digit integer; rev integer :=0; BEGIN dbms_output.put_line('Enter the Number: ' ); num1 := :num; num2 := num1; WHILE (num1 > 0) LOOP digit := num1 mod 10; rev := (rev*10)+digit; num1 := trunc(num1/10); END LOOP; dbms_output.put_line('The reverse of ' || num2 || ' is ' || rev); END; 10) Write a PL/SQL Block that calculates Factorial of a given number. declare num integer:=10; fact integer:=1; begin for i in 1..num loop fact:=fact*i; end loop; dbms_output.put_line('factorial of ' || num || ' is ' || fact); end; 11) Write a PL/SQL Block that calculates Factorial of a given number with Exceptional Handling. declare num integer := :num; fact integer := 1; begin for i in 1 .. num loop fact := fact*i;

end loop; dbms_output.put_line('factorial of ' || num || ' is ' || fact); exception when value_error then dbms_output.put_line('Over flow of number'); end; 12) . Display Details of an Employee given the Employee Number (using Implicit Cursor). DECLARE v_eno number (3); v_ename VARCHAR2(20); v_salary number(10); v_no number:=:Enumber; BEGIN SELECT empno,ename,salary INTO v_eno, v_ename, v_salary FROM employee WHERE empno=v_no; DBMS_OUTPUT.PUT_LINE(v_eno||' '||v_ename||' '||v_salary); Exception When no_data_found then DBMS_OUTPUT.PUT_LINE(' no employee found '); END;

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy