如何使用Sql Developer查看刚刚在脚本中修改的表

时间:2015-06-05 23:32:48

标签: sql oracle select plsql oracle-sqldeveloper

我在sql developer中有这个块:

begin
 delete from temp;
 insert into temp values (1);
 dbms_output.put_line('Done');
end;

如果我点击F5,脚本运行正常。该表更新为值1,“脚本输出”选项卡显示为“完成”。

但是,我想在执行块后自动可视化我刚刚在“结果”选项卡中修改的表。那可能吗?怎么样? 任何帮助表示赞赏。谢谢。

3 个答案:

答案 0 :(得分:2)

无需任何匿名 PL / SQL 块。只需将 SQL 语句作为脚本运行,

echo JHtml::_('content.prepare', '{loadposition position-22}');

将上述三个语句放在 SQL Developer 工作表中,然后按 F5 作为脚本运行,请参阅脚本输出选项卡中的输出。您最后必须 COMMIT 才能永久更改表格。

您无法在PL / SQL中执行delete from temp; insert into temp values (1); select * from temp; ,因为它是纯SQL语句。 PL / SQL需要一个INTO子句。在纯SQL中你也可以在PL / SQL中做同样的事情。

但是,如果你真的想在select * from table块中执行它,那么将SELECT语句放在PL / SQL块之外。不要合并PL / SQL和SQL。

BEGIN-END

答案 1 :(得分:1)

您可以使用CURSOR:

declare 
a temp.id%type; --name column in your table
cursor c1 is
select id from temp;
begin
  delete from temp;
  insert into temp values (1);
  open c1;
  loop 
  fetch c1 into a;
  dbms_output.put_line (a);
  exit when c1%notfound;
  end loop;
  CLOSE C1;
end;

答案 2 :(得分:1)

当表填满并且您不使用删除时,以下内容也可以使用。

declare 
    a temp.id%type; --name column in your table
begin
    -- delete from temp;
    insert into temp values (1)
    returning id into a;
    dbms_output.put_line (a);
    dbms_output.put_line('Done');
end;