使用 oci_execute() 时需要帮助消除 ORA-00911 错误
我正在使用以下代码来生成 SQL。
$sql = "INSERT INTO SUBSTATION VALUES (".
"SEQ_SUBSTATION_FEATURE_ID.NEXTVAL, ".
"'".$_REQUEST['substationName']."', ". // SUBSTATION NAME
"null, ". // SLD_PATH
"null, ". // GEOMETRY
"'".$_REQUEST['substationType']."', ". // SUBSTATION_TYPE
$_REQUEST['capacity'].", ". // CAPACITY
"'".$_REQUEST['address_1']."', ". // ADDRESS_1
"'".$_REQUEST['address_2']."', ". // ADDRESS_2
"'".$_REQUEST['landmark']."', ". // LANDMARK
"'".$_REQUEST['state']."', ". // STATE
"'".$_REQUEST['district']."', ". // DISTRICT
"'".$_REQUEST['pin']."', ". // PIN
$_REQUEST['noOfTransformers'].", ". // NO_OF_TRANSFORMERS
$_REQUEST['noOfLTBreakers'].", ". // NO_OF_LT_BREAKERS
$_REQUEST['noOfHTBreakers'].", ". // NO_OF_HT_BREAKERS
$_REQUEST['noOfHTIsolators'].", ". // NO_OF_HT_ISOLATORS
$_REQUEST['noOfLTBoards'].", ". // NO_OF_LT_BOARDS
"to_date('".$_REQUEST['commissioningDate']."','DD/MM/YYYY'), ". // COMMISSIONING DATE
"'".$_REQUEST['schemeNo']."', ". // SCHEME_NO
"to_date('".$_REQUEST['schemeDate']."','DD/MM/YYYY'), ". // SCHEME_DATE
"'".$_REQUEST['comments']."', ". // COMMENTS
"'N', ". // APPROVED
"null, ". // APPROVER
"null);"; // APPROVED_ON
这是生成的 SQL
INSERT INTO SUBSTATION VALUES
(SEQ_SUBSTATION_FEATURE_ID.NEXTVAL, 'S/S 3 4400', NULL, NULL, 'D', 5000,
'The Address 1', 'The Address 2', 'The Landmark', '15', '1', '234234',
34, 65, 12, 98, 43,
to_date('01/09/2010','DD/MM/YYYY'), 'Scheme 12345',
to_date('06/10/2010','DD/MM/YYYY'), 'This substation has following assets',
'N', null, null);
现在,我直接在 SQL Developer 中运行生成的 SQL,它工作正常。但是当我在 PHP 中使用 oci_execute($sql) 运行查询时,它不起作用。使用以下代码进行调试时:
$st = oci_parse($conn, $sql) or die("<br />Error parsing query. ");
if(!oci_execute($st)){
$err = oci_error($st);
echo $err['message'];
}
它显示错误消息:
ORA-00911:非法字符
请帮忙......
I am using following code to generate the SQL.
$sql = "INSERT INTO SUBSTATION VALUES (".
"SEQ_SUBSTATION_FEATURE_ID.NEXTVAL, ".
"'".$_REQUEST['substationName']."', ". // SUBSTATION NAME
"null, ". // SLD_PATH
"null, ". // GEOMETRY
"'".$_REQUEST['substationType']."', ". // SUBSTATION_TYPE
$_REQUEST['capacity'].", ". // CAPACITY
"'".$_REQUEST['address_1']."', ". // ADDRESS_1
"'".$_REQUEST['address_2']."', ". // ADDRESS_2
"'".$_REQUEST['landmark']."', ". // LANDMARK
"'".$_REQUEST['state']."', ". // STATE
"'".$_REQUEST['district']."', ". // DISTRICT
"'".$_REQUEST['pin']."', ". // PIN
$_REQUEST['noOfTransformers'].", ". // NO_OF_TRANSFORMERS
$_REQUEST['noOfLTBreakers'].", ". // NO_OF_LT_BREAKERS
$_REQUEST['noOfHTBreakers'].", ". // NO_OF_HT_BREAKERS
$_REQUEST['noOfHTIsolators'].", ". // NO_OF_HT_ISOLATORS
$_REQUEST['noOfLTBoards'].", ". // NO_OF_LT_BOARDS
"to_date('".$_REQUEST['commissioningDate']."','DD/MM/YYYY'), ". // COMMISSIONING DATE
"'".$_REQUEST['schemeNo']."', ". // SCHEME_NO
"to_date('".$_REQUEST['schemeDate']."','DD/MM/YYYY'), ". // SCHEME_DATE
"'".$_REQUEST['comments']."', ". // COMMENTS
"'N', ". // APPROVED
"null, ". // APPROVER
"null);"; // APPROVED_ON
Here is the SQL generated
INSERT INTO SUBSTATION VALUES
(SEQ_SUBSTATION_FEATURE_ID.NEXTVAL, 'S/S 3 4400', NULL, NULL, 'D', 5000,
'The Address 1', 'The Address 2', 'The Landmark', '15', '1', '234234',
34, 65, 12, 98, 43,
to_date('01/09/2010','DD/MM/YYYY'), 'Scheme 12345',
to_date('06/10/2010','DD/MM/YYYY'), 'This substation has following assets',
'N', null, null);
Now, I run the SQL generated directly in SQL Developer, it works fine. But when I run the query using oci_execute($sql) in PHP, it does not work. While debugging using the following code:
$st = oci_parse($conn, $sql) or die("<br />Error parsing query. ");
if(!oci_execute($st)){
$err = oci_error($st);
echo $err['message'];
}
It show the error message:
ORA-00911 : illegal character
Any help please.......
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
删除生成的 SQL 语句末尾的分号,然后重试。
Remove the semi-colon at the end of the generated SQL statement and try again.
我通过使用 oci_bind_by_name 准备语句解决了这个问题。请参考此链接...
使用php在oracle数据库中插入数据
我摆脱了 ORA-00911。这次,在插入日期时出现错误 ORA-01461,即月份无效。以下链接解决了问题...
[已解决] ocibindbyname 上出现 ORA-01461 错误< /a>
谢谢
I solved the problem by using oci_bind_by_name to prepare the statement. Please refer the this link...
Inserting data in oracle database using php
I got rid of ORA-00911. This time, error ORA-01461, which is invalid month, while inserting date. Following link solved the problem...
[Resolved] ORA-01461 Error on ocibindbyname
Thanks