Oracel No Data Found Error

灰太狼 2010-11-01 11:51:35
小弟刚刚接触Oracel开发,目前遇到四个问题,请大虾帮帮忙。
1.运行下面语句时PLSQL Developer报no data found的错误,请问如何解决:
declare
i integer;
begin
select registrykey into i from ISI_Registry where name='S';
end;

2.另外,小弟还有一个问题,为什么Oracle在if语句里面不能写select语句呢?比如
if i is null then
select registrykey from ISI_Registry
end if;
就会报ora-06550:an into clause is expected in this select statement的错误。难道if里面只能写insert,update或是into语句?

3.在oracle里面如何打印一个变量的值呢?比如我想打印变量i的值,在SQL Server里面只需要写print i; 或是 select i;
就可以,但是oracel里面却不行。


4.小弟初学oracle,请各位大虾推荐几本比较初级的书,先不要oracle配置管理或是优化方面的,只要介绍oracle语法或是sql的就可以。最好是chm的。谢谢
...全文
148 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
gelyon 2010-11-01
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 tjvictor 的回复:]

明白了。看来oracle与sql server还是有很多不同的地方,以后要多多学习,常混这个论坛版了。
[/Quote]

欢迎新朋友
灰太狼 2010-11-01
  • 打赏
  • 举报
回复
明白了。看来oracle与sql server还是有很多不同的地方,以后要多多学习,常混这个论坛版了。
gelyon 2010-11-01
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 tjvictor 的回复:]

1.我的需求是
select registrykey into i from ISI_Registry where name='S';
if i is null then
insert into xxx
end if;
但是在select时就报错了,如果我想实现上面的逻辑,那么oracle语句应该怎么写?
2.如果if里面不能写select,那么有没有什么替代方法来实现呢。因为……
[/Quote]


--用异常捕获形式来做:
begin
select registrykey into i from ISI_Registry where name='S';
exception when no_data_found then
insert into xxx...;
end;

灰太狼 2010-11-01
  • 打赏
  • 举报
回复
如果我的需求是:如果表中有这个值就xx,没有就yy,这样的语句怎么写?
因为如果没有这个值的话,Oracle抛出了no_data_found的异常呀。
minitoy 2010-11-01
  • 打赏
  • 举报
回复
select count(*) into i from ISI_Registry where name='S';
if i=0 then
insert into xxx
end if;
灰太狼 2010-11-01
  • 打赏
  • 举报
回复
1.我的需求是
select registrykey into i from ISI_Registry where name='S';
if i is null then
insert into xxx
end if;
但是在select时就报错了,如果我想实现上面的逻辑,那么oracle语句应该怎么写?
2.如果if里面不能写select,那么有没有什么替代方法来实现呢。因为有时必须要在if判断后才知道要查什么呀。
gelyon 2010-11-01
  • 打赏
  • 举报
回复
推荐书籍:我收藏的CHM格式的http://download.csdn.net/source/1969686
gelyon 2010-11-01
  • 打赏
  • 举报
回复


1、说明你ISI_Registry表里没有name='S'的记录,Oracle抛出了no_data_found的异常
2、PLSQL里是不能直接写select ...FROM ...的,必须是select ..INTO 变量 FROM ....
3、打印变量 Dbms_Output.put_line(变量); 前提是在SQLPLUS中先设置 SET serveroutput ON 这样才能打印显示出来。
4、Oracle书籍:
中文书籍:
基础的:精通Oracle 10g PL/SQL编程
中高级的:Oracle 9i&10g编程艺术:深入数据库体系结构、Oracle专家高级编程

英文书籍:
基础的:PLSQL_UserGuide、plsql reference、
中级的:OReilly SQL Cookbook
高级的:Oracle Database 11g DBA、performance turning guide

。。。。

基础的:
Oracle 10g 入门与提高
Oracle 11g 基础与提高

17,089

社区成员

发帖
与我相关
我的任务
社区描述
Oracle开发相关技术讨论
社区管理员
  • 开发
  • Lucifer三思而后行
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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