SlideShare uma empresa Scribd logo
1 de 5
PLSQL:

1)
Write a PL/SQL block to accept a year input and check whether it is a leap year.

2)
Write a PL/SQL block which will accept the employee number and print the annual_salary as well as the bonus.
 The PL/SQL block should:
• Calculate the annual salary as salary * 12
• Calculate the bonus as indicated in the following table:
 Annual Salary        Bonus
>= 20,000            2000
19,999–10,000        1000
<= 9,999             500


3)
Declare a cursor named EMP_CUR to select the employee’s last name, salary, and hire
date from the EMPLOYEES table
Process each row from the cursor, and if the salary is greater than 15,000 and the hire
date is later than 01-FEB-1988, display the employee name, salary, and hire date in
the format shown in the following sample output:




4)
Create a PL/SQL block to retrieve and output the last name and department ID of each employee from the
EMPLOYEES table for those employees whose EMPLOYEE_ID is less than 115.
In the PL/SQL block, use a cursor FOR loop strategy instead of the OPEN / FETCH /CLOSE cursor methods
used in the previous practice.
1. In the declarative section:
• Create two associative arrays. The unique key column for both arrays should be of the BINARY INTEGER
data type. One array holds the employee’s last name and the other holds the department ID.
• Declare a counter variable to be used in the executable section
• Declare a cursor that selects the last name and department ID for employees whose ID is less than 115



5)
Create a table:
CREATE TABLE analysis
(ename Varchar2(20), years Number(2), sal Number(8,2)
);
Write a PL/SQL block that handles an exception, as follows:
1. Declare variables for the employee last name, salary, and hire date. Use a substitution
variable for the employee last name. Then, query the employees table for the
last_name, salary, and hire_date of the specified employee.
2. If the employee has been with the organization for more than five years, and if that
employee’s salary is less than 3,500, raise an exception. In the exception handler,
perform the following:
• Output the following information: employee last name and the message “due
for a raise,” similar to the following:




Insert the last name, years of service, and salary into the analysis table.

3. If there is no exception, output the employee last name and the message “not due for a raise,” similar to the
following:




Verify the results by querying the analysis table. Use the following test cases to test the PL/SQL block.
LAST_NAME MESSAGE
Austin            Not due for a raise
Nayer             Due for a raise
Fripp             Not due for a raise
Khoo              Due for a raise

6)
Create, compile, and invoke the ADD_JOB procedure and review the results.
a) Create a procedure called ADD_JOB to insert a new job into the JOBS table.
Provide the ID and job title using two parameters.
Note: You can create the procedure (and other objects) by entering the code in the
SQL Worksheet area, and then click the Run Script (F5) icon. This creates and
compiles the procedure. To find out whether or not the procedure has any errors,
click the procedure name in the procedure node, and then select Compile from the
pop-up menu.
b) Invoke the procedure with IT_DBA as the job ID and Database
Administrator as the job title. Query the JOBS table and view the results.
c) Invoke your procedure again, passing a job ID of ST_MAN and a job title of
Stock Manager. What happens and why?
7)
7a. Create a procedure called UPD_JOB to update the job title. Provide the job ID and
a new title using two parameters. Include the necessary exception handling if no
update occurs.

7b) Invoke the procedure to change the job title of the job ID IT_DBA to Data Administrator. Query the JOBS
table and view the results.

7c) Test the exception-handling section of the procedure by trying to update a job that does not exist. You can
use the job ID IT_WEB and the job title Web Master.


8) Create a procedure called GET_EMPLOYEE to query the EMPLOYEES table, retrieving the salary and job
ID for an employee when provided with the employee ID.
a) Create a procedure that returns a value from the SALARY and JOB_ID columns for a specified employee ID.
Remove syntax errors, if any, and then recompile the code.

9)
Create and invoke the GET_JOB function to return a job title.
9a) Create and compile a function called GET_JOB to return a job title.
b) Create a VARCHAR2 host variable called b_title, allowing a length of 35
characters. Invoke the function with job ID SA_REP to return the value in the
host variable, and then print the host variable to view the result.

9b)Create a VARCHAR2 host variable called b_title, allowing a length of 35
characters. Invoke the function with job ID SA_REP to return the value in the
host variable, and then print the host variable to view the result.

10) Create a function called GET_ANNUAL_COMP to return the annual salary computed
from an employee’s monthly salary and commission passed as parameters.
10 a) Create the GET_ANNUAL_COMP function, which accepts parameter values for the
monthly salary and commission. Either or both values passed can be NULL, but
the function should still return a non-NULL annual salary. Use the following basic
formula to calculate the annual salary:
(salary*12) + (commission_pct*salary*12)

10b) Use the function in a SELECT statement against the EMPLOYEES table for
employees in department 30.

11)
Create a procedure, ADD_EMPLOYEE, to insert a new employee into the
EMPLOYEES table. The procedure should call a VALID_DEPTID function to check
whether the department ID specified for the new employee exists in the
DEPARTMENTS table.
11a) Create a function called VALID_DEPTID to validate a specified department ID
and return a BOOLEAN value of TRUE if the department exists.
11b) Create the ADD_EMPLOYEE procedure to add an employee to the EMPLOYEES
table. The row should be added to the EMPLOYEES table if the VALID_DEPTID
function returns TRUE; otherwise, alert the user with an appropriate message.
Provide the following parameters:
- first_name
- last_name
- email
- job: Use 'SA_REP' as the default.
- mgr: Use 145 as the default.
- sal: Use 1000 as the default.
- comm: Use 0 as the default.
- deptid: Use 30 as the default.
- Use the EMPLOYEES_SEQ sequence to set the employee_id column.
     − Set the hire_date column to TRUNC(SYSDATE).
11c) Call ADD_EMPLOYEE for the name 'Jane Harris' in department 15,
leaving other parameters with their default values. What is the result?

11d) Add another employee named Joe Harris in department 80, leaving the remaining
parameters with their default values. What is the result?


12)
1) Create a package specification and body called JOB_PKG, containing a copy of your
ADD_JOB, UPD_JOB, and DEL_JOB procedures as well as your GET_JOB function.
Note: Use the code from your previously saved procedures and functions when
creating the package. You can copy the code in a procedure or function, and then
paste the code into the appropriate section of the package.
a) Create the package specification including the procedures and function headings
as public constructs.

b) Create the package body with the implementations for each of the subprograms.
c) Invoke your ADD_JOB package procedure by passing the values IT_SYSAN and
SYSTEMS ANALYST as parameters.

13)
Create and invoke a package that contains private and public constructs.
a) Create a package specification and a package body called EMP_PKG that contains
the following procedures and function that you created earlier:
i) ADD_EMPLOYEE procedure as a public construct
ii) GET_EMPLOYEE procedure as a public construct
iii) VALID_DEPTID function as a private construct
b) Invoke the EMP_PKG.ADD_EMPLOYEE procedure, using department ID 15 for
employee Jane Harris with the email ID JAHARRIS. Because department ID 15
does not exist, you should get an error message as specified in the exception
handler of your procedure.
c) Invoke the ADD_EMPLOYEE package procedure by using department ID 80 for
employee David Smith with the email ID DASMITH.

14)
Modify the code for the EMP_PKG package that you created earlier,
and then overload the ADD_EMPLOYEE procedure. Next, you create two overloaded
functions called GET_EMPLOYEE in the EMP_PKG package. You also add a public
procedure to EMP_PKG to populate a private PL/SQL table of valid department IDs and
modify the VALID_DEPTID function to use the private PL/SQL table contents to
validate department ID values. You also change the VALID_DEPTID validation
processing function to use the private PL/SQL table of department IDs. Finally, you
reorganize the subprograms in the package specification and the body so that they are in
alphabetical sequence.
Modify the code for the EMP_PKG package that you created earlier, and
overload the ADD_EMPLOYEE procedure.
a) In the package specification, add a new procedure called ADD_EMPLOYEE that
accepts the following three parameters:
i) First name
ii) Last name
     iii) Department ID

b) Implement the new ADD_EMPLOYEE procedure in the package body as follows:
i) Format the email address in uppercase characters, using the first letter of the
first name concatenated with the first seven letters of the last name.
ii) The procedure should call the existing ADD_EMPLOYEE procedure to perform
the actual INSERT operation using its parameters and formatted email to
supply the values.
     iii) Click Run Script to create the package. Compile the package.

c) Invoke the new ADD_EMPLOYEE procedure using the name Samuel Joplin
to be added to department 30.

15)
In the EMP_PKG package, create two overloaded functions called GET_EMPLOYEE:
a) In the package specification, add the following functions:
i) The GET_EMPLOYEE function that accepts the parameter called p_emp_id
based on the employees.employee_id%TYPE type. This function
should return EMPLOYEES%ROWTYPE.
ii) The GET_EMPLOYEE function that accepts the parameter called
p_family_name of type employees.last_name%TYPE. This function
should return EMPLOYEES%ROWTYPE.

Mais conteúdo relacionado

Mais procurados

SQL-RDBMS Queries and Question Bank
SQL-RDBMS Queries and Question BankSQL-RDBMS Queries and Question Bank
SQL-RDBMS Queries and Question BankMd Mudassir
 
SQL practice questions set
SQL practice questions setSQL practice questions set
SQL practice questions setMohd Tousif
 
Bi email-alert-notification - Fusion Alert
Bi email-alert-notification - Fusion AlertBi email-alert-notification - Fusion Alert
Bi email-alert-notification - Fusion AlertFeras Ahmad
 
Top 40 sql queries for testers
Top 40 sql queries for testersTop 40 sql queries for testers
Top 40 sql queries for testerstlvd
 
Sql queries questions and answers
Sql queries questions and answersSql queries questions and answers
Sql queries questions and answersMichael Belete
 
Complex queries in sql
Complex queries in sqlComplex queries in sql
Complex queries in sqlCharan Reddy
 
DBMS 5 | MySQL Practice List - HR Schema
DBMS 5 | MySQL Practice List - HR SchemaDBMS 5 | MySQL Practice List - HR Schema
DBMS 5 | MySQL Practice List - HR SchemaMohammad Imam Hossain
 
SQL Stored Procedures For My Library Project
SQL Stored Procedures For My Library ProjectSQL Stored Procedures For My Library Project
SQL Stored Procedures For My Library ProjectRick Massouh
 
Fast formula queries for functions, contexts, db is and packages
Fast formula queries for functions, contexts, db is and packagesFast formula queries for functions, contexts, db is and packages
Fast formula queries for functions, contexts, db is and packagesFeras Ahmad
 
Aggregating Data Using Group Functions
Aggregating Data Using Group FunctionsAggregating Data Using Group Functions
Aggregating Data Using Group FunctionsSalman Memon
 
DBMS 6 | MySQL Practice List - Rank Related Queries
DBMS 6 | MySQL Practice List - Rank Related QueriesDBMS 6 | MySQL Practice List - Rank Related Queries
DBMS 6 | MySQL Practice List - Rank Related QueriesMohammad Imam Hossain
 
Creating Views - oracle database
Creating Views - oracle databaseCreating Views - oracle database
Creating Views - oracle databaseSalman Memon
 
All payroll elements with eligibility Oracle Fusion Cloud
All payroll elements with eligibility Oracle Fusion CloudAll payroll elements with eligibility Oracle Fusion Cloud
All payroll elements with eligibility Oracle Fusion CloudFeras Ahmad
 
142500146 using-oracle-fast formula-for-payroll-calculations
142500146 using-oracle-fast formula-for-payroll-calculations142500146 using-oracle-fast formula-for-payroll-calculations
142500146 using-oracle-fast formula-for-payroll-calculationsuday reddy
 

Mais procurados (20)

SQL-RDBMS Queries and Question Bank
SQL-RDBMS Queries and Question BankSQL-RDBMS Queries and Question Bank
SQL-RDBMS Queries and Question Bank
 
Dump Answers
Dump AnswersDump Answers
Dump Answers
 
Sql task
Sql taskSql task
Sql task
 
SQL practice questions set
SQL practice questions setSQL practice questions set
SQL practice questions set
 
Bi email-alert-notification - Fusion Alert
Bi email-alert-notification - Fusion AlertBi email-alert-notification - Fusion Alert
Bi email-alert-notification - Fusion Alert
 
Top 40 sql queries for testers
Top 40 sql queries for testersTop 40 sql queries for testers
Top 40 sql queries for testers
 
Sql queries questions and answers
Sql queries questions and answersSql queries questions and answers
Sql queries questions and answers
 
1 z0 047
1 z0 0471 z0 047
1 z0 047
 
Best sql plsql material
Best sql plsql materialBest sql plsql material
Best sql plsql material
 
Complex queries in sql
Complex queries in sqlComplex queries in sql
Complex queries in sql
 
DBMS 5 | MySQL Practice List - HR Schema
DBMS 5 | MySQL Practice List - HR SchemaDBMS 5 | MySQL Practice List - HR Schema
DBMS 5 | MySQL Practice List - HR Schema
 
Sql query [select, sub] 4
Sql query [select, sub] 4Sql query [select, sub] 4
Sql query [select, sub] 4
 
SQL Stored Procedures For My Library Project
SQL Stored Procedures For My Library ProjectSQL Stored Procedures For My Library Project
SQL Stored Procedures For My Library Project
 
Fast formula queries for functions, contexts, db is and packages
Fast formula queries for functions, contexts, db is and packagesFast formula queries for functions, contexts, db is and packages
Fast formula queries for functions, contexts, db is and packages
 
Aggregating Data Using Group Functions
Aggregating Data Using Group FunctionsAggregating Data Using Group Functions
Aggregating Data Using Group Functions
 
DBMS 6 | MySQL Practice List - Rank Related Queries
DBMS 6 | MySQL Practice List - Rank Related QueriesDBMS 6 | MySQL Practice List - Rank Related Queries
DBMS 6 | MySQL Practice List - Rank Related Queries
 
Creating Views - oracle database
Creating Views - oracle databaseCreating Views - oracle database
Creating Views - oracle database
 
All payroll elements with eligibility Oracle Fusion Cloud
All payroll elements with eligibility Oracle Fusion CloudAll payroll elements with eligibility Oracle Fusion Cloud
All payroll elements with eligibility Oracle Fusion Cloud
 
Q on subquery
Q on subqueryQ on subquery
Q on subquery
 
142500146 using-oracle-fast formula-for-payroll-calculations
142500146 using-oracle-fast formula-for-payroll-calculations142500146 using-oracle-fast formula-for-payroll-calculations
142500146 using-oracle-fast formula-for-payroll-calculations
 

Destaque

Sql queries with answers
Sql queries with answersSql queries with answers
Sql queries with answersvijaybusu
 
Mc amca04919 plsql programs
Mc amca04919 plsql programsMc amca04919 plsql programs
Mc amca04919 plsql programsAshwin Kumar
 
Sql task answers
Sql task answersSql task answers
Sql task answersNawaz Sk
 
3963066 pl-sql-notes-only
3963066 pl-sql-notes-only3963066 pl-sql-notes-only
3963066 pl-sql-notes-onlyAshwin Kumar
 
Oracle database 12c sql worshop 1 activity guide
Oracle database 12c sql worshop 1 activity guideOracle database 12c sql worshop 1 activity guide
Oracle database 12c sql worshop 1 activity guideOtto Paiz
 
Oracle database 12c sql worshop 2 activity guide
Oracle database 12c sql worshop 2 activity guideOracle database 12c sql worshop 2 activity guide
Oracle database 12c sql worshop 2 activity guideOtto Paiz
 
48742447 11g-sql-fundamentals-ii-additional-practices-and-solutions
48742447 11g-sql-fundamentals-ii-additional-practices-and-solutions48742447 11g-sql-fundamentals-ii-additional-practices-and-solutions
48742447 11g-sql-fundamentals-ii-additional-practices-and-solutionsAshwin Kumar
 
Oracle database 12c sql worshop 2 student guide vol 1
Oracle database 12c sql worshop 2 student guide vol 1Oracle database 12c sql worshop 2 student guide vol 1
Oracle database 12c sql worshop 2 student guide vol 1Otto Paiz
 
Oracle database 12c sql worshop 1 student guide vol 2
Oracle database 12c sql worshop 1 student guide vol 2Oracle database 12c sql worshop 1 student guide vol 2
Oracle database 12c sql worshop 1 student guide vol 2Otto Paiz
 
Oracle database 12c sql worshop 2 student guide vol 2
Oracle database 12c sql worshop 2 student guide vol 2Oracle database 12c sql worshop 2 student guide vol 2
Oracle database 12c sql worshop 2 student guide vol 2Otto Paiz
 
Oracle order management implementation manual
Oracle order management implementation manualOracle order management implementation manual
Oracle order management implementation manualNawaz Sk
 
Sql queries interview questions
Sql queries interview questionsSql queries interview questions
Sql queries interview questionsPyadav010186
 
A must Sql notes for beginners
A must Sql notes for beginnersA must Sql notes for beginners
A must Sql notes for beginnersRam Sagar Mourya
 

Destaque (16)

Pl lab solution
Pl lab solutionPl lab solution
Pl lab solution
 
Sql queries with answers
Sql queries with answersSql queries with answers
Sql queries with answers
 
Tables
TablesTables
Tables
 
Mc amca04919 plsql programs
Mc amca04919 plsql programsMc amca04919 plsql programs
Mc amca04919 plsql programs
 
Sql task answers
Sql task answersSql task answers
Sql task answers
 
3963066 pl-sql-notes-only
3963066 pl-sql-notes-only3963066 pl-sql-notes-only
3963066 pl-sql-notes-only
 
Oracle database 12c sql worshop 1 activity guide
Oracle database 12c sql worshop 1 activity guideOracle database 12c sql worshop 1 activity guide
Oracle database 12c sql worshop 1 activity guide
 
Oracle database 12c sql worshop 2 activity guide
Oracle database 12c sql worshop 2 activity guideOracle database 12c sql worshop 2 activity guide
Oracle database 12c sql worshop 2 activity guide
 
48742447 11g-sql-fundamentals-ii-additional-practices-and-solutions
48742447 11g-sql-fundamentals-ii-additional-practices-and-solutions48742447 11g-sql-fundamentals-ii-additional-practices-and-solutions
48742447 11g-sql-fundamentals-ii-additional-practices-and-solutions
 
Oracle database 12c sql worshop 2 student guide vol 1
Oracle database 12c sql worshop 2 student guide vol 1Oracle database 12c sql worshop 2 student guide vol 1
Oracle database 12c sql worshop 2 student guide vol 1
 
Oracle database 12c sql worshop 1 student guide vol 2
Oracle database 12c sql worshop 1 student guide vol 2Oracle database 12c sql worshop 1 student guide vol 2
Oracle database 12c sql worshop 1 student guide vol 2
 
Oracle database 12c sql worshop 2 student guide vol 2
Oracle database 12c sql worshop 2 student guide vol 2Oracle database 12c sql worshop 2 student guide vol 2
Oracle database 12c sql worshop 2 student guide vol 2
 
Oracle order management implementation manual
Oracle order management implementation manualOracle order management implementation manual
Oracle order management implementation manual
 
Dbms lab questions
Dbms lab questionsDbms lab questions
Dbms lab questions
 
Sql queries interview questions
Sql queries interview questionsSql queries interview questions
Sql queries interview questions
 
A must Sql notes for beginners
A must Sql notes for beginnersA must Sql notes for beginners
A must Sql notes for beginners
 

Semelhante a Plsql task

Practice create procedure
Practice   create procedurePractice   create procedure
Practice create procedurecit gubbi
 
33.docxSTEP 1 Understand the UML Diagram Analyze and under.docx
33.docxSTEP 1 Understand the UML Diagram Analyze and under.docx33.docxSTEP 1 Understand the UML Diagram Analyze and under.docx
33.docxSTEP 1 Understand the UML Diagram Analyze and under.docxgilbertkpeters11344
 
Please be advised that there are four (4) programs just like this on.docx
Please be advised that there are four (4) programs just like this on.docxPlease be advised that there are four (4) programs just like this on.docx
Please be advised that there are four (4) programs just like this on.docxlorindajamieson
 
MSCD650 Final Exam feedback FormMSCD650 Final Exam Grading For.docx
MSCD650 Final Exam feedback FormMSCD650 Final Exam Grading For.docxMSCD650 Final Exam feedback FormMSCD650 Final Exam Grading For.docx
MSCD650 Final Exam feedback FormMSCD650 Final Exam Grading For.docxgilpinleeanna
 
Oracle - Program with PL/SQL - Lession 09
Oracle - Program with PL/SQL - Lession 09Oracle - Program with PL/SQL - Lession 09
Oracle - Program with PL/SQL - Lession 09Thuan Nguyen
 
Aggregate Functions,Final
Aggregate Functions,FinalAggregate Functions,Final
Aggregate Functions,Finalmukesh24pandey
 
CIS 247C iLab 4 of 7: Composition and Class Interfaces
CIS 247C iLab 4 of 7: Composition and Class Interfaces  CIS 247C iLab 4 of 7: Composition and Class Interfaces
CIS 247C iLab 4 of 7: Composition and Class Interfaces HomeWork-Fox
 
Oracle OCP 1Z0-007题库
Oracle OCP 1Z0-007题库Oracle OCP 1Z0-007题库
Oracle OCP 1Z0-007题库renguzi
 
Rdbms class test ii sep 2019
Rdbms class test  ii sep 2019Rdbms class test  ii sep 2019
Rdbms class test ii sep 2019ARVIND SARDAR
 
in C++ Design a class named Employee The class should keep .pdf
in C++ Design a class named Employee The class should keep .pdfin C++ Design a class named Employee The class should keep .pdf
in C++ Design a class named Employee The class should keep .pdfadithyaups
 
Divyansh Mehta,BCA Final Year 2015 ,Dezyne E'cole College
Divyansh Mehta,BCA Final Year 2015 ,Dezyne E'cole CollegeDivyansh Mehta,BCA Final Year 2015 ,Dezyne E'cole College
Divyansh Mehta,BCA Final Year 2015 ,Dezyne E'cole Collegedezyneecole
 
Use of Classes and functions#include iostreamusing name.docx
 Use of Classes and functions#include iostreamusing name.docx Use of Classes and functions#include iostreamusing name.docx
Use of Classes and functions#include iostreamusing name.docxaryan532920
 
Cis 407 i lab 5 of 7
Cis 407 i lab 5 of 7Cis 407 i lab 5 of 7
Cis 407 i lab 5 of 7helpido9
 
How to add new Object Link in SAP DMS
How to add new Object Link in SAP DMSHow to add new Object Link in SAP DMS
How to add new Object Link in SAP DMSAssaf Sheinrok
 
Salesforce, APEX Concepts
Salesforce, APEX ConceptsSalesforce, APEX Concepts
Salesforce, APEX ConceptsGaurish Goel
 

Semelhante a Plsql task (20)

Practice create procedure
Practice   create procedurePractice   create procedure
Practice create procedure
 
33.docxSTEP 1 Understand the UML Diagram Analyze and under.docx
33.docxSTEP 1 Understand the UML Diagram Analyze and under.docx33.docxSTEP 1 Understand the UML Diagram Analyze and under.docx
33.docxSTEP 1 Understand the UML Diagram Analyze and under.docx
 
Please be advised that there are four (4) programs just like this on.docx
Please be advised that there are four (4) programs just like this on.docxPlease be advised that there are four (4) programs just like this on.docx
Please be advised that there are four (4) programs just like this on.docx
 
MSCD650 Final Exam feedback FormMSCD650 Final Exam Grading For.docx
MSCD650 Final Exam feedback FormMSCD650 Final Exam Grading For.docxMSCD650 Final Exam feedback FormMSCD650 Final Exam Grading For.docx
MSCD650 Final Exam feedback FormMSCD650 Final Exam Grading For.docx
 
Oracle - Program with PL/SQL - Lession 09
Oracle - Program with PL/SQL - Lession 09Oracle - Program with PL/SQL - Lession 09
Oracle - Program with PL/SQL - Lession 09
 
Aggregate Functions,Final
Aggregate Functions,FinalAggregate Functions,Final
Aggregate Functions,Final
 
Unit 2 web technologies
Unit 2 web technologiesUnit 2 web technologies
Unit 2 web technologies
 
CIS 247C iLab 4 of 7: Composition and Class Interfaces
CIS 247C iLab 4 of 7: Composition and Class Interfaces  CIS 247C iLab 4 of 7: Composition and Class Interfaces
CIS 247C iLab 4 of 7: Composition and Class Interfaces
 
Oracle OCP 1Z0-007题库
Oracle OCP 1Z0-007题库Oracle OCP 1Z0-007题库
Oracle OCP 1Z0-007题库
 
Rdbms class test ii sep 2019
Rdbms class test  ii sep 2019Rdbms class test  ii sep 2019
Rdbms class test ii sep 2019
 
in C++ Design a class named Employee The class should keep .pdf
in C++ Design a class named Employee The class should keep .pdfin C++ Design a class named Employee The class should keep .pdf
in C++ Design a class named Employee The class should keep .pdf
 
PL/SQL TRIGGERS
PL/SQL TRIGGERSPL/SQL TRIGGERS
PL/SQL TRIGGERS
 
Divyansh Mehta,BCA Final Year 2015 ,Dezyne E'cole College
Divyansh Mehta,BCA Final Year 2015 ,Dezyne E'cole CollegeDivyansh Mehta,BCA Final Year 2015 ,Dezyne E'cole College
Divyansh Mehta,BCA Final Year 2015 ,Dezyne E'cole College
 
Use of Classes and functions#include iostreamusing name.docx
 Use of Classes and functions#include iostreamusing name.docx Use of Classes and functions#include iostreamusing name.docx
Use of Classes and functions#include iostreamusing name.docx
 
Lab 07
Lab 07Lab 07
Lab 07
 
Cis 407 i lab 5 of 7
Cis 407 i lab 5 of 7Cis 407 i lab 5 of 7
Cis 407 i lab 5 of 7
 
DOODB_LAB.pptx
DOODB_LAB.pptxDOODB_LAB.pptx
DOODB_LAB.pptx
 
How to add new Object Link in SAP DMS
How to add new Object Link in SAP DMSHow to add new Object Link in SAP DMS
How to add new Object Link in SAP DMS
 
Lab guide10
Lab guide10Lab guide10
Lab guide10
 
Salesforce, APEX Concepts
Salesforce, APEX ConceptsSalesforce, APEX Concepts
Salesforce, APEX Concepts
 

Último

Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
Q4 English4 Week3 PPT Melcnmg-based.pptx
Q4 English4 Week3 PPT Melcnmg-based.pptxQ4 English4 Week3 PPT Melcnmg-based.pptx
Q4 English4 Week3 PPT Melcnmg-based.pptxnelietumpap1
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfphamnguyenenglishnb
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)lakshayb543
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSJoshuaGantuangco2
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfTechSoup
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomnelietumpap1
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4MiaBumagat1
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxDr.Ibrahim Hassaan
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 

Último (20)

Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
Q4 English4 Week3 PPT Melcnmg-based.pptx
Q4 English4 Week3 PPT Melcnmg-based.pptxQ4 English4 Week3 PPT Melcnmg-based.pptx
Q4 English4 Week3 PPT Melcnmg-based.pptx
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choom
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptxYOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptx
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 

Plsql task

  • 1. PLSQL: 1) Write a PL/SQL block to accept a year input and check whether it is a leap year. 2) Write a PL/SQL block which will accept the employee number and print the annual_salary as well as the bonus. The PL/SQL block should: • Calculate the annual salary as salary * 12 • Calculate the bonus as indicated in the following table: Annual Salary Bonus >= 20,000 2000 19,999–10,000 1000 <= 9,999 500 3) Declare a cursor named EMP_CUR to select the employee’s last name, salary, and hire date from the EMPLOYEES table Process each row from the cursor, and if the salary is greater than 15,000 and the hire date is later than 01-FEB-1988, display the employee name, salary, and hire date in the format shown in the following sample output: 4) Create a PL/SQL block to retrieve and output the last name and department ID of each employee from the EMPLOYEES table for those employees whose EMPLOYEE_ID is less than 115. In the PL/SQL block, use a cursor FOR loop strategy instead of the OPEN / FETCH /CLOSE cursor methods used in the previous practice. 1. In the declarative section: • Create two associative arrays. The unique key column for both arrays should be of the BINARY INTEGER data type. One array holds the employee’s last name and the other holds the department ID. • Declare a counter variable to be used in the executable section • Declare a cursor that selects the last name and department ID for employees whose ID is less than 115 5) Create a table: CREATE TABLE analysis (ename Varchar2(20), years Number(2), sal Number(8,2) );
  • 2. Write a PL/SQL block that handles an exception, as follows: 1. Declare variables for the employee last name, salary, and hire date. Use a substitution variable for the employee last name. Then, query the employees table for the last_name, salary, and hire_date of the specified employee. 2. If the employee has been with the organization for more than five years, and if that employee’s salary is less than 3,500, raise an exception. In the exception handler, perform the following: • Output the following information: employee last name and the message “due for a raise,” similar to the following: Insert the last name, years of service, and salary into the analysis table. 3. If there is no exception, output the employee last name and the message “not due for a raise,” similar to the following: Verify the results by querying the analysis table. Use the following test cases to test the PL/SQL block. LAST_NAME MESSAGE Austin Not due for a raise Nayer Due for a raise Fripp Not due for a raise Khoo Due for a raise 6) Create, compile, and invoke the ADD_JOB procedure and review the results. a) Create a procedure called ADD_JOB to insert a new job into the JOBS table. Provide the ID and job title using two parameters. Note: You can create the procedure (and other objects) by entering the code in the SQL Worksheet area, and then click the Run Script (F5) icon. This creates and compiles the procedure. To find out whether or not the procedure has any errors, click the procedure name in the procedure node, and then select Compile from the pop-up menu. b) Invoke the procedure with IT_DBA as the job ID and Database Administrator as the job title. Query the JOBS table and view the results. c) Invoke your procedure again, passing a job ID of ST_MAN and a job title of Stock Manager. What happens and why?
  • 3. 7) 7a. Create a procedure called UPD_JOB to update the job title. Provide the job ID and a new title using two parameters. Include the necessary exception handling if no update occurs. 7b) Invoke the procedure to change the job title of the job ID IT_DBA to Data Administrator. Query the JOBS table and view the results. 7c) Test the exception-handling section of the procedure by trying to update a job that does not exist. You can use the job ID IT_WEB and the job title Web Master. 8) Create a procedure called GET_EMPLOYEE to query the EMPLOYEES table, retrieving the salary and job ID for an employee when provided with the employee ID. a) Create a procedure that returns a value from the SALARY and JOB_ID columns for a specified employee ID. Remove syntax errors, if any, and then recompile the code. 9) Create and invoke the GET_JOB function to return a job title. 9a) Create and compile a function called GET_JOB to return a job title. b) Create a VARCHAR2 host variable called b_title, allowing a length of 35 characters. Invoke the function with job ID SA_REP to return the value in the host variable, and then print the host variable to view the result. 9b)Create a VARCHAR2 host variable called b_title, allowing a length of 35 characters. Invoke the function with job ID SA_REP to return the value in the host variable, and then print the host variable to view the result. 10) Create a function called GET_ANNUAL_COMP to return the annual salary computed from an employee’s monthly salary and commission passed as parameters. 10 a) Create the GET_ANNUAL_COMP function, which accepts parameter values for the monthly salary and commission. Either or both values passed can be NULL, but the function should still return a non-NULL annual salary. Use the following basic formula to calculate the annual salary: (salary*12) + (commission_pct*salary*12) 10b) Use the function in a SELECT statement against the EMPLOYEES table for employees in department 30. 11) Create a procedure, ADD_EMPLOYEE, to insert a new employee into the EMPLOYEES table. The procedure should call a VALID_DEPTID function to check whether the department ID specified for the new employee exists in the DEPARTMENTS table. 11a) Create a function called VALID_DEPTID to validate a specified department ID and return a BOOLEAN value of TRUE if the department exists. 11b) Create the ADD_EMPLOYEE procedure to add an employee to the EMPLOYEES table. The row should be added to the EMPLOYEES table if the VALID_DEPTID function returns TRUE; otherwise, alert the user with an appropriate message. Provide the following parameters: - first_name - last_name - email
  • 4. - job: Use 'SA_REP' as the default. - mgr: Use 145 as the default. - sal: Use 1000 as the default. - comm: Use 0 as the default. - deptid: Use 30 as the default. - Use the EMPLOYEES_SEQ sequence to set the employee_id column. − Set the hire_date column to TRUNC(SYSDATE). 11c) Call ADD_EMPLOYEE for the name 'Jane Harris' in department 15, leaving other parameters with their default values. What is the result? 11d) Add another employee named Joe Harris in department 80, leaving the remaining parameters with their default values. What is the result? 12) 1) Create a package specification and body called JOB_PKG, containing a copy of your ADD_JOB, UPD_JOB, and DEL_JOB procedures as well as your GET_JOB function. Note: Use the code from your previously saved procedures and functions when creating the package. You can copy the code in a procedure or function, and then paste the code into the appropriate section of the package. a) Create the package specification including the procedures and function headings as public constructs. b) Create the package body with the implementations for each of the subprograms. c) Invoke your ADD_JOB package procedure by passing the values IT_SYSAN and SYSTEMS ANALYST as parameters. 13) Create and invoke a package that contains private and public constructs. a) Create a package specification and a package body called EMP_PKG that contains the following procedures and function that you created earlier: i) ADD_EMPLOYEE procedure as a public construct ii) GET_EMPLOYEE procedure as a public construct iii) VALID_DEPTID function as a private construct b) Invoke the EMP_PKG.ADD_EMPLOYEE procedure, using department ID 15 for employee Jane Harris with the email ID JAHARRIS. Because department ID 15 does not exist, you should get an error message as specified in the exception handler of your procedure. c) Invoke the ADD_EMPLOYEE package procedure by using department ID 80 for employee David Smith with the email ID DASMITH. 14) Modify the code for the EMP_PKG package that you created earlier, and then overload the ADD_EMPLOYEE procedure. Next, you create two overloaded functions called GET_EMPLOYEE in the EMP_PKG package. You also add a public procedure to EMP_PKG to populate a private PL/SQL table of valid department IDs and modify the VALID_DEPTID function to use the private PL/SQL table contents to validate department ID values. You also change the VALID_DEPTID validation processing function to use the private PL/SQL table of department IDs. Finally, you
  • 5. reorganize the subprograms in the package specification and the body so that they are in alphabetical sequence. Modify the code for the EMP_PKG package that you created earlier, and overload the ADD_EMPLOYEE procedure. a) In the package specification, add a new procedure called ADD_EMPLOYEE that accepts the following three parameters: i) First name ii) Last name iii) Department ID b) Implement the new ADD_EMPLOYEE procedure in the package body as follows: i) Format the email address in uppercase characters, using the first letter of the first name concatenated with the first seven letters of the last name. ii) The procedure should call the existing ADD_EMPLOYEE procedure to perform the actual INSERT operation using its parameters and formatted email to supply the values. iii) Click Run Script to create the package. Compile the package. c) Invoke the new ADD_EMPLOYEE procedure using the name Samuel Joplin to be added to department 30. 15) In the EMP_PKG package, create two overloaded functions called GET_EMPLOYEE: a) In the package specification, add the following functions: i) The GET_EMPLOYEE function that accepts the parameter called p_emp_id based on the employees.employee_id%TYPE type. This function should return EMPLOYEES%ROWTYPE. ii) The GET_EMPLOYEE function that accepts the parameter called p_family_name of type employees.last_name%TYPE. This function should return EMPLOYEES%ROWTYPE.