2017-10-16 58 views
0

我创建一个经典报告(基于功能)用下面的代码:的Oracle APEX错误ORA-01460 ORA-02063

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。

我会做什么错?

+0

什么是你输入'P500_FN'。为什么你在任何地方使用绑定变量。在声明中只使用一次从绑定变量获取值到局部变量中。对这些变量进行比较。 –

+0

我正在输入一个字符串。只要一个人的名字 –

+0

你能给出完整的错误信息,而不仅仅是代码? – MT0

回答

1

我可以看到你使用的内部''bind变量,将在PLSQL块不会求:

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

这应该是这样的:

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

太好了!但现在,如果我像“乔丹”输入一个名称,我得到这个错误ORA-00904:“乔丹”:无效的标识符 –

+0

@JordanHolmer您需要通过'Jordan'作为一个字符串,因此它必须在''Jordan''时你通过它。当您传递值时,您必须包含单引号(')。 – XING

+0

谢谢!我现在开始工作了 –

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); 
+0

我得到同样的错误,当我做这个 –