oracle SQL中完成的匿名块
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22391973/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
anonymous block completed in oracle SQL
提问by user3357925
Whilst trying to create a query cursor as follows:
在尝试创建查询游标时,如下所示:
DECLARE CURSOR Query1
IS
SELECT * FROM RACE
WHERE Race_Time='22-SEP-14 12.00.00.000000000';
BEGIN
OPEN Query1;
END;
I get the following error. anonymous block completed. Does anyone know how to fix this? I tried setting the 'SET SERVEROUTPUT ON;' before the declare but this did not seem to fix the error. Thanks in advance!
我收到以下错误。匿名块完成。有谁知道如何解决这一问题?我尝试设置“SET SERVEROUTPUT ON;” 在声明之前,但这似乎并没有解决错误。提前致谢!
回答by Amr Hamza
It seems that dbms_output is turned off
似乎 dbms_output 已关闭
you can see you out put if you put SET SERVEROUTPUT ON;
in the beginning of your script.
如果你把你放在SET SERVEROUTPUT ON;
脚本的开头,你就可以看到你了。
or you can view dbms_output window (View then DBMS Output) then press the "+" at the top of the Dbms Output window and then select an open database
或者您可以查看 dbms_output 窗口(查看然后 DBMS 输出)然后按 Dbms 输出窗口顶部的“+”,然后选择一个打开的数据库
回答by PETTA
"anonymous block completed" means your PL/SQL code was successfully executed. To Display: try using a output statement...
“匿名块已完成”表示您的 PL/SQL 代码已成功执行。显示:尝试使用输出语句...
For example:
例如:
BEGIN
dbms_output.put_line ('Hello, world!');
END;
回答by Justin Cave
If you want to control the process in PL/SQL, you could do something like
如果你想在 PL/SQL 中控制进程,你可以做类似的事情
DECLARE
l_race_rec race%rowtype;
CURSOR Query1
IS
SELECT *
FROM RACE
WHERE Race_Time='22-SEP-14 12.00.00.000000000';
BEGIN
OPEN Query1;
LOOP
FETCH query1 INTO l_race_rec;
EXIT WHEN query1%notfound;
dbms_output.put_line( l_race_rec.column1 || ' ' || l_race_rec.column2 || ... || l_race_rec.columnN );
END LOOP;
CLOSE Query1;
END;
Unless your assignment requires the use of explicit cursors, though, implicit cursors are likely easier to use
但是,除非您的赋值需要使用显式游标,否则隐式游标可能更易于使用
BEGIN
FOR x IN( SELECT *
FROM RACE
WHERE Race_Time='22-SEP-14 12.00.00.000000000')
LOOP
dbms_output.put_line( x.column1 || ' ' || x.column2 || ... || x.columnN );
END LOOP;
END;
If you are using SQL*Plus, you can also do something like
如果您使用的是 SQL*Plus,您还可以执行类似的操作
VAR rc REFCURSOR;
BEGIN
OPEN :rc
FOR SELECT *
FROM race
WHERE race_time = '22-SEP-14 12.00.00.000000000';
END;
PRINT rc
If race_time
is really a timestamp
, you should really be comparing a timestamp
with another timestamp
rather than comparing a timestamp
to a string. Use explicit conversion with an explicit format mask to avoid errors due to different sessions having different NLS settings
如果race_time
真的是 a timestamp
,你真的应该将 atimestamp
与另一个进行比较,timestamp
而不是将 atimestamp
与字符串进行比较。使用带有显式格式掩码的显式转换来避免由于不同会话具有不同 NLS 设置而导致的错误
WHERE race_time = to_timestamp( '22-SEP-14 12.00.00.000000000',
'DD-MON-RR HH24:MI:SS.FF9' )
Of course, I'm not sure why you would use a timestamp
in the first place here-- it seems unlikely that you really know the nanosecond at which a race started.
当然,我不确定您为什么首先在这里使用 a -timestamp
您似乎不太可能真正知道比赛开始的纳秒。