Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --1. Write a simple PL/SQL Block to print Hello World.
- --2. Write a simple PL/SQL block to accept two numbers from user and perform all four basic mathematical operations.
- --3. Write a simple PL/SQL block to fetch the salary of employee named ‘Ravi’ from the Employee table. (Create table accordingly)
- --4. Write a simple PL/SQL block to accept the department number from user and print the count of employees in that department specified by the user. (Create table accordingly)
- --5. Write a simple PL/SQL block to get the age of a person as input and determine if the person is eligible to vote or not.
- --6. Write a simple PL/SQL block to find the greatest of three given numbers.
- --7. Write a simple PL/SQL block to get the day of the week as input from user and print the corresponding day. 1 –SUN and 7-SAT
- --8. Write a simple PL/SQL block to print the sum of first n natural numbers using for loop.
- --9. Write a simple PL/SQL block to print the sum of first n natural numbers using while loop.
- --10. Find Average of N numbers using PLSQL (Get user input)
- --1
- BEGIN
- DBMS_OUTPUT.put_line ('Hello World..');
- END;
- /
- --2
- DECLARE
- a INTEGER;
- b INTEGER;
- c INTEGER;
- f REAL;
- BEGIN
- a := &a;
- b := &b;
- c := a + b;
- DBMS_OUTPUT.put_line('Value of a+b: ' || c);
- c := a - b;
- DBMS_OUTPUT.put_line('Value of a-b: ' || c);
- c := a * b;
- DBMS_OUTPUT.put_line('Value of a*b: ' || c);
- f := a/b;
- DBMS_OUTPUT.put_line('Value of a/b: ' || f);
- END;
- /
- --3
- CREATE TABLE employee_20BRS1064(
- e_id NUMBER primary key,
- d_id NUMBER,
- name VARCHAR2(20),
- salary NUMBER
- );
- INSERT INTO employee_20BRS1064 VALUES (1001,101,'Joe Biden',200);
- INSERT INTO employee_20BRS1064 VALUES (1002,101,'Narendra Modi',300);
- INSERT INTO employee_20BRS1064 VALUES (1003,102,'Donald Trump',450);
- INSERT INTO employee_20BRS1064 VALUES (1004,102,'Putin',600);
- INSERT INTO employee_20BRS1064 VALUES (1005,102,'Ravi',900);
- INSERT INTO employee_20BRS1064 VALUES (1006,103,'Rahul Ghandhi',700);
- INSERT INTO employee_20BRS1064 VALUES (1007,103,'Hillary Clinton',650);
- INSERT INTO employee_20BRS1064 VALUES (1008,103,'Kamla Harris',950);
- INSERT INTO employee_20BRS1064 VALUES (1009,104,'Arun Jethli',550);
- INSERT INTO employee_20BRS1064 VALUES (1010,104,'Sonia Ghandhi',700);
- INSERT INTO employee_20BRS1064 VALUES (1011,105,'Kim Jong un',1000);
- INSERT INTO employee_20BRS1064 VALUES (1012,105,'Imran Khan',400);
- INSERT INTO employee_20BRS1064 VALUES (1013,105,'Jacida Ardern',400);
- SELECT * FROM employee_20BRS1064 WHERE name='&name';
- --drop table employee_20BRS1064;
- --4
- SELECT COUNT(*) FROM employee_20BRS1064 WHERE d_id=&d_id;
- --5
- DECLARE
- a INTEGER;
- BEGIN
- a := &a;
- IF a>=18 THEN DBMS_OUTPUT.put_line('YES.Eligible to vote');
- ELSE DBMS_OUTPUT.put_line('NO.Not eligible to vote');
- END IF;
- END;
- /
- --6
- DECLARE
- a INTEGER;
- b INTEGER;
- c INTEGER;
- BEGIN
- a := &a;
- b := &b;
- c := &c;
- IF a>=b THEN
- IF a>=c THEN
- DBMS_OUTPUT.put_line('Largest value is ' || a);
- ELSE
- DBMS_OUTPUT.put_line('Largest value is ' || c);
- END IF;
- ELSE
- IF b>=c THEN
- DBMS_OUTPUT.put_line('Largest value is ' || b);
- ELSE
- DBMS_OUTPUT.put_line('Largest value is ' || c);
- END IF;
- END IF;
- END;
- /
- --7
- DECLARE
- a INTEGER;
- BEGIN
- a := &a;
- CASE(a)
- WHEN 1 THEN DBMS_OUTPUT.put_line('SUNDAY');
- WHEN 2 THEN DBMS_OUTPUT.put_line('MONDAY');
- WHEN 3 THEN DBMS_OUTPUT.put_line('TUESDAY');
- WHEN 4 THEN DBMS_OUTPUT.put_line('WEDNESDAY');
- WHEN 5 THEN DBMS_OUTPUT.put_line('THURSDAY');
- WHEN 6 THEN DBMS_OUTPUT.put_line('FRIDAY');
- WHEN 7 THEN DBMS_OUTPUT.put_line('SATURNDAY');
- ELSE DBMS_OUTPUT.put_line('Enter Valid day');
- END CASE;
- END;
- /
- --8
- DECLARE
- a INTEGER;
- b INTEGER;
- c INTEGER := 0;
- BEGIN
- b := &b;
- FOR a IN 1..b
- LOOP
- c := c+a;
- END LOOP;
- DBMS_OUTPUT.put_line('Sum of first '||b||' numbers is '|| c);
- END;
- /
- --9
- DECLARE
- a INTEGER := 1;
- b INTEGER;
- c INTEGER := 0;
- BEGIN
- b := &b;
- WHILE(a<=b)
- LOOP
- c := c+a;
- a := a+1;
- END LOOP;
- DBMS_OUTPUT.put_line('Sum of first '||b||' numbers is '|| c);
- END;
- /
- --10
- DECLARE
- a INTEGER := 1;
- b INTEGER;
- c REAL := 0;
- BEGIN
- b := &b;
- WHILE(a<=b)
- LOOP
- c := c+a;
- a := a+1;
- END LOOP;
- c := c/b;
- DBMS_OUTPUT.put_line('Average of first '||b||' numbers is '|| c);
- END;
- /
Add Comment
Please, Sign In to add comment