小弟刚刚接触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的。谢谢

解决方案 »

  1.   

    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 基础与提高
      

  2.   

    推荐书籍:我收藏的CHM格式的http://download.csdn.net/source/1969686
      

  3.   

    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判断后才知道要查什么呀。
      

  4.   

    select count(*) into i from ISI_Registry where name='S';
    if i=0 then
      insert into xxx
    end if;
      

  5.   

    如果我的需求是:如果表中有这个值就xx,没有就yy,这样的语句怎么写?
    因为如果没有这个值的话,Oracle抛出了no_data_found的异常呀。
      

  6.   

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

  7.   

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