Oracle APEX 错误 ORA-01460 ORA-02063
Oracle APEX error 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。
我可能做错了什么?
你不需要动态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 );
我可以看到您在 ''
中使用了 bind
变量,这些变量永远不会在 PLSQL 块中求值:
q := q || ' and name_first_name = :P500_FN';
这应该是这样的:
q := q || ' and name_first_name = '||:P500_FN;
我正在使用以下代码创建经典报表(基于函数):
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。
我可能做错了什么?
你不需要动态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 );
我可以看到您在 ''
中使用了 bind
变量,这些变量永远不会在 PLSQL 块中求值:
q := q || ' and name_first_name = :P500_FN';
这应该是这样的:
q := q || ' and name_first_name = '||:P500_FN;