oracleplsql

PL/SQL block throwing a "variables not bound" error despite seemingly no errors in the code


I've been looking at my code for a while and searching for any syntax errors that may be causing the problem but I really can't find it anywhere. I'm running the script in Oracle Autonomous Database and tried it on the Live SQL but it won't run on both.

Code is:

VARIABLE b_basic_percent NUMBER
VARIABLE b_pf_percent NUMBER

DECLARE
    v_today DATE := SYSDATE;
    v_tomorrow v_today%TYPE;
BEGIN
    v_tomorrow := v_today + 1;
    DBMS_OUTPUT.PUT_LINE('Hello World');
    DBMS_OUTPUT.PUT_LINE('TODAY IS : ' || v_today);
    DBMS_OUTPUT.PUT_LINE('TOMORROW IS ' || v_tomorrow);

    :b_basic_percent := 45;
    :b_pf_percent := 12;
END;
/

PRINT b_basic_percent
PRINT b_pf_percent

I've tried removing the whitespaces between the ":=" and values but I don't think it's significant.


Solution

  • I copied your code, as is, to our web interface for Autonomous in Oracle Cloud...it works.

    enter image description here

    It's not working in LiveSQL because the VARIABLE and PRINT commands aren't supported. However, we're about to update LiveSQL to use the same technology as I show in the above screenshot, so it will work there as well, soon.

    Please update your question to show more details, like the actual errors/problems encountered when running your script.