Procedures, Functions, Triggers Flashcards
What is the basic syntax for creating a procedure?
CREATE OR REPLACE
PROCEDURE name(parameters) AS
– Declare any variables here
BEGIN
EXCEPTION
END;
What is the basic syntax for creating a function?
CREATE OR REPLACE FUNCTION name(parameters) RETURN datatype AS -- Declare any variables here BEGIN -- Return statement must be included EXCEPTION
END;
Do these need declare statements (Y/N)?
- Procedures
- Functions
- Triggers
- N
- N
- Y
When do triggers execute?
DML statements
INSERT, UPDATE, DELETE
What are the 2 types of triggers?
- Statement Level
- Row Level
What are statement level triggers?
Fires once for a statement
EX. We update 10 rows, then it will fire 1 time
What are row-level triggers?
Will fire for every row that’s effected by a statement
EX. We update 10 rows, then it will fire 10 times
:OLD and :NEW bind variables only for ___
Row-level triggers
:OLD is meaningless in a ___
INSERT
:NEW is meaningless in a ___
DELETE
:OLD and :NEW are used in ___
Triggers
What is the basic syntax for creating a trigger?
CREATE OR REPLACE TRIGGER triggerName BEFORE -- OR AFTER INSERT -- OR DELETE, UPDATE ON tableName FOR EACH ROW --if row-level trigger -- PL/SQL block
What is the basic sequence for creating a sequence?
CREATE SEQUENCE sequenceName START WITH num;
SELECT sequenceName.nextval FROM DUAL;
How would you use a sequence in a trigger
CREATE OR REPLACE TRIGGER triggerName BEFORE INSERT ON tableName FOR EACH ROW BEGIN SELECT sequenceName.nextval INTO :NEW.columnName FROM DUAL; END;
In a ___, a return value must be used
Function