0% found this document useful (0 votes)
6 views6 pages

DBMS Lab Test

The document contains examples of PL/SQL code to print patterns like Floyd's triangle and Fibonacci series, find prime numbers in a range, create tables and insert data, and write SQL queries to join tables and filter results.
Copyright
© © All Rights Reserved
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)
6 views6 pages

DBMS Lab Test

The document contains examples of PL/SQL code to print patterns like Floyd's triangle and Fibonacci series, find prime numbers in a range, create tables and insert data, and write SQL queries to join tables and filter results.
Copyright
© © All Rights Reserved
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/ 6

LAB TEST DE

Q/NO-1 Print Floyd's triangle

DECLARE

n NUMBER := 10;

counter NUMBER := 1;

BEGIN

FOR i IN 1..n LOOP

FOR j IN 1..i LOOP

DBMS_OUTPUT.PUT(counter || ' ');

counter := counter + 1;

END LOOP;

DBMS_OUTPUT.PUT_LINE('');

END LOOP;

END;

/
Q.NO-2 print Fibonacci series

DECLARE

a NUMBER := 0;

b NUMBER := 1;

temp NUMBER;

n NUMBER := 20;

BEGIN

DBMS_OUTPUT.PUT_LINE('Fibonacci Series:');

DBMS_OUTPUT.PUT_LINE(a);

DBMS_OUTPUT.PUT_LINE(b);

FOR i IN 3..n LOOP

temp := a + b;

DBMS_OUTPUT.PUT_LINE(temp);

a := b;

b := temp;

END LOOP;

END;
/

Q.NO- 3 print prime series within a range.


DECLARE

start_range NUMBER := 1;

end_range NUMBER := 100;

is_prime BOOLEAN;

BEGIN

DBMS_OUTPUT.PUT_LINE('Prime Numbers:');

FOR i IN start_range..end_range LOOP

is_prime := TRUE;

IF i <= 1 THEN

is_prime := FALSE;

ELSE

FOR j IN 2..TRUNC(SQRT(i)) LOOP

IF MOD(i, j) = 0 THEN

is_prime := FALSE;

EXIT;

END IF;

END LOOP;

END IF;

IF is_prime THEN

DBMS_OUTPUT.PUT_LINE(i);

END IF;

END LOOP;

END;

/
Q/N0 4 –

Create table Salesman_653

salesman_id number(5),

Name varchar(20),

City varchar(20),

Commission number(5,2)

);

DESC SALESMAN_653;

INSERT ALL

INTO SALESMAN_653 VALUES(5001,'JAMES HOOG','NEW YORK',0.15)

INTO SALESMAN_653 VALUES(5002,'NAIL KNITE','PARIS',0.13)

INTO SALESMAN_653 VALUES(5005,'PIT ALEX','LONDON',0.11)

INTO SALESMAN_653 VALUES(5006,'MC LYON','PARIS',0.14)

INTO SALESMAN_653 VALUES(5007,'PAUL ADAM','ROME',0.13)

INTO SALESMAN_653 VALUES(5003,'LAUSON HEN','SAN JOSE',0.12)

SELECT * FROM DUAL;

SELECT * FROM SALESMAN_653;


Create table CUSTOMER_653

CUSTOMER_ID number(5),

CUST_NAME varchar(20),

CITY varchar(20),

GRADE number(5),

SALESMAN_ID NUMBER(5)

);

DESC CUSTOMER_653;

INSERT ALL

INTO CUSTOMER_653 VALUES(3002,'NICK RIMANDO','NEW YORK',100,5001)

INTO CUSTOMER_653 VALUES(3007,'BRAD DAVIS','NEW YORK',200,5001)

INTO CUSTOMER_653 VALUES(3005,'GRAHM ZUSI','CALIFORNIA',200,5002)

INTO CUSTOMER_653 VALUES(3008,'JULIAN GREEN','LONDON',300,5002)

INTO CUSTOMER_653 VALUES(3004,'FABIAN JOHNSON','PARIS',300,5006)

SELECT * FROM DUAL;

SELECT * FROM CUSTOMER_653;


Q.NO- 4A From the following tables write a SQL query to find
the salesperson and customer who reside in the same city.
Return Salesman, cust_name and city.
SELECT Salesman_653.name , Customer_653.Cust_name, Customer_653.City FROM Customer_653

JOIN Salesman_653 ON Customer_653.Salesman_id = Salesman_653.Salesman_id

WHERE Customer_653.City = Salesman_653.City;

Q/NO -4B From the following tables write a SQL query to find
salespeople who received commissions of more than 12
percent from the company. Return Customer Name, customer
city, Salesman, commission
SELECT Customer_653.Cust_name, Customer_653.City , Salesman_653.Name , Salesman_653.Commision
FROM Customer_653

JOIN Salesman_653 ON Customer_653.Salesman_id = Salesman_653.Salesman_id WHERE


Salesman_653.Commision > 0.12;

SUMMITTED BY-

Aditya Raj

2201020652

4TH SEMESTER

GROUP 3

You might also like