Oracle APEX错误ORA-01460 ORA-02063

时间:2017-10-16 14:21:02

标签: oracle plsql oracle-apex

我正在使用以下代码创建经典报告(基于函数):

declare
    q long;
begin
-- The query with any conditions always applied
    q := 'select * from name_selection_atnd where 1 = 1';

-- If all items are null then kill query
if  :P500_FN is null 
    and :P500_LN is null
then
    q := q || ' and name_said = 0'; --will always return 0 rows
end if;

-- Append any optional conditions
if :P500_FN is not null then
  q := q || ' and name_first_name = :P500_FN';
end if;

if :P500_LN is not null then
  q := q || ' and name_last_name = :P500_LN';
end if;

return q;
end;

除了名字和姓氏之外,我的最终代码还需要包含更多要搜索的项目,但是现在我只使用这两个参数进行测试。当我只填写名字时,搜索工作。当我只填写姓氏时,它有效。当我输入第一个姓氏时,我收到错误ORA-01460和ORA-02063。

我可能做错了什么?

2 个答案:

答案 0 :(得分:1)

我可以看到你在bind中使用了''变量,这些变量永远不会在PLSQL块中进行评估:

q := q || ' and name_first_name = :P500_FN';

这应该是这样的:

q := q || ' and name_first_name = '||:P500_FN; 

答案 1 :(得分:0)

您不需要动态SQL:

SELECT *
FROM   name_selection_atnd
WHERE  ( :P500_FN IS NULL OR name_first_name = :P500_FN )
AND    ( :P500_LN IS NULL OR name_last_name  = :P500_LN )
AND    ( :P500_FN IS NOT NULL OR :P500_LN IS NOT NULL );