create   or   replace   procedure   PROC_HR_ISNEWUSER(vAccountName_in     In   Varchar2  ,   
    cur_result_out   Out   search_result)  Is   
    str_accountName   Varchar2(50);   
    str_sql   Varchar2(200);    
  Begin   
      If   vAccountName_in  is Not Null   Then   
            str_accountName   :=   'and   customercode='   ||   vAccountName_in;  
                        
      str_sql   :=   'select  customername   from   t_mc_customer  where   1=1'
      ||   str_accountName   ;   
        end if ;
      Open   cur_result_out   For   str_sql;   
       
  end   PROC_HR_ISNEWUSER;  
ORACLE的代码上面主要的意思是``首先判断`vAccountName_in参数是否有值,如果有值就将( and customercode=vAccountName_in)付给
变量str_accountName,然后传到查询(str_sql)中进行组合,打开游标,将查询结果customername 显示出来.
现在有个问题,就是运行时显示必须声明标识符 search_result  ???  这个错,我不知道如何修改.
还有麻烦帮我看看,这样写还有什么地方写错了``(ORACLE)```

解决方案 »

  1.   

    ORACLE
    幫頂
    建議到ORACLE版問
      

  2.   

    create or replace package pk_type is
    type search_result is ref cursor;
    end;
    create or replace procedure PROC_HR_ISNEWUSER(vAccountName_in In Varchar2,
                                                  cur_result_out  Out pk_type.search_result) Is
      str_accountName Varchar2(50);
      str_sql         Varchar2(200);
    Begin
      If vAccountName_in is Not Null Then
        str_accountName := 'and  customercode=' || vAccountName_in;    str_sql := 'select  customername  from  t_mc_customer  where  1=1' ||
                   str_accountName;
      end if;
      Open cur_result_out For str_sql;end PROC_HR_ISNEWUSER;
      

  3.   

    create or replace procedure PROC_HR_ISNEWUSER(vAccountName_in In Varchar2,
                                                  cur_result_out  Out pk_type.search_result) Is
      str_accountName Varchar2(50);
      str_sql         Varchar2(200);
      sqlinfo varchar2(200);
      sqlcode1 varchar2(200);
    Begin
      If vAccountName_in is Not Null Then
        str_accountName := 'and  customercode=' || vAccountName_in;    str_sql := 'select  customername  from  t_mc_customer  where  1=1 ' ||
                   str_accountName;
      end if;
      Open cur_result_out For str_sql;
      exception
      when others then
       sqlinfo:=sqlerrm;
       sqlcode1:=substr(sqlcode,1,200);
      open cur_result_out for
     
      select sqlcode1,sqlinfo from dual;
      end PROC_HR_ISNEWUSER;
      

  4.   


    create  or  replace  procedure  PROC_HR_ISNEWUSER(vAccountName_in    In  Varchar2  ,  
        cur_result_out  Out  SYS_REFCURSOR)  Is  
        str_accountName  Varchar2(50);  
        str_sql  Varchar2(200);    
      Begin  
          If  vAccountName_in  is Not Null  Then  
                str_accountName  :=  'and  customercode='  ||  vAccountName_in;  
                            
          str_sql  :=  'select  customername  from  t_mc_customer  where  1=1' 
          ||  str_accountName  ;  
            end if ; 
          Open  cur_result_out  For  str_sql;  
          
      end  PROC_HR_ISNEWUSER;  
      

  5.   

    '后少个空格,还少两个单引号
    str_accountName  :=  'and  customercode='  ||  vAccountName_in改为---->  str_accountName := ' and customercode=''' || vAccountName_in||'''';
      

  6.   

    cur_result_out  Out  search_result  search_result是什么类型?