Procedures, Functions, Triggers Flashcards

1
Q

What is the basic syntax for creating a procedure?

A

CREATE OR REPLACE
PROCEDURE name(parameters) AS
– Declare any variables here
BEGIN

EXCEPTION

END;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the basic syntax for creating a function?

A
CREATE OR REPLACE
   FUNCTION name(parameters)
      RETURN datatype AS
   -- Declare any variables here
   BEGIN
      -- Return statement must be included
   EXCEPTION

END;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Do these need declare statements (Y/N)?

  • Procedures
  • Functions
  • Triggers
A
  • N
  • N
  • Y
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

When do triggers execute?

A

DML statements

INSERT, UPDATE, DELETE

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are the 2 types of triggers?

A
  • Statement Level

- Row Level

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are statement level triggers?

A

Fires once for a statement

EX. We update 10 rows, then it will fire 1 time

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are row-level triggers?

A

Will fire for every row that’s effected by a statement

EX. We update 10 rows, then it will fire 10 times

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

:OLD and :NEW bind variables only for ___

A

Row-level triggers

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

:OLD is meaningless in a ___

A

INSERT

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

:NEW is meaningless in a ___

A

DELETE

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

:OLD and :NEW are used in ___

A

Triggers

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the basic syntax for creating a trigger?

A
CREATE OR REPLACE TRIGGER triggerName
BEFORE -- OR AFTER
INSERT -- OR DELETE, UPDATE
ON tableName
FOR EACH ROW --if row-level trigger
-- PL/SQL block
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the basic sequence for creating a sequence?

A

CREATE SEQUENCE sequenceName START WITH num;

SELECT sequenceName.nextval FROM DUAL;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How would you use a sequence in a trigger

A
CREATE OR REPLACE TRIGGER triggerName
BEFORE INSERT ON tableName
FOR EACH ROW
BEGIN
	SELECT sequenceName.nextval INTO :NEW.columnName FROM DUAL;
END;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

In a ___, a return value must be used

A

Function

How well did you know this?
1
Not at all
2
3
4
5
Perfectly