0

我在以下 select 语句上方有一个 oracle 连接字符串。

这是选择语句:

$stid = oci_parse($conn1, 'SELECT s.SID, USERNAME AS "User", PROGRAM, MODULE,
ACTION, LOGON_TIME "Logon", l.*
FROM V$SESSION s, V$ENQUEUE_LOCK l
WHERE l.SID = s.SID
AND l.TYPE = 'CF'
AND l.ID1 = 0
AND l.ID2 = 2');

oci_execute ($stid);

但是,它在第​​ 69 行给了我一个 t_string 错误。这是这一行:

AND l.TYPE = 'CF'

单引号是问题吗?

4

2 回答 2

3

您必须转义单引号:

$stid = oci_parse($conn1, 'SELECT s.SID, USERNAME AS "User", PROGRAM, MODULE,
ACTION, LOGON_TIME "Logon", l.*
FROM V$SESSION s, V$ENQUEUE_LOCK l
WHERE l.SID = s.SID
AND l.TYPE = \'CF\'
AND l.ID1 = 0
AND l.ID2 = 2')

现在,它被解析为:

'SELECT s.SID, USERNAME AS "User", PROGRAM, MODULE,
 ACTION, LOGON_TIME "Logon", l.*
 FROM V$SESSION s, V$ENQUEUE_LOCK l
 WHERE l.SID = s.SID
 AND l.TYPE = '

然后是你的值,然后是另一个字符串,这是无效的语法。

于 2013-08-08T14:26:57.850 回答
0

是的,单引号是问题所在。

要么像这样转义 CF 引号,\'CF\'要么使用 " 代替。

于 2013-08-08T14:28:06.353 回答