1

我回到了过于复杂的甲骨文世界,我想做以下事情:

  • 在数据库中插入一条记录
  • 再次选择记录
  • 回滚一切

我创建了以下失败的代码

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;

错误信息:

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

我确信问题很明显,但我已经检查了文档并且无法从中获得任何智慧。任何指针将不胜感激。

4

2 回答 2

3

您必须将选定的值放入变量中,例如

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;
于 2012-04-26T13:32:20.153 回答
3

只需从 SQL*Plus 执行您的代码,无需 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;
于 2012-04-26T13:55:09.697 回答