我在jdbc中使用了sql查询
SELECT COUNT (COST_CENTER) AS count FROM IMDB1_FINANCE_BUDGET where COST_CENTER='object name'
这工作正常,但我有一些测试对象,如' 0654603?在现在开始查询时带有单引号的SSG会计将是
SELECT COUNT (COST_CENTER) AS count FROM IMDB1_FINANCE_BUDGET where COST_CENTER=''0654603 ? SSG '
现在它正在抛出异常
java.sql.SQLException: ORA-00933: SQL command not properly ended
如何处理此类对象
答案 0 :(得分:2)
在这种情况下处理单引号的最佳方法是使用Quoting string literal technique
例如, q' [' SCOTT]'
SQL> WITH DATA AS(
2 SELECT '''SCOTT' nm FROM dual
3 )
4 SELECT * FROM DATA WHERE nm = q'['SCOTT]';
NM
------
'SCOTT
SQL>
当然,用单引号''                    
SQL> WITH DATA AS(
2 SELECT '''SCOTT' nm FROM dual
3 )
4 SELECT * FROM DATA WHERE nm = '''SCOTT';
NM
------
'SCOTT
SQL>