我使用以下代码生成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:非法字符
请帮助.......
答案 0 :(得分:1)
删除生成的SQL语句末尾的分号,然后重试。
答案 1 :(得分:0)
我通过使用 oci_bind_by_name 来准备语句来解决问题。请参阅此链接......
Inserting data in oracle database using php
我摆脱了ORA-00911。这次,错误 ORA-01461 ,即 无效月 ,同时插入日期。以下链接解决了问题...
[Resolved] ORA-01461 Error on ocibindbyname
由于