我想在oracle数据库上使用来自可变数据的php的简单oracle insert语句,但我在浏览器上收到错误:
oci_bind_by_name():ORA-01036:非法变量名称/编号
我正在回答几个问题,但没有得到答案。这是我的代码:
include("conn.php");
$THR_ATTENDANCERAW_ID = 'AAANttAAMAAANG1ABF';
$AD_CLIENT_ID = '8D8C2A846B2545128823CC7611C9EF80';
$AD_ORG_ID = 'BB7935DD9F9F46B8A3CEBFB8CA73929B';
$ISACTIVE = 'Y';
$CREATED = '03/21/2018 10:20:12';
$CREATEDBY = '0';
$UPDATED = '03/21/2018 10:20:12';
$UPDATEDBY = '0';
$CHECKTIME = '03/21/2018 10:20:12';
$USERNO = '10842803';
$DOCUMENTNO = '0010842803';
$ISMANUAL = 'N';
$DEVICENO = '2';
$ATTENDANCETYPE = '0';
$ERROR_CODE = '0';
$PRODUCTNAME = 'NULL';
$SERIAL_NUMBER = 'NULL';
$ACCOUNT_NUMBER = 'NULL';
$NAME = 'NULL';
$S_TIME = 'NULL';
$MACHINE = 'NULL';
$VERIFY_MODE = 'NULL';
$sql1 = "
INSERT INTO THR_ATTENDANCERAW (THR_ATTENDANCERAW_ID, AD_CLIENT_ID, AD_ORG_ID, ISACTIVE, CREATED,
CREATEDBY, UPDATED, UPDATEDBY, CHECKTIME, USERNO,
DOCUMENTNO, ISMANUAL, DEVICENO, ATTENDANCETYPE, ERROR_CODE,
PRODUCTNAME, SERIAL_NUMBER, ACCOUNT_NUMBER, NAME, S_TIME,
MACHINE, VERIFY_MODE)
VALUES (
'AAANttAAMAAANG1ABF, :AD_CLIENT_ID, :AD_ORG_ID, :ISACTIVE, :CREATED, :CREATEDBY, :UPDATED, :UPDATEDBY, :CHECKTIME, :USERNO, :DOCUMENTNO, :ISMANUAL, :DEVICENO, :ATTENDANCETYPE, :ERROR_CODE, :PRODUCTNAME, :SERIAL_NUMBER, :ACCOUNT_NUMBER, :NAME, :S_TIME, :MACHINE, :VERIFY_MODE')" ;
//echo $sql1;
$compiled1 = oci_parse($conn, $sql1);
oci_bind_by_name($compiled1, ':THR_ATTENDANCERAW_ID', $THR_ATTENDANCERAW_ID);
oci_bind_by_name($compiled1, ':AD_CLIENT_ID', $AD_CLIENT_ID);
oci_bind_by_name($compiled1, ':AD_ORG_ID', $AD_ORG_ID);
oci_bind_by_name($compiled1, ':ISACTIVE', $ISACTIVE);
oci_bind_by_name($compiled1, ':CREATED', $CREATED);
oci_bind_by_name($compiled1, ':CREATEDBY', $CREATEDBY);
oci_bind_by_name($compiled1, ':UPDATED', $UPDATED);
oci_bind_by_name($compiled1, ':UPDATEDBY', $UPDATEDBY);
oci_bind_by_name($compiled1, ':CHECKTIME', $CHECKTIME);
oci_bind_by_name($compiled1, ':USERNO', $USERNO);
oci_bind_by_name($compiled1, ':DOCUMENTNO', $DOCUMENTNO);
oci_bind_by_name($compiled1, ':ISMANUAL', $ISMANUAL);
oci_bind_by_name($compiled1, ':DEVICENO', $DEVICENO);
oci_bind_by_name($compiled1, ':ATTENDANCETYPE', $ATTENDANCETYPE);
oci_bind_by_name($compiled1, ':ERROR_CODE', $ERROR_CODE);
oci_bind_by_name($compiled1, ':PRODUCTNAME', $PRODUCTNAME);
oci_bind_by_name($compiled1, ':SERIAL_NUMBER', $SERIAL_NUMBER);
oci_bind_by_name($compiled1, ':ACCOUNT_NUMBER', $ACCOUNT_NUMBER);
oci_bind_by_name($compiled1, ':NAME', $NAME);
oci_bind_by_name($compiled1, ':S_TIME', $S_TIME);
oci_bind_by_name($compiled1, ':MACHINE', $MACHINE);
oci_bind_by_name($compiled1, ':VERIFY_MODE', $VERIFY_MODE);
oci_execute($compiled1);
?>
错误显示为:
Warning: oci_bind_by_name(): ORA-01036: illegal variable name/number in C:\xampp\htdocs\php_zklib\insert.php on line 42
Warning: oci_bind_by_name(): ORA-01036: illegal variable name/number in C:\xampp\htdocs\php_zklib\insert.php on line 43
Warning: oci_bind_by_name(): ORA-01036: illegal variable name/number in C:\xampp\htdocs\php_zklib\insert.php on line 44
Warning: oci_bind_by_name(): ORA-01036: illegal variable name/number in C:\xampp\htdocs\php_zklib\insert.php on line 45
Warning: oci_bind_by_name(): ORA-01036: illegal variable name/number in C:\xampp\htdocs\php_zklib\insert.php on line 46
Warning: oci_bind_by_name(): ORA-01036: illegal variable name/number in C:\xampp\htdocs\php_zklib\insert.php on line 47
Warning: oci_bind_by_name(): ORA-01036: illegal variable name/number in C:\xampp\htdocs\php_zklib\insert.php on line 48
Warning: oci_bind_by_name(): ORA-01036: illegal variable name/number in C:\xampp\htdocs\php_zklib\insert.php on line 49
Warning: oci_bind_by_name(): ORA-01036: illegal variable name/number in C:\xampp\htdocs\php_zklib\insert.php on line 50
Warning: oci_bind_by_name(): ORA-01036: illegal variable name/number in C:\xampp\htdocs\php_zklib\insert.php on line 51
Warning: oci_bind_by_name(): ORA-01036: illegal variable name/number in C:\xampp\htdocs\php_zklib\insert.php on line 52
Warning: oci_bind_by_name(): ORA-01036: illegal variable name/number in C:\xampp\htdocs\php_zklib\insert.php on line 53
Warning: oci_bind_by_name(): ORA-01036: illegal variable name/number in C:\xampp\htdocs\php_zklib\insert.php on line 54
Warning: oci_bind_by_name(): ORA-01036: illegal variable name/number in C:\xampp\htdocs\php_zklib\insert.php on line 55
Warning: oci_bind_by_name(): ORA-01036: illegal variable name/number in C:\xampp\htdocs\php_zklib\insert.php on line 56
Warning: oci_bind_by_name(): ORA-01036: illegal variable name/number in C:\xampp\htdocs\php_zklib\insert.php on line 57
Warning: oci_bind_by_name(): ORA-01036: illegal variable name/number in C:\xampp\htdocs\php_zklib\insert.php on line 58
Warning: oci_bind_by_name(): ORA-01036: illegal variable name/number in C:\xampp\htdocs\php_zklib\insert.php on line 59
Warning: oci_bind_by_name(): ORA-01036: illegal variable name/number in C:\xampp\htdocs\php_zklib\insert.php on line 60
Warning: oci_bind_by_name(): ORA-01036: illegal variable name/number in C:\xampp\htdocs\php_zklib\insert.php on line 61
Warning: oci_bind_by_name(): ORA-01036: illegal variable name/number in C:\xampp\htdocs\php_zklib\insert.php on line 62
Warning: oci_bind_by_name(): ORA-01036: illegal variable name/number in C:\xampp\htdocs\php_zklib\insert.php on line 63
Warning: oci_execute(): ORA-00947: not enough values in C:\xampp\htdocs\php_zklib\insert.php on line 67
答案 0 :(得分:0)
我不使用PHP。
错误堆栈中的最后一行是
警告:oci_execute():ORA-00947:值不够
如果你看一下$ sql1,它说的是这样的:
INSERT INTO THR_ATTENDANCERAW
(THR_ATTENDANCERAW_ID,
AD_CLIENT_ID,
<snip>
VERIFY_MODE)
VALUES
('AAANttAAMAAANG1ABF, :AD_CLIENT_ID, <snip>, :VERIFY_MODE')
^ ^
here here
在最后一行看到那些单引号?在Oracle中,它们意味着您要插入字符串(这是您在这些单引号之间看到的所有内容)。
我认为Oracle认为有22个列要填充一些值,而您只在第一列(THR_ATTENDANCERAW_ID)中插入一个 long 字符串。
因此,因为第一个值看起来像一个字符串,所以只将该值包含在单引号中,即'AAANttAAMAAANG1ABF'
,并保留其余值(当然,删除结束的单引号)。