我在以下select语句上面有一个oracle连接字符串。
这里是select语句:
$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'
是单引号问题吗?
答案 0 :(得分: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 = '
然后是你的值,然后是另一个字符串,这是无效的语法。
答案 1 :(得分:0)
是的,单引号就是问题。
要么像\'CF\'
那样转义CF引号,要么使用“而不是。