Quiz 2 (week 2 cursors, week 3, week 4) Flashcards
A cursor is a _____ to this context area
A cursor can hold ___ __ ___rows of data
The set of rows the cursor holds is referred to as the _____ ____
pointer
zero or more
active set
____ ___ Are automatically created by Oracle whenever a ___ statement is executed
DML (INSERT, UPDATE,
DELETE)
%_____ - true if 1 or more rows are affected
%____ - the opposite of %____
%_____ - the number of rows processed
SQL%FOUND (true if 1 or more rows are affected)
SQL%NOTFOUND (the opposite of SQL%FOUND)
SQL%ROWCOUNT (the number of rows processed)
Explicit cursors are programmer defined cursors for gaining more control over the ___ ___
Once opened, the data must be moved from the ___ ____ to a ___ ___ to be used by the program.
Variables must be populated ___ __ __ __ of the data in the cursor.
context area
temp area
local variable
in the same order
Declare cursor syntax
DECLARE
l_id sh.Customers.Cust_ID%TYPE
l_fname sh.Customers.Cust_First_Name%TYPE
l_lname sh.Customers.Cust_Last_Name%TYPE
CURSOR cr IS SELECT Cust_ID, Cust_First_Name, Cust_Last_Name
FROM sh.Customers
WHERE Cust_ID < 100;
CURSOR name IS [select statement]
fetch from cursor into variables without bulk collect syntax
BEGIN
OPEN cr;
LOOP
FETCH cr INTO l_id, l_fname, l_lname;
DBMS_OUTPUT>PUT_LINE(rowNames);
EXIT WHEN cr%NOTFOUND;
END LOOP;
CLOSE cr;
END;
cursor attributes
cr%ISOPEN
cr%NOTFOUND
cr%FOUND
cr%ROWCOUNT
bulk collect rows syntax
DECLARE
TYPE Rec_Cust IS RECORD
(l_id NUMBER,
name VARCHAR2(20));
TYPE Arr_Cust IS TABLE OF Rec_Cust; l_Cust Arr_Cust
define cursor
BEGIN
OPEN cr;
FECTH cr BULK COLLECT INTO l_cust;
CLOSE cr;
FOR i IN 1 .. l_Cust.LAST LOOP DBMS_OUTPUT>PUT_LINE(rows); END LOOP; END;
Make a record that has the data types of the table
make a table of the record
define cursor
open cr, bulk collect, close cr
for loop
how to access rows of a table with an index
tableName(1)
forall loop
when to use
syntax
can only include one DML
FORALL i IN 1..l_Cust.LAST
INSERT INTO table Values l_cust(i)
___ ___ - Is a named block of PL\SQL
code that is saved in in the
DBMS
Procedures can be executed
using ____
Stored Procedures can
___ ____
perform ___ or ___
Stored procedures
EXECUTE
return values
perform DDL or DMLs
Procedure syntax
CREATE OR REPLACE PROCEDURE hello (parameterName IN VARCHAR2)
IS
returnedVar VARCHAR2(24);
BEGIN
END;
ways to call a procedure
procedureName(val1, val2)
CALL procedureName(val1, val2)
procedure_name(param2 => val2, param1 => val1)
assignment operator
:=
what does IN mean in procedures
where to use
read only, you can use the data, but you cannot change it
use in the parameter section
what does OUT mean in procedures
where to use
writable variable
use in the parameter section
what does INOUT mean in procedures
readable and writable
how to get an empty table with the table structure of another table
CREATE TABLE tableName AS
SELECT * FROM otherTable
WHERE 1=2;
1 is never equal to 2, so no rows will be selected
a __ always returns a value
a ___ cant make charges to the database, like DML statements
function
function
the return keyword is optional for functions t/f
f
function syntax
CREATE OR REPLACE FUNCTION functionName (param1 dataType)
RETURN dataType
IS
PL/SQL block
functions can return multiple values t/f
f
only one