在匿名块内显示选择结果
我正在尝试调试过程中的 SELECT,并且我正在尝试使用匿名块。我希望 SQL Developer 简单地返回最后一个 SELECT 语句,但出现错误:
ORA-06550: line 21, column 5:
PLS-00428: an INTO clause is expected in this SELECT statement
在过程内部,我有一个用于该选择的 INTO,但是有没有一种简单的方法可以让我简单地获取最后一个 SELECT 语句的结果我的调试?我使用匿名块和变量,以便代码与过程中的实际内容尽可能相似,这样我就不必更改代码
set serveroutput on format wrapped;
DECLARE
p_cd_doc_type number;
p_dc_doc_code varchar2(200);
p_dt_base date;
p_qt_days number;
p_vl_mov_total number;
p_qt_transac number;
v_dt_max date;
v_dt_min date;
begin
p_dt_base := sysdate;
p_qt_days := 1;
v_dt_max := trunc(p_dt_base) + 1;
v_dt_min := v_dt_max - p_qt_days;
p_vl_mov_total := 0;
DBMS_OUTPUT.PUT_LINE('v_dt_max = ' || v_dt_max);
DBMS_OUTPUT.PUT_LINE('v_dt_min = ' || v_dt_min);
select *
from tb_cad_cliente a join tb_trn_transacao b
on a.cd_cliente = b.cd_cliente
where a.cd_doc_type = p_cd_doc_type
and a.dc_doc_code = p_dc_doc_code
and b.dt_row between v_dt_min and v_dt_max
and b.cd_status = 3;
end;
I'm trying to debug a SELECT inside a procedure, and I'm trying to this using a anonymous block. I would like that SQL Developer simply return the last SELECT statement, but I get the error:
ORA-06550: line 21, column 5:
PLS-00428: an INTO clause is expected in this SELECT statement
Inside the procedure, I have an INTO for that select, but is there a simple way that I can simply get the results for the last SELECT statement for my debugging? I'm using anonymous block and variables so that the code is as similar as possible from what's actually inside the procedure, so that I don't have to change the code
set serveroutput on format wrapped;
DECLARE
p_cd_doc_type number;
p_dc_doc_code varchar2(200);
p_dt_base date;
p_qt_days number;
p_vl_mov_total number;
p_qt_transac number;
v_dt_max date;
v_dt_min date;
begin
p_dt_base := sysdate;
p_qt_days := 1;
v_dt_max := trunc(p_dt_base) + 1;
v_dt_min := v_dt_max - p_qt_days;
p_vl_mov_total := 0;
DBMS_OUTPUT.PUT_LINE('v_dt_max = ' || v_dt_max);
DBMS_OUTPUT.PUT_LINE('v_dt_min = ' || v_dt_min);
select *
from tb_cad_cliente a join tb_trn_transacao b
on a.cd_cliente = b.cd_cliente
where a.cd_doc_type = p_cd_doc_type
and a.dc_doc_code = p_dc_doc_code
and b.dt_row between v_dt_min and v_dt_max
and b.cd_status = 3;
end;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您可以尝试使用此方法轻松打印结果:
You can try with this, to print your result easily:
适用于 Oracle 12c 或更高版本
For oracle 12c or higher
为了返回选择的值,需要将其选择到容器(参考游标或 REF CURSOR)中。在您的声明中,您应该包含
ref_cursor_out SYS_REFCURSOR;
并将您的选择更改为:
在 SQL Developer 中,有一个选项(我是 Toad 用户,所以我忘记了 SD 中的位置),它告诉 IDE 将结果集加载到网格中进行查看。
[编辑:根据 @DCookie 的评论,感谢您的关注!]
In order to return the value of the select it needs to be selected into a container (a reference cursor or REF CURSOR). In your Declare you should include
ref_cursor_out SYS_REFCURSOR;
and change your select to:
In SQL Developer there is an option (I am a Toad user, so I forget where in SD) that tells the IDE to load the result set into a grid to view.
[edit: per comment from @DCookie, Thanks for the catch!]
错误
据我所知,无论您使用什么工具来调试,pl/sql 块(匿名和命名)对于PL/SQL 编译器<应该是有效 /强>。
事实上,您的块对于 PL/SQL 编译器来说无效,并且您的错误会告诉您,并且是从 PL/SQL 编译器中输出的> 并且不是来自Sql Developer!
并
为什么错误
当出现 Pl/sql 错误时,您只能选择在代码和手册中进行调查:
静态 SQL 语句中的名称解析
PS:
路线始终相同:
如何提问
所有“预言机”都在这里:
<一个href="http://download.oracle.com/docs/cd/E11882_01/doc.112/e12152/toc.htm" rel="nofollow">Sql 开发人员
Error
For what I know, whatever tool you use to debug, the pl/sql blocks(anonymous and named) should be valid for the PL/SQL compiler.
The fact is that your block doesn't result valid for the PL/SQL compiler, and your error is there to tell you, and is coming out from the PL/SQL compiler and not from the Sql Developer!
and
Why error
When an Pl/sql error appear, you only have the choice to investigate in the code and in the manuals:
Resolution of names in static SQL statements
PS:
The route is always the same:
How to ask
All the "oracles" are here:
Sql Developer
我最近从 MSSQL 更改为 PLSQL,并且我错过了用于分析目的的过程中以表格形式返回的值。我编写了简单的动态查询,分两步返回表。也许有人使用它:
I recently changed from MSSQL to PLSQL and I miss the return values as tables from procedures for analytical purposes. I wrote simply dynamic query that return table by two steps. Maybe someone use it: