Podcast
Questions and Answers
What function is used to calculate the difference between two dates in months?
What function is used to calculate the difference between two dates in months?
- `MONTHS_DIFF`
- `DATE_DIFF`
- `MONTHS_BETWEEN` (correct)
- `MONTHS.DIFF`
In PL/SQL, you can directly embed SQL queries within the PL/SQL block to manipulate data.
In PL/SQL, you can directly embed SQL queries within the PL/SQL block to manipulate data.
True (A)
How can you display output in PL/SQL?
How can you display output in PL/SQL?
DBMS_OUTPUT.PUT_LINE
To declare a variable to store a string of varying length in PL/SQL, one would use the datatype ________.
To declare a variable to store a string of varying length in PL/SQL, one would use the datatype ________.
Match the PL/SQL components with their descriptions
Match the PL/SQL components with their descriptions
Which of the following is the correct way to declare a variable v_date
of DATE type and initialize it to '2000-01-01'
in PL/SQL?
Which of the following is the correct way to declare a variable v_date
of DATE type and initialize it to '2000-01-01'
in PL/SQL?
In PL/SQL, comments started with --
extend until the end of the line only.
In PL/SQL, comments started with --
extend until the end of the line only.
How do you define a multi-line comment in PL/SQL?
How do you define a multi-line comment in PL/SQL?
To update the salary of an employee with employee_id = 122
in PL/SQL, you can use the _______ statement.
To update the salary of an employee with employee_id = 122
in PL/SQL, you can use the _______ statement.
Match the following terms with their descriptions:
Match the following terms with their descriptions:
Which of the following statements is true regarding NULL
values in PL/SQL?
Which of the following statements is true regarding NULL
values in PL/SQL?
A reserved word can be used as a user-defined identifier by enclosing it in double quotes.
A reserved word can be used as a user-defined identifier by enclosing it in double quotes.
What is the purpose of the %TYPE
attribute in PL/SQL?
What is the purpose of the %TYPE
attribute in PL/SQL?
The upper limit of PLS_INTEGER
datatype is ________.
The upper limit of PLS_INTEGER
datatype is ________.
Match the following conditional statements with their correct function in PL/SQL:
Match the following conditional statements with their correct function in PL/SQL:
Which statement is used to skip the current iteration of a loop in PL/SQL?
Which statement is used to skip the current iteration of a loop in PL/SQL?
In PL/SQL, you can use named loops, which can be useful for clarity in nested loops.
In PL/SQL, you can use named loops, which can be useful for clarity in nested loops.
What statement is used to exit a loop in PL/SQL?
What statement is used to exit a loop in PL/SQL?
To check if a number is even or odd in PL/SQL, you can use the ________ function.
To check if a number is even or odd in PL/SQL, you can use the ________ function.
Match each loop type with its appropriate use case
Match each loop type with its appropriate use case
Which of the following is the correct syntax to use GOTO
statement in a for loop?
Which of the following is the correct syntax to use GOTO
statement in a for loop?
When using the CONTINUE
statement inside a loop, the statements after CONTINUE
are skipped, and the loop restarts from its beginning.
When using the CONTINUE
statement inside a loop, the statements after CONTINUE
are skipped, and the loop restarts from its beginning.
In PL/SQL, what does SQL%ROWCOUNT
return?
In PL/SQL, what does SQL%ROWCOUNT
return?
Use _______ to manipulate data in PL/SQL
Use _______ to manipulate data in PL/SQL
Match the following cursor attributes with their descriptions:
Match the following cursor attributes with their descriptions:
What will be the state of %NOTFOUND
if a cursor successfully fetches a row?
What will be the state of %NOTFOUND
if a cursor successfully fetches a row?
An explicit cursor must be declared and opened whereas implicit cursors are automatically managed by Oracle.
An explicit cursor must be declared and opened whereas implicit cursors are automatically managed by Oracle.
What keyword is used to retrieve values from a cursor into variables?
What keyword is used to retrieve values from a cursor into variables?
A cursor _____ allows you to perform DML operations one row at a time
A cursor _____ allows you to perform DML operations one row at a time
Match the following types of cursors with their appropriate use cases:
Match the following types of cursors with their appropriate use cases:
What is the purpose of using %ROWTYPE
?
What is the purpose of using %ROWTYPE
?
A cursor can be used in a FOR
loop to process each row in the active set automatically.
A cursor can be used in a FOR
loop to process each row in the active set automatically.
Within a cursor FOR
loop, how do you access the fields of the current row?
Within a cursor FOR
loop, how do you access the fields of the current row?
You can specify that a cursor is _____
to prevent other users from modifying the rows while you are processing them.
You can specify that a cursor is _____
to prevent other users from modifying the rows while you are processing them.
Match cursor attributes with their usage
Match cursor attributes with their usage
What PL/SQL construct is used to encapsulate a series of operations into a named block that can be invoked multiple times?
What PL/SQL construct is used to encapsulate a series of operations into a named block that can be invoked multiple times?
Procedures can return values to the calling environment, which is similar to functions.
Procedures can return values to the calling environment, which is similar to functions.
In PL/SQL, how do you specify that a procedure parameter is an IN
parameter?
In PL/SQL, how do you specify that a procedure parameter is an IN
parameter?
To replace a procedure, use CREATE OR _______ PROCEDURE
statement.
To replace a procedure, use CREATE OR _______ PROCEDURE
statement.
Which conditional logic structures are available in PL/SQL to handle complex situations?
Which conditional logic structures are available in PL/SQL to handle complex situations?
In PL/SQL, nested IF
statements are generally preferred over using the ELSIF
clause for better performance.
In PL/SQL, nested IF
statements are generally preferred over using the ELSIF
clause for better performance.
Flashcards
PL/SQL Print
PL/SQL Print
A block of code in PL/SQL to print name, birthday and age
Age Calculator
Age Calculator
PL/SQL to calculates your age in 10, 20 and 25 years
PL/SQL Day
PL/SQL Day
A block of code to get the day you were born
PL/SQL Math
PL/SQL Math
Signup and view all the flashcards
Employee Incentive
Employee Incentive
Signup and view all the flashcards
Reserved Words
Reserved Words
Signup and view all the flashcards
PL/SQL Comments
PL/SQL Comments
Signup and view all the flashcards
Variable Declaration
Variable Declaration
Signup and view all the flashcards
Adjust Salary
Adjust Salary
Signup and view all the flashcards
Usage of NULL
Usage of NULL
Signup and view all the flashcards
Character type
Character type
Signup and view all the flashcards
Insert Data
Insert Data
Signup and view all the flashcards
Employee info
Employee info
Signup and view all the flashcards
Upper Limit
Upper Limit
Signup and view all the flashcards
Conditional Assignment
Conditional Assignment
Signup and view all the flashcards
Employee Salary
Employee Salary
Signup and view all the flashcards
Number Check
Number Check
Signup and view all the flashcards
incentive Cal
incentive Cal
Signup and view all the flashcards
Weekday check
Weekday check
Signup and view all the flashcards
Sales Condition
Sales Condition
Signup and view all the flashcards
Vacancies check
Vacancies check
Signup and view all the flashcards
Grade description
Grade description
Signup and view all the flashcards
Number Sign
Number Sign
Signup and view all the flashcards
Alphanumeric Character
Alphanumeric Character
Signup and view all the flashcards
Temp converstion
Temp converstion
Signup and view all the flashcards
Date Check
Date Check
Signup and view all the flashcards
Loop stop
Loop stop
Signup and view all the flashcards
Nested Loops
Nested Loops
Signup and view all the flashcards
J Test
J Test
Signup and view all the flashcards
Skip Numbers
Skip Numbers
Signup and view all the flashcards
Loop test
Loop test
Signup and view all the flashcards
Varible check
Varible check
Signup and view all the flashcards
Join info
Join info
Signup and view all the flashcards
salary check
salary check
Signup and view all the flashcards
Dates
Dates
Signup and view all the flashcards
Employee data
Employee data
Signup and view all the flashcards
Data join
Data join
Signup and view all the flashcards
Study Notes
- PL/SQL (Procedural Language/SQL) is a programming language that extends SQL with procedural capabilities.
- PL/SQL blocks are fundamental units of code, that can be named or anonymous.
- Blocks consist of a DECLARE section, a BEGIN section, and an optional EXCEPTION section.
Printing Name, Birthday, and Age
- A PL/SQL block can be created to print name, birthday, and age.
- Variables are declared with VARCHAR2 for the name and DATE for the birthday.
- The age is computed via
TRUNC(MONTHS_BETWEEN(SYSDATE, Birthday) / 12)
which determines the integer part of the age based on months since the birthday
Calculating Age in Future Years
- A PL/SQL block determines future age in 10, 20, and 25 years.
- It calculates the current age and subsequently adds 10, 20, and 25 years to that value.
Determining Day of the Week for a Given Birthday
- A PL/SQL block outputs the day of the week someone was born.
- It coverts the birthday date to a day string using
TO_CHAR(v_birthday, 'Day')
.
Performing Addition and Subtraction
- A PL/SQL block calculates the sum and difference of two numbers.
- It declares two number variables, calculates their sum and difference and presents the results.
Calculating Employee Incentive
- A PL/SQL block calculates an employee's incentive based on their salary.
- It uses the
employees
table with thesalary%TYPE
attribute. - Incentives are calculated by multiplying the salary by
0.10
.
Using Reserved Words as Identifiers
- A PL/SQL block is created to show that reserved words can be used as user defined identifiers by surrounding them in double quotes.
- Dubble quotes are valid
“BEGIN” number := 10
.
Explaining Comments
- Single-line comments start with
--
. - Multi-line comments are enclosed within
/*
and*/
.
Declaring Variables
- Different datatypes are declared like VARCHAR2, NUMBER, and DATE.
- Date are initialized with SYSDATE.
Adjusting Employee Salary
- A PL/SQL block updates an employee's salary by 10%
- The HR schema
employees
table is used. - The updated salary is displayed.
Usage of NULL Values
NULL
is not equal to any value, including itself, during comparison.- IS NULL should be used to detect
NULL
values.
Declaring Character Type Variables
- CHAR and VARCHAR2 variables are declared.
- CHAR can be fixed-length, VARCHAR2 is variable-length.
Inserting Data with Character Type Variable
- A PL/SQL block that inserts a new employee into the
employees
table using a VARCHAR2 variable for the first name.
Inserting Data into Departments Table
- A PL/SQL code block that inserts a new department using
VARCHAR2
for the department name.
Upper Limit of PLS_INTEGER
- The maximum value for
PLS_INTEGER
is2147483647
.
Arranging Numbers
- IF/ELSE statement arranges two numbers into
num_small
andnum_large
.
Procedure for Incentive Status
- A procedure calculates and updates employee incentives.
- SQL%ROWCOUNT checks for successful updates.
Even or Odd Check
- The MOD function is used to check if a number is even or odd.
MOD(number, 2) = 0
indicates an even number.
Procedure for Incentive By Target
- A procedure calculates bonus based on target.
- It calculates a bonus based on whether an employee's target exceeds 5000.
Weekday Check Procedure
- A procedure determines if a date is a weekend or a weekday
- Built-in IN operator is used
- Day converted using TO_CHAR
Incentive on Sales Limit
- Incentive amounts are computed based on different sales thresholds, with varying percentages applied to sales figures.
Vacancies Check
- A COUNT(*) statement determines the number of employees in department 50.
Display Grade Description
- A CASE statement is used to output a grade description based on a grade.
- It assigns descriptions such as 'Excellent', 'Good', 'Average', or 'Fail' based on the value of
v_grade
.
Vacancy Check in Department
- Counts employee in department, then indicates if there are vacancies available in that department.
Display Grade with CASE
- The CASE keyword allows you to SELECT results in the THEN part of the statement
Display Grade with CASE and Exception
- Handled exceptions by calling
RAISE_APPLICATION_ERROR
.
Positive or Negative Check
- An ELSIF statement can check if a number is negative.
Letter or Digit Check
- BETWEEN can check for either a letter or digit.
Temperature Conversion
- Used ROUND(temp,2) to give 2 DP
Specific Date Check
- Built in TO_CHAR with parameter
Day
displays day of week that date falls on
Loop EXIT
- EXIT WHEN command lets the loop end when the expression equates to true
Loop WHEN EXIT
- A LOOP can be exited using the EXIT WHEN statement
Nested Loop
- Inner and outer loops each repeat as indicated by
1..3 LOOP
.
Update Salary with Mid-Range Check
- Updates salaries based on conditions related to mid-salary range
- v_mid_salary determined by
(v_min_salary + v_max_salary) / 2
Nested Quit
- Nested loops can check for specific values, can call
Exit When
command.
CONTINUE Statement
- The CONTINUE statement skips the rest of the current loop iteration and proceeds to the next iteration.
CONTINUE WHEN Statement
- The CONTINUE WHEN statement skips the rest of the statements in the loop iteration if the condition specified after WHEN.
Print First N Number
- A WHILE statement increments and displays values.
Addition N numbers
- The loop iterates until the counter
i
reaches the specified limitv_n
, printing output.
Local Variable
- Assigning a local variable lets you override the global variable in the scope of the inner block.
Nested-FOR-Loop
- The outer and inner loop have labels of
outer_loop
andinner_loop
. - Used loop commands within for loops.
Prime Numbers
- Check for prime numbers to a given number by using
GOTO PrimeNumber
- A GOTO command can be used to go to a specific line, use
<<label>>
to set.
Insert from Table
- Inserting from one table to another
- Insert data into one table from another.
Insert Row
- Checking it the salary is not null or salary is not valid.
Cursors
- Cursors can select from a table with WHERE and other commands
- Cursors can include %TYPE in the DECLARE statement
- Shows total employee and displays result
CURVAL and NEXTVAL
- A sequence increments and outputs value
employee_seq.NEXTVAL
- selects the next in sequenceemployee_seq.CURVAL
– selects the current value- Displays two different output lines
SQL%ROWCOUNT
SQL%ROWCOUNT
returns the number of rows affected by the most recent SQL statement.
Implicit Cursor Without Attribute
- Updates or does not update rows, based on if it find an entry in the table.
- Confirmed by
Update executed successfully
messages.
SQL%FOUND
- The SQL%FOUND attribute used after DELETE determines if a delete executed.
SQL%NOTFOUND
- The SQL%NOTFOUND used after UPDATE determines if a entry was updated.
Table-Based Record
- Can select direct in to
v_employee
variable inemployees%ROWTYPE
- Outputs name of employee
Details of employee 149
- Selecting direct from table gives you access to data
- Easy to display output from table
Details with cursor
- Create cursors to select from data
- Display that data
Details cursor and retrieve display
- Can create variable on the fly in SQL SELECT to display
Cursor Datatype
- Creating a datatype is a good way to re-use code.
Implicit Cursor
- Loops though table or cursor
- Sets the record from the table, then select data
- Outputs data
Explicit Cursor
- Loops through table or cursor
- Sets the record from the cursor, then select data
- Outputs data
Salary with CURRENTOF
- Select data and select from loop
- Use CURRENTOF to update table as it loops through the selected data.
Fetch Single Record and Column
- Fetch a single record and single column from a table is an easy and fast way to extract data and display it.
Fetch Single Column
- Displays a column
- Great way to display column
Multiple Records and Columns
- Displays multiple values
- Cursors are effective in pulling the data from the table.
Different Table Records
- A join can select from different rows
- A LOOP can display the data from a database join
Nested Cursors
- Displays department ID
- Displays employee connected to department ID
Cursor for Loops
- Nestles functions and loops for use
- Displays table information and labels them
Managers and the Department Name
- Selects departments and the associated users
- Displays the managers
Multiple Tables
- Can select from multiple tables to insert information
- Effective way to populate database.
Two Tables
- Select data to join
- Insert new data from joined table.
Create Cursor
- Select first name, last name , salary
- Fetch, process, output.
Fetch Statement
- The code selects from the table
- Creates cursor and then fetch though
First Three
- Can select three from table
- Using command
num <= 3
Query cursor and variables
- Assign value as var
- Select that var, display output
List data
- Creates view with managers last name table
- Loops though output
Table select
- Display table and values
- Join statements use
Display Name Column
- Data select, where condition, display output
Display records
- Use sub query for department name.
Record in Table
- Select employee id and employee name
- Use “Record” parameter for types
Query in Cursor
- Select information from sub query
- Add on the value table on the on statement
Salary Increase
- Calculate increase bases on date hire
- Use math to calc
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.