PLSQL Flashcards

(73 cards)

1
Q

What does PL/SQL stand for?

A

Procedural SQL

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

What is a major drawback of SQL?

A

No procedural capability

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

What is one advantage of PL/SQL?

A

Supports SQL data manipulation along with conditional checking

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

What are the key components of a PL/SQL block?

A

DECLARE, BEGIN, EXCEPTION, END

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

Fill in the blank: PL/SQL data types are native to _______’s data dictionary.

A

Oracle

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

What does %TYPE do in PL/SQL?

A

Declares a variable or constant to have the same data type as that of a previously defined variable or a column in the table or view

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

What is a requirement for naming a variable in PL/SQL?

A

A variable must begin with a character and can be followed by a maximum of 29 other characters

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

What is DBMS_OUTPUT?

A

A package that includes a number of procedures and functions that accumulate information in a buffer

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

How do you display user messages in PL/SQL?

A

Using the PUT_LINE procedure

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

What is the syntax for a simple IF statement in PL/SQL?

A

if <condition> then <statements>; end if;</statements></condition>

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

What is the syntax for an ELSE IF ladder in PL/SQL?

A

if <condition1> then <statements>; elsif <condition2> then <statements>; else <statements>; end if;</statements></statements></condition2></statements></condition1>

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

What is a simple loop in PL/SQL?

A

loop <statements> end loop;</statements>

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

What is the purpose of the EXIT statement in a loop?

A

To terminate the loop when a certain condition is met

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

What is the syntax for a WHILE loop in PL/SQL?

A

while <condition> loop <statements> end loop;</statements></condition>

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

What is a stored function in PL/SQL?

A

Logically grouped PL/SQL statements that perform a specific task and return a single value

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

What are the three parts of a stored function?

A

Declarative part, executable part, exception handling

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

What is the purpose of the CREATE OR REPLACE FUNCTION statement?

A

To define a new stored function or replace an existing one

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

What is the main difference between functions and procedures in PL/SQL?

A

Functions explicitly return a single value, while procedures can return multiple values

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

What is the syntax for creating a stored procedure?

A

create or replace procedure procedure_name(parameters) is <local> begin <PL/SQL statements>; exception <PL/SQL statements to handle errors> end;</local>

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

What does the term ‘BULK COLLECT’ refer to in PL/SQL?

A

A method to fetch multiple rows of data into a collection in a single operation

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

True or False: Stored functions can use DDL statements.

A

False

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

Fill in the blank: To execute a function, use the syntax select _______ from dual;

A

funname(parameters)

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

What is the purpose of the procedure ‘proc11’?

A

To calculate the area of a circle given its radius

The formula used is area = radius * radius * pi, where pi is constant.

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

What is the constant value of pi used in ‘proc11’?

A

3.14

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
What is the minimum balance constant defined in the 'withdraw' procedure?
1000
26
What happens if the new balance after withdrawal is less than the minimum balance?
The procedure outputs 'Cannot withdraw'.
27
What are the three modes of parameter passing in stored procedures?
* IN * OUT * IN OUT
28
What is the default mode of parameter passing?
IN
29
What does the OUT mode of parameter passing do?
Returns value from called program to the calling program.
30
In the OUT mode, what must the calling program pass?
A variable name for the OUT parameter.
31
What is the purpose of the IN OUT mode?
To pass values from the calling program to the called program and return a value.
32
What is the function of 'proc1' in the example?
To retrieve the name of an instructor based on their ID.
33
What SQL command is used to retrieve employee details in the 'get_employee_details' procedure?
SELECT
34
What does the function 'show_description' return if no data is found?
'The Course is not in the database'
35
What are cursors in PL/SQL?
Work areas reserved by Oracle for internal processing of SQL statements.
36
What is an implicit cursor?
A cursor managed automatically by Oracle.
37
What does the attribute SQL%ISOPEN return for implicit cursors?
False
38
What is the first step in using explicit cursors?
Declare a cursor that specifies the SQL statement to be processed.
39
What does the cursor attribute SQL%ROWCOUNT return?
The number of rows affected by an insert, update, delete, or select statement.
40
What is the purpose of the FOR loop in explicit cursors?
To iterate over each record in the cursor.
41
What SQL statement is used to update the budget in the example with implicit cursors?
UPDATE department SET budget = 200000 WHERE building = 'Watson';
42
What is the purpose of the 'Discount' procedure?
To apply a 5% discount to courses with more than 80 enrollments.
43
What SQL clause is used to group records in the 'Discount' procedure?
HAVING
44
What happens when the cursor 'c_group_discount' is iterated over?
The cost of qualifying courses is updated with a 5% discount.
45
Fill in the blank: The 'withdraw' procedure uses _______ to check the existence of an account.
count(*)
46
True or False: In the IN mode, the parameter can be assigned a value within the called program.
False
47
What type of variable must be passed for an OUT parameter?
A variable name
48
What must the calling function not specify for an OUT parameter?
Literal, constant, or expression
49
What is the output when the balance is updated successfully?
'New balance: ' || newbal
50
What command is used to commit changes in the 'withdraw' procedure?
COMMIT
51
What is a trigger in PL/SQL?
A PL/SQL block associated with a table, executed automatically in response to a specific data manipulation event ## Footnote Data manipulation events include insert, update, and delete.
52
What are the components of a trigger?
* Triggering SQL Statement * Trigger Action * Trigger Restriction
53
What is a Before Trigger?
A trigger that is fired before the triggering SQL statement is executed.
54
What is an After Trigger?
A trigger that is fired after the triggering SQL statement is executed.
55
What is the difference between statement level and row level triggers?
* Statement Level: Fired for each DML operation on the table, cannot access individual record values. * Row Level: Triggered for each record inserted, updated, or deleted.
56
What is a Row Level Trigger?
A trigger fired for each and every record which is inserted, updated, or deleted from the table.
57
What does :old.column_name and :new.column_name indicate?
:old indicates the old value of a column, while :new indicates the new value.
58
What is RAISE_APPLICATION_ERROR?
A procedure to issue user-defined error messages from stored subprograms.
59
What is the error number range for RAISE_APPLICATION_ERROR?
-20000 to -20999.
60
What are the disadvantages of triggers?
* Can execute every time a field is updated, leading to system overhead. * Difficult to view and debug compared to tables and views. * Do not receive parameters.
61
What are the advantages of triggers?
* Event logging and storing information on table access. * Auditing. * Implicit execution compared to explicit calls for procedures.
62
How do you disable a trigger in PL/SQL?
ALTER TRIGGER trigger_name DISABLE;
63
How do you enable a trigger in PL/SQL?
ALTER TRIGGER trigger_name ENABLE;
64
What SQL statement is used to drop a trigger?
DROP TRIGGER trigger_name;
65
Fill in the blank: A trigger is executed __________ in response to a specific data manipulation event.
implicitly
66
What is the purpose of the example trigger that raises an error if more than 1000 books from the same publisher have been added?
To enforce a business rule preventing excessive entries from a single publisher.
67
What SQL statement retrieves the count of accidents grouped by location?
SELECT location, COUNT(*) AS num FROM accident GROUP BY location;
68
When should all accidents from a location be inserted into Table1?
If the number of accidents exceeds 20.
69
What does the INSERT_PROCEDURE do?
Inserts all accidents that occurred in a specified location into Table1.
70
What is the purpose of the cursor in the test procedure?
To iterate over each driver and count accidents to determine where to store their information.
71
What is the significance of the sysdate function in triggers?
It records the current date and time of the DML operation.
72
What happens when the condition in a row level trigger is met?
The specified action (like raising an error) will be executed.
73
What SQL command is used to fetch data from a cursor?
FETCH cursor_name INTO variable_name;