我正在写一个像
这样的查询select * from fact_table where name = 'R&D'
select * from fact_table where name = 'John's'
我正在使用oracle 11g数据库。是否有任何通用函数或查询样式,我可以处理像'&'这样的特殊字符和我的查询中的'''。
我不想单独处理每个案例,我想要一个通用的机制。
如果这是重复的帖子,请引导我阅读原帖
答案 0 :(得分:1)
&符号应该可以正常工作。某些工具(如SQLPlus或SQLDeveloper)使用此字符来指示绑定变量。像这样禁用此“功能”: 设置定义关闭 像这样重新启用它:
上设置定义单引号需要特别注意。 使用两个单引号字符告诉数据库将其视为文字,如下所示: select * from fact_table,其中name ='John'''
答案 1 :(得分:0)
使用报价运算符
select * from fact_table where name = q'#John's#'
对于&符号,SQL * Plus
等工具存在问题set define ~
select * from fact_table where name = 'R&D'
但是在pl / sql块中,它似乎工作正常:
declare
output VARCHAR2(10);
BEGIN
SELECT name
INTO output
FROM fact_table
WHERE name = '&1';
DBMS_OUTPUT.put_line('Output: ' || output);
END;
/
SQL> @test.sql;
Enter value for 1: R&D
old 7: WHERE name = '&1';
new 7: WHERE name = 'R&D';
Output: R&D
PL/SQL procedure successfully completed.