Oracle dbms_output.put 和dbms_output.put_line 的区别

油区波斯猫 2011-12-31 06:03:35
如下表
学生信息tblemp
id name gender
101 张三 1
201 李四 2
301 王五
输出性别信息时将数字转换为汉字,如果是1输出男、2输出女。
declare
cursor c is select * from tblemp;
begin
for i in c loop
dbms_output.put_line(i.id||i.name);//问题出现在这一行 输出结果如下:
if(i.gender =1) then dbms_output.put_line('男'); 101张三
elsif (i.gender=2) then dbms_output.put_line('女'); 男
end if; 201李四
end loop; 女
end; 301王五
begin
dbms_output.put_line('213');
end;

如果把有问题的那一行换成 dbms_output.put(i.id||i.name);
输出结果则变为:
101张三男
201李四女



自己写的测试语句:
begin
dbms_output.put_line('213');
end;
结果输出213

begin
dbms_output.put('213');
end;
结果什么也不输出。


本人所用环境为PLSQL Developer oracle 11g
...全文
1057 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
jinzhiyang 2012-01-04
  • 打赏
  • 举报
回复
dbms.output.put() 是不换行输出

dbms.output.put_line() 是换行输出
我心飞翔 2012-01-01
  • 打赏
  • 举报
回复
原因如下:
当使用DBMS_OUTPUT.PUT_LINE()时,会在数据行尾加一个换行符,此时会将缓冲的内容输出。

当使用DBMS_OUTPUT.PUT()时,必须手动加入一个换行符(通过调用NEW_LINE(),GET_LINE(),GET_LINES())
此时才会将缓冲区内容输出。

实测步骤:

-- Created on 2012-01-01 by ADMINISTRATOR
declare
-- Local variables here
i integer;
begin
dbms_output.put('213');
dbms_output.new_line();

end;


这样就可以输出213了。
iihero_ 2011-12-31
  • 打赏
  • 举报
回复
set serveroutpput on
之后,再试试put
油区波斯猫 2011-12-31
  • 打赏
  • 举报
回复
在线等答案。等解释啊。。。

17,377

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 基础和管理
社区管理员
  • 基础和管理社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧