如何编写带引号的SQL语句? [英] How to write SQL statement with quotes?

查看:103
本文介绍了如何编写带引号的SQL语句?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
在Java中,是否有一种无需转义引号就能编写字符串文字的方法?

Possible Duplicate:
In Java, is there a way to write a string literal without having to escape quotes?

我想使用sql查询获取Oracle启动时间.我使用此SQL语句

I want to get Oracle starttime with sql query. I use this SQL statement

SQL_Statement = "select to_char(startup_time, 'HH24:MI DD-MON-YY') "Startup time" from  v$instance";

当我尝试使用此SQL语句编写代码时,引号存在问题.编写此SQL语句的正确方法是什么?

There is a problem with the quotes when I try to write a code with this SQL statement. What is the proper way to write this SQL statement?

最美好的祝愿

P.S我使用Java.当我尝试运行此SQL查询时:

P.S I use Java. When I try to run this SQL query:

select  to_char(startup_time, 'HH24:MI DD-MON-YY') 'Startup time' from  v$instance

我收到此错误:

Error starting at line 1 in command:
select  to_char(startup_time, 'HH24:MI DD-MON-YY') 'Startup time' from  v$instance 
Error at Command Line:1 Column:50
Error report:
SQL Error: ORA-00923: FROM keyword not found where expected
00923. 00000 -  "FROM keyword not found where expected"
*Cause:    
*Action:

推荐答案

在Java中,您需要使用单个'\'字符对字符串内的双引号进行转义

In Java, you need to escape the double quotes inside the string using a single '\' character

SQL_Statement = "select to_char(startup_time, 'HH24:MI DD-MON-YY') \"Startup time\" from  v$instance";

请参见 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆