Loading topic
SELECT can return zero rows, one row, or a million rows, and the statement treats them as one result. PL/SQL is a procedural language and handles one value or one record at a time. A cursor connects the two. This chapter explains what a cursor is, where it lives, how i7 min readDECLARE, BEGIN, EXCEPTION and END. It also assumes you know basic SQL DML, variables, IF statements and simple exception handling. By the end you will be able to read the outcome of any DML statement through the SQL cursor5 min read%ISOPEN, %FOUND, %NOTFOUND and %ROWCOUNT. This chapter covers what each one returns at each point in a cursor's life, how the implicit cursor SQL differs from an explicit cursor, and the mistakes that cause ORA-01001 and silent 4 min read%FOUND and %NOTFOUND attributes. Here you will replace a list of scalar variables with one record variable that matches a cursor's r5 min readLOOP with EXIT WHEN and WHILE with a priming fetch. It also covers where the exit test belongs and the mistakes that follow when it is in the w5 min readLOOP control flow, and handle exceptions. You should also know how an explicit cursor is declared, opened, fetched and closed, and how %NOTFOUND and %ROWTYPE work. The cursor FOR loop wraps that whole li5 min readSELECT. It also assumes you have seen the named cursor FOR loop from the previous chapter. Here you drop the CURSOR declaration and put the query directly in the loop header.5 min readFETCH or a cursor FOR loop. It also assumes you know basic exception handling.5 min read%FOUND, %NOTFOUND and %ISOPEN.5 min read%ROWTYPE, the cursor FOR loop, and basic PL/SQL exception handling. You should also know what a collection is, meaning a PL/SQL variable that holds many values under one name.6 min readDECLARE, BEGIN, EXCEPTION and END section. It also assumes you know the cursor lifecycle (declare, open, 6 min readFOR UPDATE, SYS_REFCURSOR and BULK COLLECT ... LIMIT. Here you decide which of these to use for a g6 min read