我正在尝试在PHP中执行存储过程,将数据插入表中并继续收到以下错误消息。
oci_execute()[function.oci-execute]:ORA-01843:不是有效月份 ORA-06512:第1行
我自己运行了插入查询,但没有收到此错误。这是程序代码。
CREATE OR REPLACE PACKAGE trans_data AS
PROCEDURE INSERT_TRANSACTION_INFO(
var_FName IN TRANSACTION.FIRST_NAME%type,
var_LName IN TRANSACTION.LAST_NAME%type,
var_DOB IN TRANSACTION.DOB%type,
var_InvoiceDate IN TRANSACTION.INVOICE_DATE%type,
var_ServiceCode IN TRANSACTION.SERVICE_CODE%type,
var_BilledAmt IN TRANSACTION.BILLED_AMT%type,
var_SSN IN TRANSACTION.SSN%type,
var_ServiceDate IN TRANSACTION.SERVICE_DATE%type,
var_VendorCode IN TRANSACTION.VENDOR_CODE%type,
var_TransStatus IN TRANSACTION.TRANS_STATUS%type,
var_Comp IN TRANSACTION.COMPANY%type,
var_State IN TRANSACTION.STATE%type,
var_Return OUT VARCHAR2
);
END trans_data;
CREATE OR REPLACE PACKAGE BODY trans_data AS
PROCEDURE INSERT_TRANSACTION_INFO(
var_FName IN TRANSACTION.FIRST_NAME%type,
var_LName IN TRANSACTION.LAST_NAME%type,
var_DOB IN TRANSACTION.DOB%type,
var_InvoiceDate IN TRANSACTION.INVOICE_DATE%type,
var_ServiceCode IN TRANSACTION.SERVICE_CODE%type,
var_BilledAmt IN TRANSACTION.BILLED_AMT%type,
var_SSN IN TRANSACTION.SSN%type,
var_ServiceDate IN TRANSACTION.SERVICE_DATE%type,
var_VendorCode IN TRANSACTION.VENDOR_CODE%type,
var_TransStatus IN TRANSACTION.TRANS_STATUS%type,
var_Comp IN TRANSACTION.COMPANY%type,
var_State IN TRANSACTION.STATE%type,
var_Return OUT VARCHAR2)
IS
BEGIN
INSERT INTO TRANSACTION
(FIRST_NAME, LAST_NAME, DOB, INVOICE_DATE, SERVICE_CODE, BILLED_AMT,
SSN, SERVICE_DATE, VENDOR_CODE, TRANSACTION_ID, TRANS_STATUS, COMPANY,
STATE)
VALUES
(var_FName, var_LName, to_date(var_DOB, 'MM/DD/YY'),
to_date(var_InvoiceDate, 'MM/DD/YY'), var_ServiceCode, var_BilledAmt,
var_SSN, to_date(var_ServiceDate, 'MM/DD/YY'), var_VendorCode,
SEQ_TRANSACTION_ID.nextval, var_TransStatus, var_Comp, var_State);
var_return := 'PASS';
EXCEPTION
WHEN DUP_VAL_ON_INDEX THEN
var_return := 'DUPE';
WHEN OTHERS THEN
var_return := 'FAIL';
END INSERT_TRANSACTION_INFO;
END trans_data;
我的PHP代码收到上一页的POST,我验证了所有字段都正确传递,并将它们绑定到变量。
//setup insert statement
$stmts = OCI_Parse($c,"BEGIN ucs.trans_data.INSERT_TRANSACTION_INFO(
:var_FName, :var_LName, :var_DOB, :var_InvoiceDate, :var_ServiceCode, :var_BilledAmt, :var_SSN,
:var_ServiceDate, :var_VendorCode, :var_TransStatus, :var_Comp, :var_State, :var_return); END;");
//bind input and output
OCI_Bind_By_Name($stmts, ":var_FName", $FName);
OCI_Bind_By_Name($stmts, ":var_LName", $LName);
OCI_Bind_By_Name($stmts, ":var_DOB", $DOB);
OCI_Bind_By_Name($stmts, ":var_InvoiceDate", $InvoiceDate);
OCI_Bind_By_Name($stmts, ":var_ServiceCode", $ServiceCode);
OCI_Bind_By_Name($stmts, ":var_BilledAmt", $BilledAmt);
OCI_Bind_By_Name($stmts, ":var_SSN", $SSN);
OCI_Bind_By_Name($stmts, ":var_ServiceDate", $ServiceDate);
OCI_Bind_By_Name($stmts, ":var_VendorCode", $VendorCode);
OCI_Bind_By_Name($stmts, ":var_TransStatus", $TransStatus);
OCI_Bind_By_Name($stmts, ":var_Comp", $ComCode);
OCI_Bind_By_Name($stmts, ":var_State", $State);
OCI_Bind_By_Name($stmts, ":var_return", $Return, 4);
//execute statement and add message to Return
oci_execute($stmts);
oci_commit($c);
为什么使用01/01/11日期的任何想法都会返回此消息?如果您需要我发布任何其他信息,请告诉我。
答案 0 :(得分:0)
您在过程中为DATE参数声明了错误的类型。
您的程序使用to_date
来解析日期,因此每个日期都应作为VARCHAR
传递。但是你声明你的参数属于DATE
类型:
var_DOB IN TRANSACTION.DOB%type,
var_InvoiceDate IN TRANSACTION.INVOICE_DATE%type,
var_ServiceDate IN TRANSACTION.SERVICE_DATE%type,
尝试将其更改为:
var_DOB IN VARCHAR2,
var_InvoiceDate IN VARCHAR2,
var_ServiceDate IN VARCHAR2,
然后看它是否有效。