2013-07-07 238 views
0

我不知道该怎么做。我写了一个函数,没有出现任何错误,但后来当我运行的代码我:功能上的ORA-06550,PLS-00103,ORA-06512

ORA-0650: line 3, column 14: 

PLS-00103: Encountered the symbol "/" when expecting one of the following: 

:= . (@ % ; not null range default character 

ORA-06512: at line 58 

Vendor code 6550 

这是函数:

create or replace 
FUNCTION "GET_MUSICIAN_FUN" 
( 
i_mus_id IN musicians.id%type 
) 
RETURN musicians%ROWTYPE 
AS 
o_mus_rec musicians%ROWTYPE; 
BEGIN 
    SELECT m.id, m.first_name, m.last_name, m.born, m.died , m.picture_path, m.bio 
    INTO o_mus_rec 
    FROM musicians m 
    WHERE id = i_mus_id; 
    RETURN o_mus_rec; 
EXCEPTION 
    WHEN NO_DATA_FOUND THEN 
    RAISE_APPLICATION_ERROR(-20005, 'Found nothing.'); 
    WHEN TOO_MANY_ROWS THEN 
    RAISE_APPLICATION_ERROR(-20006, 'Found too many.'); 
    WHEN OTHERS THEN 
    RAISE_APPLICATION_ERROR(-20007, 'Cannot get musician.'); 
END GET_MUSICIAN_FUN; 

编辑:

当我把它带:

declare 
result musicians%rowtype; 
begin 
result := get_musician_fun(53); 
end; 
/

我得到:"anonymous block completed"

但是从PHP调用它时:

$con = oci_connect("yoni", "yoni", "//localhost/xe"); 
$s = oci_parse($con, "begin :rc := GET_MUSICIAN_FUN(53); end;"); 
$rc = oci_new_cursor($con); 
oci_bind_by_name($s, ":rc", $rc, -1, OCI_B_CURSOR); 
oci_execute($s); // line 41 
oci_execute($rc, OCI_DEFAULT); 
oci_fetch_all($rc, $res, null, -1, OCI_FETCHSTATEMENT_BY_ROW); // line 43 
return $res; 

我得到:

Warning 
: oci_execute(): ORA-06550: line 1, column 14: 
PLS-00382: expression is of wrong type 
ORA-06550: line 1, column 7: 
PL/SQL: Statement ignored in... on line 41 

Warning 
: oci_fetch_all(): ORA-24338: statement handle not executed in... on line 43 
+0

来自SQL开发人员。我也从PHP脚本中调用了该函数,并给出了相同的错误。 –

+0

在SQL开发人员中,我使用Ctrl-F10(运行)。我怎样才能看到底层代码? –

+0

@YoniLevy:我不知道'PHP',但是看着你的错误声明,我认为你没有在PHP端正确地获取它,我想你需要在php中声明一个你的表音乐家的变量并迭代它。找到链接希望它有帮助。[链接](http://stackoverflow.com/questions/14055397/recover-a-table-of-varchar2-from-a-pl-sql-function-in-php) –

回答

0

我不是PHP的专家,但你去获取一个Oracle行对象到PHP。 rowtype仅在oracle pl/sql代码中使用。

尝试这种方法

create or replace function get_musician_fun(i_mus_id in musicians.id%type) 
return varchar2 
as 
    musician_row varchar2(32000); 
begin 
    select m.id||','|| m.first_name||','|| m.last_name||','|| m.born||','|| m.died ||','|| m.picture_path||','|| m.bio 
    into o_mus_rec 
    from musicians m 
    where id = i_mus_id; 
    return musician_row; 
exception 
    when no_data_found then 
    raise_application_error(-20005,'found nothing.'); 
    when too_many_rows then 
    raise_application_error(-20006,'found too many.'); 
    when others then 
    raise_application_error(-20007,'cannot get musician.'); 
end get_musician_fun; 

,并在你的PHP像CSV分裂的结果。

  • 看看修改后的raise_application_error位上面的代码。
  • 如果没有存储过程,您可能会更好地查询数据库并获取行 。
+0

我也发现rowtype不能在oracle之外使用,所以我决定用一个游标来完成。无论如何,你的答案将起作用,所以我会接受它。谢谢 –