【问题标题】:Warning: compiled but with compilation errors oracle compile pl/sql error警告:已编译但有编译错误 oracle compile pl/sql error
【发布时间】:2014-02-14 01:09:17
【问题描述】:

您好,我是这里的新手,也是 oracle pl/sql 块的新手,这是编译它的代码返回警告:已编译但存在编译错误

 create or replace function func_o12 return varchar2
       is
         declare nn varchar2(20);
     begin
        select
              case substr(1234,1,3)
                  when '134' then '1234 is a match'
                  when '1235' then '1235 is a match'
                  when concat('1','23') then concat('1','23')||' is a match'
              else 'no match'
              end
         into :nn  
           from dual;
       return :nn;
      end;

【问题讨论】:

  • 在这种情况下您不需要使用查询 - 只需直接分配 nn,例如nn := case ... end;

标签: oracle plsql


【解决方案1】:

您不需要声明或绑定标记:

create or replace function func_o12 return varchar2
       is
         nn varchar2(20);
     begin
        select
              case substr(1234,1,3)
                  when '134' then '1234 is a match'
                  when '1235' then '1235 is a match'
                  when concat('1','23') then concat('1','23')||' is a match'
              else 'no match'
              end
         into nn  
           from dual;
       return nn;
      end;

【讨论】:

  • 感谢 Mr.Kite 在以下查询的哪个场景中将使用 :w_date 运行,因为此查询语法正确,但我不知道在哪个场景中查询会成功运行? select a.* from hr.employees a where to_char(a.hire_date,'yyyy/mm/dd hh:mm:ss') =:w_date;
  • 我怀疑你想指定 hh:mm:ss 作为雇佣日期,可能是这样的::w_date := '2014/01/16';select a.* from hr.employees a where to_char(a.hire_date,'yyyy/mm/dd') = :w_date;
  • 我在询问变量 :w_date 特别是符号 : ?如果我想在 where employee_id=:hereicanSubstite; 这样的查询中进行替换变量,但我想要这个使用符号:变量名我有一个替代方案,即 & 符号替换。
  • : 表示它是一个绑定变量,是一种替换。对于您所描述的情况,使用它是正确的。我不相信在 SQL*Plus 之外可以进行替换。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-10-26
  • 2012-02-09
  • 1970-01-01
  • 2019-08-08
  • 2018-11-03
  • 2010-12-12
  • 2018-09-16
相关资源
最近更新 更多