PL/SQL Flashcards

1
Q

What is the basic syntax for a block?

A

DECLARE

BEGIN

EXCEPTION

END

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

What are ‘Anonymous Blocks’?

A

When you click the run button you get ‘compile runs’

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

What are ‘Named Blocks’

A

When you click the run button you get ‘compiles’

P code is generated

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

Declare variable v_foo and assign it the value 7

A

v_foo NUMBER := 7

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

Assign the number of teachers in the COSC department into the v_cosc variable from the teachers table

A

SELECT COUNT(*)
INTO v_cosc
FROM teachers
WHERE dept = ‘COSC’;

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

What are the 2 errors you may get when using a SELECT … INTO statement?

A
  • NO_DATA_FOUND
    Get when 0 rows are returned
  • TOO_MANY_ROWS
    Get when more than 1 row is returned
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Write this as PL/SQL

If(grade > 50) {
   System.out.println("Pass");
} else if (grade > 0) {
   System.out.println("Fail");
} else {
   System.out.printlnt("W");
}
A

IF grade > 50 THEN
dbms_output.put_line(‘Pass’);

ELSIF grade > 0 THEN
dbms_output.put_line(‘Fail’);
ELSE
dbms_output.put_line(‘W’);

END IF;

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

Write this as PL/SQL

while (i < 5) {
System.out.println(i);
i++;
}

A

WHILE i < 5 LOOP
System.out.println(i)
i := i + 1;
END LOOP;

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

Declare a varaible v_name to be the same data type as name from the Employees table

A

v_name Employees.name%TYPE;

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

Write an exception when theres SELECT … INTO returns no rows to print out Oops!

A

EXCEPTION
WHEN NO_DATA_FOUND THEN dbms_output.put_line(‘Oops!’);
END;

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

What are bind variables?

A

Variables created in SQL*Plus and that can be referenced in PL/SQL

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

Declare a bind foo variable to equal 7

A

:foo := 7;

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

Print out ‘Hello World’ in PL/SQL. Include line that enables printing

A

SET SERVEROUTPUT ON

dbms_output.put_line(‘Hello World’);

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