admin

如何编写带引号的SQL语句?

sql

我想使用sql查询获取Oracle启动时间。我用这个SQL语句

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

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

最好的祝愿

PS我使用Java。当我尝试运行此SQL查询时:

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:

阅读 176

收藏
2021-06-07

共1个答案

admin

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

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