Bird
0
0

You want to declare two variables a and b as integers, assign a the value 4, and then assign b the value of a multiplied by 3. Which of the following PL/pgSQL code snippets correctly does this?

hard📝 Application Q15 of 15
PostgreSQL - PL/pgSQL Fundamentals
You want to declare two variables a and b as integers, assign a the value 4, and then assign b the value of a multiplied by 3. Which of the following PL/pgSQL code snippets correctly does this?
ADECLARE b integer := a * 3; a integer := 4; BEGIN NULL; END;
BDECLARE a integer; b integer; BEGIN a = 4; b = a * 3; END;
CDECLARE a integer; b integer; BEGIN a := 4; b := a * 3; END;
DDECLARE a integer := 4; b integer; BEGIN b = a * 3; END;
Step-by-Step Solution
Solution:
  1. Step 1: Check variable declaration and initialization

    DECLARE a integer; b integer; BEGIN a := 4; b := a * 3; END; declares both variables without initial values, then assigns values inside the BEGIN block using correct assignment operator :=.
  2. Step 2: Verify assignment and calculation

    It assigns a := 4; and then b := a * 3;, which correctly sets b to 12.
  3. Final Answer:

    correctly declares and assigns variables with := -> Option C
  4. Quick Check:

    Declare first, assign with := inside BEGIN [OK]
Quick Trick: Declare variables first, assign values inside BEGIN with := [OK]
Common Mistakes:
  • Using = instead of :=
  • Assigning values during declaration with expressions
  • Missing BEGIN block for assignments

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes