Podcast
Questions and Answers
What does the UPDATE statement do in PL/SQL?
What does the UPDATE statement do in PL/SQL?
- Merges rows from one table into another
- Modifies existing rows in a table (correct)
- Removes rows from a table
- Adds new rows to a table
What is a key characteristic of the MERGE statement?
What is a key characteristic of the MERGE statement?
- It can update the same row multiple times
- It requires having SELECT privileges on both tables
- It only allows insertion of new rows
- It selects rows from one table to update or insert into another table (correct)
Which statement is used to delete rows from a table in PL/SQL?
Which statement is used to delete rows from a table in PL/SQL?
- ADD
- REMOVE
- DELETE (correct)
- DROP
Which command would you use to add a new employee record to the COPY_EMP table?
Which command would you use to add a new employee record to the COPY_EMP table?
In which scenario would you use the UPDATE statement?
In which scenario would you use the UPDATE statement?
What must you have to execute the MERGE statement successfully?
What must you have to execute the MERGE statement successfully?
Which PL/SQL statement would you use to adjust the salary of employees in a specific job category?
Which PL/SQL statement would you use to adjust the salary of employees in a specific job category?
What happens when the DELETE statement is executed in PL/SQL?
What happens when the DELETE statement is executed in PL/SQL?
What is the purpose of the INTO clause in a PL/SQL SELECT statement?
What is the purpose of the INTO clause in a PL/SQL SELECT statement?
Which of the following DML commands is NOT used to modify the data in a PL/SQL block?
Which of the following DML commands is NOT used to modify the data in a PL/SQL block?
When is it important to use a copy of original tables like COPY_EMP?
When is it important to use a copy of original tables like COPY_EMP?
Which DML statement would you use to add new rows to a table in PL/SQL?
Which DML statement would you use to add new rows to a table in PL/SQL?
What does the MERGE statement do in PL/SQL?
What does the MERGE statement do in PL/SQL?
Which statement best describes implicit cursors in PL/SQL?
Which statement best describes implicit cursors in PL/SQL?
What happens if you attempt to modify a table that is marked as necessary for course progression?
What happens if you attempt to modify a table that is marked as necessary for course progression?
What is the primary function of DML statements in PL/SQL?
What is the primary function of DML statements in PL/SQL?
What is an implicit cursor in PL/SQL?
What is an implicit cursor in PL/SQL?
What happens in a MERGE statement when a match is found?
What happens in a MERGE statement when a match is found?
Which of the following is NOT a characteristic of an explicit cursor?
Which of the following is NOT a characteristic of an explicit cursor?
What PL/SQL code structure helps you determine how many rows were processed by a DML statement?
What PL/SQL code structure helps you determine how many rows were processed by a DML statement?
In the DELETE statement given, what variable is used to target the deletion of rows?
In the DELETE statement given, what variable is used to target the deletion of rows?
What does the INSERT clause in the MERGE statement do when there is no match?
What does the INSERT clause in the MERGE statement do when there is no match?
Which implicit cursor attribute helps to understand the outcome of the last SQL statement executed?
Which implicit cursor attribute helps to understand the outcome of the last SQL statement executed?
What is the primary purpose of cursors in PL/SQL?
What is the primary purpose of cursors in PL/SQL?
What is the purpose of the SQL%FOUND attribute?
What is the purpose of the SQL%FOUND attribute?
Which PL/SQL statement uses SQL%ROWCOUNT correctly?
Which PL/SQL statement uses SQL%ROWCOUNT correctly?
What does the SQL%NOTFOUND attribute indicate?
What does the SQL%NOTFOUND attribute indicate?
After executing an UPDATE statement, how can you confirm the number of rows updated?
After executing an UPDATE statement, how can you confirm the number of rows updated?
Which of these attributes should not be used in SQL statements?
Which of these attributes should not be used in SQL statements?
In which situation would SQL%ROWCOUNT return a value of zero?
In which situation would SQL%ROWCOUNT return a value of zero?
During what type of operations should cursor attributes be utilized?
During what type of operations should cursor attributes be utilized?
What would the output of DBMS_OUTPUT.PUT_LINE(SQL%ROWCOUNT || ' rows updated.'); indicate if no rows were updated?
What would the output of DBMS_OUTPUT.PUT_LINE(SQL%ROWCOUNT || ' rows updated.'); indicate if no rows were updated?
Study Notes
Manipulating Data in PL/SQL
- PL/SQL blocks can include data manipulation language (DML) statements like INSERT, UPDATE, DELETE, and MERGE.
- DML statements enable modifying multiple rows in a table.
- INSERT adds new rows.
- UPDATE modifies existing rows.
- DELETE removes rows.
- MERGE selects rows from one table and uses them to update and/or insert new rows into another table, based on a condition.
- MERGE statements are deterministic—a target row cannot be updated more than once.
- MERGE requires INSERT and UPDATE object privileges in the target table, and SELECT privileges in the source table.
Implicit and Explicit Cursors
- Implicit cursors are automatically created by Oracle for each SQL data manipulation statement and single-row queries.
- Implicit cursors are named "SQL" and are managed by the Oracle server.
- Explicit cursors are defined by PL/SQL programmers for queries returning multiple rows.
Cursor Attributes for Implicit Cursors
- Cursor attributes are variables used to monitor the results of cursor actions.
- They are prefaced with "SQL" and can only be used in PL/SQL, not SQL statements.
- SQL%FOUND is a Boolean variable that returns TRUE if the last executed SQL statement returned at least one row.
- SQL%NOTFOUND is a Boolean variable that returns TRUE if the last executed SQL statement returned no rows.
- SQL%ROWCOUNT is an integer variable that returns the number of rows affected by the last executed SQL statement.
Using Implicit Cursor Attributes
- Example 1: After deleting rows from a table based on a condition, the code prints the number of rows deleted using
SQL%ROWCOUNT
. - Example 2: After updating several rows in a table based on a condition, the code prints the number of rows updated using
SQL%ROWCOUNT
. - Good Practice Guideline:
SQL%ROWCOUNT
can be used to report success or failure of DML operations.
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.
Related Documents
Description
Explore the intricacies of data manipulation in PL/SQL, including how to effectively use DML statements like INSERT, UPDATE, DELETE, and MERGE. Delve into the concepts of implicit and explicit cursors and learn how they function in handling SQL queries.