0

I'm new to Oracle APEX and I'm trying to run a simple SQL script in my application to update some data in the database. Here's the script I'm using:

START TRANSACTION;
SELECT MAX(SAL) FROM Employee;
UPDATE Employee SET SAL = SAL * 100;
COMMIT;

However, I'm encountering the following error:

ORA-00900: invalid SQL statement
ORA-06512: at "SYS.WWV_DBMS_SQL_APEX_230100", line 797
ORA-06512: at "SYS.DBMS_SYS_SQL", line 1658
ORA-06512: at "SYS.WWV_DBMS_SQL_APEX_230100", line 782
ORA-06512: at "APEX_230100.WWV_FLOW_DYNAMIC_EXEC", line 2035

I searched on the internet to get a solution. But I couldn't find anything Similler. I want to know why this is'nt working.

1

2 Answers 2

1

If you're running that piece of code in SQL Workshop (looks like you are), note that:

  • there's no start transaction in Oracle (as you were already told; this is not MySQL)

  • commands can be run one-at-a-time. In other words, you can have several statements in the window, but if you just push the Run button, you'll get an error.

    Mark a command (with a mouse, for example) and then run it

    enter image description here

  • finally, commit is useless in this context. If you execute it, you'll get

    Commit statement not applicable. All statements are automatically committed.

Sign up to request clarification or add additional context in comments.

2 Comments

BEGIN DECLARE max_salary NUMBER; BEGIN SELECT MAX(SAL) INTO max_salary FROM Employee; UPDATE Employee SET SAL = SAL * 2; COMMIT; END; END; I just found it on the internet. And it works. I don't know why. I am actually very new to these things
That's a PL/SQL block. Statements you originally posted are pure SQL.
0

START TRANSACTION; is not a valid statement in Oracle.

Transactions are started implicitly with the first statement you use and you cannot explicitly declare a transaction.

Your remaining statements are, individually, valid SQL statements in Oracle's dialect.

fiddle

BEGIN
  DECLARE
    max_salary NUMBER;
  BEGIN
    SELECT MAX(SAL) INTO max_salary FROM Employee;
    UPDATE Employee SET SAL = SAL * 2;
    COMMIT;
  END;
END;

And it works. I don't know why.

If you are using an editor where you can ony run single statements then you have used a PL/SQL anonymous block to wrap multiple SQL statements into a single PL/SQL statement and your editor is running the single PL/SQL statement and passing it to the database which is using the PL/SQL engine to run each of the SQL statements.

Note: You do not need the initial BEGIN and the final END.

1 Comment

BEGIN DECLARE max_salary NUMBER; BEGIN SELECT MAX(SAL) INTO max_salary FROM Employee; UPDATE Employee SET SAL = SAL * 2; COMMIT; END; END; I just found it on the internet. And it works. I don't know why. I am actually very new to these things

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.