midterm Flashcards
math operators
*
/
**
logical operators
AND
OR
NOT
between
min and max value
WHERE colName BETWEEN val1 AND val2
in clause
compare a value to a list of literal values that have been specified
WHERE colName IN (val1, val2, val3, val4)
LIKE clause
wildcards
% represents zero or more characters
_ represents a single character
WHERE FIrst_Name LIKE ‘Herma%’
DISTINCT clause
eliminates _____ records, fetching only ___ unique records when using a select statement
duplicate, unique
subquery syntax
SELECT emp_ID, name
FROM employees
WHERE salary =
(SELECT MAX(salary) FROM employees);
let you use an aggregate function in the where clause
types of joins (6)
inner join
left join
right join
full join
cross join
self join
input
V_name := ‘&name’;
NCHAR vs VARCHAR
when you insert a string shorter than the defined length into an NCHAR column, the database pads the string with spaces to math the defined length
varchar does not do this
NUMBER vs pls_int
number stores more than int
if statements syntax
IF condition THEN
statements;
ELSIF condition THEN
statements;
ELSE
statements;
END IF;
case statement syntax
CASE l_num
WHEN 11 THEN
statements;
WHEN 10 THEN
statements;
ELSE
statements
END CASE;
_________________________-
CASE
WHEN l_num > 11 THEN
statements;
WHEN l_num =10 THEN
statements;
ELSE
statements;
END CASE
pls_integer vs simple_integer
pls_intger can store null values, simple_integer cannot store null values, it does not raise an overflow exception and it wraps around to zero
while loop syntax
WHILE condition LOOP
statements
END LOOP;
IN vs OUT parameters
IN - read only
OUT - can change the value (write)
EXCEPTIONS
syntax
zero_divide
case_not_found
no_data_found
rowtype_mismatch
too_many_rows
value_error
EXCEPTION
WHEN ZERO_DIVIDE THEN
DBMS_OUTPUT>PUT(‘error message’);
END:
how to define an exception
DECLARE
varName EXCEPTION;
EXCEPTION
WHEN varName THEN
print statement
END;
for loop syntax
FOR i IN 1 .. 20 LOOP
statments;
END LOOP;
cursor declare syntax
declare
CURSOR cr IS SELECT cust_ID, cust_first, cust_last FROM SH.customers
cursor attributes
%ISOPEN
%NOTFOUND
%FOUND
%ROWCOUNT
4 steps in using an explicit cursor
declare
open
fetch
close
when fetching to a record or list of variables, the variables should be ___________
in the same order as the variables in the cursor
declare record
TYPE rec_cust IS RECORD(l_id NUMBER, l_first VARCHAR(20));
– instance of record
Cust rec_cust
create a table of records
create table using existing table structure
TYPE arr_cust IS TABLE OF rec_cust;
–instance of arr_cust
l_cust arr_cust
TYPE arr_cust IS TABLE OF sh.customers%ROWTYPE;
l_cust arr_cust;