以下程序中的错误是什么?

时间:2014-01-30 20:01:08

标签: plsql oracle10g syntax-error

这是我正在编写的PL / SQL程序,用于将字符串转换为ascii值,但是出现以下错误:

ORA-06550: line 12, column 5:
PLS-00113: END identifier 'FUNCTION' must match 'ENCODE12' at line 3, column 10
ORA-06550: line 12, column 13:
PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following: begin function package pragma procedure form
  1. 声明
  2. buff number(3):= 0;
  3. function Encode12(string varchar2)
  4. 我是新的PL / SQL编程。预先感谢。

    declare
    buff number(3):=0;
    function Encode12(string varchar2)
    return varchar2 is 
    encodedString varchar2(50):='';
    Begin
    for i in 1 .. length(string) loop 
    buff:=ascii(substr(string,i,1));
    concat(encodedString,buff);
    end loop;
    return encodedString;
    end function;
    

1 个答案:

答案 0 :(得分:1)

尝试:

create or replace function Encode12(string varchar2 )
return varchar2 is 
  encodedString varchar2(50):='';
  buff number(3):=0;
Begin
  for i in 1 .. length(string) loop 
     buff:=ascii(substr(string,i,1));
     -- concat(encodedString,buff);
     encodedString := encodedString || buff;
  end loop;
  return encodedString;
end;
/

Oracle中没有concat过程,必须使用赋值和连接运算符:

encodedString := encodedString || buff;

请看一下这个演示:http://sqlfiddle.com/#!4/21309/1