Recall & Review
beginner
How do you declare a variable in a PostgreSQL PL/pgSQL block?
You declare a variable in the DECLARE section of a PL/pgSQL block using the syntax: <br>
variable_name data_type;Click to reveal answer
beginner
What is the correct way to assign a value to a variable in PL/pgSQL?
You assign a value using the
:= operator, for example: <br>variable_name := value;Click to reveal answer
beginner
Where in a PL/pgSQL function do you declare variables?
Variables are declared in the
DECLARE section, which comes after the AS or IS keyword and before the BEGIN block.Click to reveal answer
intermediate
Can you declare and assign a variable in one step in PL/pgSQL? If yes, how?
Yes, you can declare and assign a variable in one step like this: <br>
variable_name data_type := initial_value;Click to reveal answer
beginner
What happens if you try to use a variable before declaring it in PL/pgSQL?
You will get a compilation error because PL/pgSQL requires variables to be declared before use.
Click to reveal answer
In PostgreSQL PL/pgSQL, where do you declare variables?
✗ Incorrect
Variables must be declared in the DECLARE section before the BEGIN block.
Which operator is used to assign a value to a variable in PL/pgSQL?
✗ Incorrect
PL/pgSQL uses ':=' for variable assignment.
How do you declare and assign a variable named count of type integer with initial value 10?
✗ Incorrect
The correct syntax is 'count integer := 10;'
What will happen if you use a variable without declaring it first in PL/pgSQL?
✗ Incorrect
PL/pgSQL requires variables to be declared before use, otherwise it causes a compilation error.
Which section comes immediately before the BEGIN block in a PL/pgSQL function?
✗ Incorrect
The DECLARE section is where variables are declared and it comes before BEGIN.
Explain how to declare and assign a variable in a PostgreSQL PL/pgSQL function.
Think about the structure of a PL/pgSQL block and how variables are set up before the main code.
You got /4 concepts.
What errors might occur if you forget to declare a variable before using it in PL/pgSQL?
Consider what happens when the database engine tries to run code with unknown variables.
You got /3 concepts.