Complete the code to declare a variable in PL/pgSQL.
DECLARE my_var [1]; In PL/pgSQL, variables are declared using the variable_name TYPE; syntax inside the DECLARE block. Here, use INTEGER.
Complete the code to start a PL/pgSQL function.
CREATE FUNCTION add_numbers(a INTEGER, b INTEGER) RETURNS INTEGER LANGUAGE plpgsql AS $$ BEGIN RETURN a [1] b; END; $$;The function adds two numbers, so the operator should be +.
Fix the error in the IF statement condition.
IF total [1] 100 THEN RAISE NOTICE 'Total is over 100'; END IF;
In PL/pgSQL, to check if total is greater than 100, use the > operator. The == operator is not valid in SQL.
Fill both blanks to complete the loop that sums numbers from 1 to 5.
DECLARE total INTEGER := 0; BEGIN FOR i IN [1] LOOP total := total + i; END LOOP; RETURN [2]; END;
The loop runs from 1 to 5 using 1..5. The function returns the total sum.
Fill all three blanks to create a conditional that raises a notice if count is zero.
IF [1] = [2] THEN RAISE NOTICE '[3] is zero'; END IF;
The condition checks if count equals zero, then raises a notice saying 'count is zero'.
