Podcast
Questions and Answers
What does the UPDATE statement do in PL/SQL?
What does the UPDATE statement do in PL/SQL?
What is a key characteristic of the MERGE statement?
What is a key characteristic of the MERGE statement?
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?
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?
Signup and view all the answers
In which scenario would you use the UPDATE statement?
In which scenario would you use the UPDATE statement?
Signup and view all the answers
What must you have to execute the MERGE statement successfully?
What must you have to execute the MERGE statement successfully?
Signup and view all the answers
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?
Signup and view all the answers
What happens when the DELETE statement is executed in PL/SQL?
What happens when the DELETE statement is executed in PL/SQL?
Signup and view all the answers
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?
Signup and view all the answers
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?
Signup and view all the answers
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?
Signup and view all the answers
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?
Signup and view all the answers
What does the MERGE statement do in PL/SQL?
What does the MERGE statement do in PL/SQL?
Signup and view all the answers
Which statement best describes implicit cursors in PL/SQL?
Which statement best describes implicit cursors in PL/SQL?
Signup and view all the answers
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?
Signup and view all the answers
What is the primary function of DML statements in PL/SQL?
What is the primary function of DML statements in PL/SQL?
Signup and view all the answers
What is an implicit cursor in PL/SQL?
What is an implicit cursor in PL/SQL?
Signup and view all the answers
What happens in a MERGE statement when a match is found?
What happens in a MERGE statement when a match is found?
Signup and view all the answers
Which of the following is NOT a characteristic of an explicit cursor?
Which of the following is NOT a characteristic of an explicit cursor?
Signup and view all the answers
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?
Signup and view all the answers
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?
Signup and view all the answers
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?
Signup and view all the answers
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?
Signup and view all the answers
What is the primary purpose of cursors in PL/SQL?
What is the primary purpose of cursors in PL/SQL?
Signup and view all the answers
What is the purpose of the SQL%FOUND attribute?
What is the purpose of the SQL%FOUND attribute?
Signup and view all the answers
Which PL/SQL statement uses SQL%ROWCOUNT correctly?
Which PL/SQL statement uses SQL%ROWCOUNT correctly?
Signup and view all the answers
What does the SQL%NOTFOUND attribute indicate?
What does the SQL%NOTFOUND attribute indicate?
Signup and view all the answers
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?
Signup and view all the answers
Which of these attributes should not be used in SQL statements?
Which of these attributes should not be used in SQL statements?
Signup and view all the answers
In which situation would SQL%ROWCOUNT return a value of zero?
In which situation would SQL%ROWCOUNT return a value of zero?
Signup and view all the answers
During what type of operations should cursor attributes be utilized?
During what type of operations should cursor attributes be utilized?
Signup and view all the answers
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?
Signup and view all the answers
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.