m.edmondson
m.edmondson

Reputation: 30922

Select recently inserted record then rollback

I'm back in the over-complicated world of Oracle where I'd like to do the following:

I've created the following code which fails

BEGIN

insert into sometable values (1, 1, 'test', 'test', 1, 'a', 1, 1, 1, 'test', 'test', 'test', 'test', 1);

select *
from sometable
where id = 1;

ROLLBACK;

END;

The error message:

ORA-06550: line 5, column 1:
PLS-00428: an INTO clause is expected in this SELECT statement

I'm sure the problem is obvious, but I've checked the docs and can't gain any wisdom from them. Any pointers would be appreciated.

Upvotes: 1

Views: 192

Answers (2)

jva
jva

Reputation: 2807

Just execute your code from SQL*Plus without BEGIN..END;

insert into sometable values (1, 1, 'test', 'test', 1, 'a', 1, 1, 1, 'test', 'test', 'test', 'test', 1);

select *
from sometable
where id = 1;

ROLLBACK;

Upvotes: 3

hkutluay
hkutluay

Reputation: 6944

You have to put selected values to an variable like

DECLARE 
  V_COUNT NUMBER;
BEGIN

insert into sometable values (1, 1, 'test', 'test', 1, 'a', 1, 1, 1, 'test', 'test', 'test', 'test', 1);

select COUNT(1) INTO V_COUNT 
from sometable
where id = 1;

ROLLBACK;

END;

Upvotes: 3

Related Questions