0

In SQL Server, multiple statements in SSMS can be performed. In Oracle (using toad), I don't know why I receive certain errors doing the same thing. For example, I assume an Oracle requirement is to place them in a block, but I still get the following:

DECLARE
  v_datetime TIMESTAMP := SYSDATE;
BEGIN
  insert into sometable_log values (v_datetime, 'this is a test ',1);
  select * from sometable_log where event_dt = v_datetime;
END;

produces:

[Error] Execution (5: 1): ORA-06550: line 4, column 1: PLS-00428: an INTO clause is expected in this SELECT statement

Why would I need to use an into clause? Can someone please help me understand what this is?

Thank you!

Littlefoot
  • 131,892
  • 15
  • 35
  • 57
ssou
  • 21
  • 3
  • In PL/SQL, you need an `into` clause so you can capture the value for further processing. If you want to return a ref cursor implicitly to the caller from a PL/SQL block, see https://stackoverflow.com/a/40360471/230471 – William Robertson Jul 17 '18 at 21:19
  • If you just want to run two commands one after another in Toad rather than coding anything in PL/SQL, then consult the Toad documentation (I don't use it). – William Robertson Jul 17 '18 at 21:22
  • It doesn't seem like you really do want a PL/SQL block. It would probably be more useful to say what errors you get running the plain SQL statements [Maybe this?](https://stackoverflow.com/q/23029246/266304) – Alex Poole Jul 17 '18 at 21:23

1 Answers1

0

When executing the block of code, Oracle expects that the select command should have some code-like effect. That's why it wants you to add the into clause.

To do what you need, just move the select statement outside of the PL/SQL begin/end block.

Mark Harrison
  • 297,451
  • 125
  • 333
  • 465
  • Thank you, Mark. If I do that, then it will not recognize v_datetime variable. So, is the difference that Oracle doesn't work in batch , as does Sql Server? It seems that there is a fundamental difference between the way PL/SQL and Sql Server works, and that looks to me that PLSQL handles only one statement at a time in batch fashion. Am I correct? – ssou Jul 18 '18 at 14:19