0% found this document useful (0 votes)
26 views

PLSQL Homework 3

Uploaded by

kiraningale48
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)
26 views

PLSQL Homework 3

Uploaded by

kiraningale48
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/ 29

PLSQL

HOMEWORK 1
17-05-2024
1 What is anonymous block in PLSQL?
ANS : An unnamed PL/SQL code block (code not stored in the database as a
procedure, function, or package) is known as an anonymous block.
It is a standalone block of code that can be executed directly in an Oracle
database without being stored in the database. These blocks are primarily used
for scripting, testing, or quick, ad-hoc tasks.

2. WHAT IS SET SERVEROUTPUT ON?


ANS : SET SERVEROUTPUT ON is a SQLPlus command used in Oracle databases to
enable the display of output from PL/SQL blocks.
When you run a PL/SQL block that contains calls to DBMS_OUTPUT.PUT_LINE (a
procedure used to print messages to the console), the output will be shown in the
SQLPlus console only if SET SERVEROUTPUT ON is enabled.

3. WHAT Is DBM_OUTPUT.PUT_LINE?
ANS : The DBMS_OUTPUT package enables you to send messages from stored
procedures, packages, and triggers.
The PUT and PUT_LINE procedures in this package enable you to place
information in a buffer that can be read by another trigger, procedure, or
package.

4. What is varible?

ANS : Variables are used to store temporary data that can be manipulated and
used within the PL/SQL block during its execution. They can store various types of
data such as numbers, characters, dates, and more.

5. what are the opertors used in PLSQL?


---1. Arithmetic Operators
---2. Comparison Operators
---3. Logical Operators
---4. String Operators
---5. Set Operators

6. Write a code to multiply the number 10,30?

>>SET SERVEROUTPUT ON;

DECLARE
v_out NUMBER(10);
BEGIN
SELECT
10 * 30
INTO v_out
FROM
dual;

dbms_output.put_line('MULTIPLICATION =' || v_out);


END;
7. Write a code to multiply the numbber 10,20,40,60 and add 10,50?

8. Write a code to multiply the numbber 10,20,40,60 and add 10,50 and
substract 5000-200?
>>DECLARE
V_OUT NUMBER (10);
V1_OUT NUMBER (10);
V2_OUT NUMBER (10);
BEGIN
SELECT 10*20*40*60 , 10+50,5000-200 INTO V_OUT ,V1_OUT,V2_OUT FROM
DUAL;
DBMS_OUTPUT.PUT_LINE ('MULTIPLICATION =' || V_OUT ||'____'|| 'ADDITION
='||V1_OUT||'____'||'SUBTRACTION ='||V2_OUT);
END;

9. Data type used in PLSQL?


---1. Scalar Data Types
---2. Composite Data Types
---3. Large Object (LOB) Data Types
---4. Reference Data Types
---5. User-Defined Data Types

10. Write a plsql block for the employee whose salary is 24000? output column
should be employee_id,first_name,last_name,salary?
11. write a plsql block for the employee whose last name is Mikkilineni?output
column should be employee_id,first_name,last_name,salary,job_id,email?

12. write a plsql block for the employee whose employee id is 131? output
column should be employee_id,first_name,last_name,salary,job_id,email?

>>DECLARE
employee_id NUMBER (10);

first_name VARCHAR2 (25);

last_name VARCHAR2 (25);

salary NUMBER (10);

job_id VARCHAR2 (10);

email VARCHAR2 (25);

BEGIN

SELECT employee_id,first_name,last_name,salary,job_id,email INTO


employee_id,first_name,last_name,salary,job_id,email FROM HR.EMPLOYEES
WHERE employee_id =131;

DBMS_OUTPUT.PUT_LINE ('employee_id ='||employee_id||'___' ||'first_name


='||first_name||'___'||'last_name ='||last_name||'____'||'salary ='||salary
||'____'||'job_id ='||job_id||'____'||'email ='||email );

END;
HOMEWORK 2
22-05-2024
1. Write a plsql block to add 10,20,40,60,90 number.
2. Write a plsql block to multiply 10,20,60,40 number.

3. Write a plsql block to fetch salary for the employee whose employee_id = 100?
4. Write a plsql block to fetch first_name,last_name,job_id for the employee
whose email id is 'LDEHAAN'?

5. Write a plsql block to fetch first_name,job_id,manager_id,department_id


whose first name is 'Lex'?
6. Write a plsql block to update salary is 5000 for the employees mail id is
'AHUNOLD'?

7. Write a plsql block to update first_name is 'Jack' and last name is 'sparrow' for
the employees whose employee id is 103.
8. Write a plsql block to update salary with 5000 whose last_name is 'Ernst' if
last_name is not matching then update 2000 for employee first_name is 'Bruce'?--
IF -THEN-ELSE
>>if last name MATCHING

>>if last name not MATCHING

9. Write plsql block


if email != 'ABHSJ' then
insert employeeid - 380, first_name - 'Ajay',last_name - 'Thakre', email -
'AJMHS',HIRE_DATE - '12-JAN-22' and job_id - 'AD_VP'
if email = 'LDEHAAN' then update salary with 2500?

10. Write a plsql block to fetch all records from employee_25 table for the
employee_id = 140?
11. Write a plsql block to fetch employee_id,first_name,last_name from
employees for first_name = Neena?

12. Write a plsql block to fetch email_id,department_id,job_id from employees


for EMAIL = LDEHAAN?
13. Write a plsql block to fetch INCENTIVE for employee_id = 100? -- salary*0.12 =
INCENTIVE

15. Write a plsql block to fetch salary,employee_id,first_name,last_name for the


employee whose last name is Kochhar?
16. What is different between %TYPE and %ROWTYPE datatype?
%TYPE Attribute
Purpose: %TYPE is used to declare a variable that takes the data type of a single
column in a table or a variable.
Usage: It is typically used when you need a variable that holds a value of a specific
column from a table or a specific variable.

%ROWTYPE Attribute

Purpose: %ROWTYPE is used to declare a record variable that can hold an entire
row of data from a table or a row fetched from a cursor.
Usage: It is useful when you need to work with an entire row of data from a table
or the result set of a query.

17. What is IS NULL in PLSQL BLOCK?


ans: In PL/SQL, the IS NULL condition is used to check whether a variable, column,
or expression contains a NULL value. It is commonly used in conditional
statements to handle scenarios where data might be missing or undefined.
ex:DECLARE
emp_salary employees.salary%TYPE;
BEGIN
SELECT salary INTO emp_salary FROM employees
WHERE employee_id = 100;
-- Check if the salary is NULL
IF emp_salary IS NULL THEN
DBMS_OUTPUT.PUT_LINE('The salary is NULL.');
ELSE
DBMS_OUTPUT.PUT_LINE('The salary is: ' || TO_CHAR(emp_salary,
'FM9999990.00'));
END IF;
END;

HOMEWORK
1. Write a plsql block to fetch salary for the employee whose employee_id is
100,101,102?
>>begin
for QR in (select employee_id,salary from emp where employee_id in
(100,101,102))
loop
DBMS_OUTPUT.PUT_LINE('SALARY OF EMPLOYEE_ID '||QR.employee_id ||' IS
'||QR.salary);
END LOOP;
END;
2. Write a plsql block to fetch first_name,last_name,job_id for the employee
whose email id is 'LDEHAAN','AHUNOLD','NGREENBE'?

3. Write a plsql block to fetch first_name,job_id,manager_id,department_id


whose first name is 'LDEHAAN','AHUNOLD','NGREENBE'?
4. Write a plsql block to update salary is 5000 for the employees mail id is
'AHUNOLD'?
>>DECLARE
v_emp_id emp.employee_id%TYPE;
BEGIN
FOR emp_rec IN (SELECT employee_id FROM emp WHERE email = 'AHUNOLD')
LOOP
UPDATE emp SET salary = 5000 WHERE employee_id =
emp_rec.employee_id;
DBMS_OUTPUT.PUT_LINE('Salary updated to 5000 for employee id: ' ||
emp_rec.employee_id);
END LOOP;
END;
5. Write a plsql block to update first_name is 'Jack' and last name is 'sparrow' for
the employees whose employee id 104,106.
>>DECLARE
v_emp_id emp.employee_id%TYPE;
BEGIN
FOR emp_rec IN (SELECT employee_id FROM emp WHERE employee_id IN
(104,106))
LOOP
UPDATE emp SET FIRST_NAME = 'Jack',LAST_NAME = 'sparrow' WHERE
employee_id IN emp_rec.employee_id;
DBMS_OUTPUT.PUT_LINE('FIRST NAME AND LAST MEN UPDATED FOR
EMPLOYEE ID: ' || emp_rec.employee_id);
END LOOP;
END;
6. Write a query to fetch all records from emp table?
7. Write a plsql block to fetch employee id, salary,first_name,email column from
employee_25?
8. Write a plsql block to fetch and delete the rows whose first_name conatain
'Douglas'.
9. write a plsql block to fetch and update salary is 5000 whose email is
'DOCONNEL', employee_id is 197,198,175?

10 write q plsql block to fetch and update first_name is 'JOE' and last name is
'TURMA' whose employee_id is 198 and first_name is Jennifer?
11. Write a plsql block to delete the records for the employees whose detail
contain only email - 'KFEENEY' and employee_id - 197?
12. Write a plsql block to to fetch salary data between 10000 and 50000?

13. Write a plsql block to to fetch salary data between 10000 and 50000?--
without using between clouse.
14. Write a plsql block to fetch salary - 17000,4800,7900,2700,3100?

15. Write a plsql block to fetch


salary - 3000,4400,650010000.78000
first_name - 'Kevin','Douglas','Hermann'
EMAIL - 'AWALSH','DGRANT'
>>select * from hr.employees
where
salary in (3000,4400,650010000.78000)
or first_name in ('Kevin','Douglas','Hermann')
or email in ('AWALSH','DGRANT');

16. Write a plsql block to fetch records from COMMISSION_PCT columns where
values having NULL.
17. Write a plsql block to fetch records from COMMISSION_PCT columns where
values having NOT NULL.

You might also like