使用OraOleadb驱动程序调用Oracle存储过程的经典ASP

使用OraOleadb驱动程序调用Oracle存储过程的经典ASP,oracle,asp-classic,Oracle,Asp Classic,我面临一个非常奇怪的问题,可能是我错过了什么 下面是一个场景,我们有一个ASP应用程序,它使用Oracle11g作为后端数据库 我们正在调用一个接受这些参数的存储过程 PROCEDURE PR_SUMMARY_IN(theAccountId in varchar2, theAwardId in number, theDueDate in varchar2,

我面临一个非常奇怪的问题,可能是我错过了什么

下面是一个场景,我们有一个ASP应用程序,它使用Oracle11g作为后端数据库

我们正在调用一个接受这些参数的存储过程

PROCEDURE PR_SUMMARY_IN(theAccountId in varchar2,
                        theAwardId in number,
                        theDueDate in varchar2,
                        theSubmittedDate in varchar2,
                        theReportDescription in varchar2,
                        theFormId in varchar2,
                        theReturnCode out number) 
AS
    v_submitted_date date;
BEGIN
      IF theSubmittedDate IS NOT NULL THEN                                    
                v_submitted_date := to_date(theSubmittedDate,'MM/DD/YYYY');--error here         
            ELSE                                                                    
                v_submitted_date := NULL;                                           

            END IF;

       insert into abc (.....) values (....)
    end
参数值如下所示

'3407840001'
8714898
'05/09/2016'
'05/09/2016'
'Test'
'1'
当我从SQLPlus运行此过程时,它可以工作,但当我从ASP代码调用它时,它会抛出一个错误

ORA-20502:ORA-01858:在需要数字的位置找到非数字字符

下面是ASP代码快照

due_date = Request.Form("due_date" & i)
        IF Len(due_date) = 0 THEN
            theDueDt = NULL
        ELSE
            theDueDt = "'" & due_date & "'"
        END IF

        submitted_date = Request.Form("submitted_date" & i)
        IF Len(submitted_date) = 0 THEN
            theSubmittedDt = NULL
        ELSE
            theSubmittedDt = "'" & submitted_date & "'"
        END IF

        report_description = Request.Form("report_description" & i)
        IF Len(report_description) = 0 THEN
            theReportDesc = NULL
        ELSE
            theReportDesc = "'" & Replace(report_description,"'","''") & "'"
        END IF

        form_id = Request.Form("form_id" & i)
        IF Len(form_id) = 0 THEN
            theFrmId = NULL
        ELSE
            theFrmId = "'" & Replace(form_id,"'","''") & "'"
        END IF  

        cmd.CommandType = 4
        cmd.CommandText = "deadlines_summary.PR_SUMMARY_IN" 

        cmd.Parameters.Append cmd.CreateParameter("theAccountId", 12, 1, 100, Request.Form ("aid"))
        cmd.Parameters.Append cmd.CreateParameter("theAwardId", adNumeric, 1, 100, award_id)
        cmd.Parameters.Append cmd.CreateParameter("theDueDate", 12, 1, 100, theDueDt)
        cmd.Parameters.Append cmd.CreateParameter("theSubmittedDate", 12, 1, 100, theSubmittedDt)
        cmd.Parameters.Append cmd.CreateParameter("theReportDescription", 12, 1, 100, theReportDesc)
        cmd.Parameters.Append cmd.CreateParameter("theFormId", 12, 1, 100, theFrmId)

        cmd.Parameters.Append cmd.CreateParameter("theReturnCode", 131, 2, 10)


        IF Len(report_description) > 0 THEN    
            set rs = cmd.execute
        END IF
有什么建议吗

出于测试目的,我已在SP中将局部变量声明为varchar2,并以mm/dd/yyyy格式分配了值“12/09/2016”

然后在圆木下面。前后

如果值是硬编码的,则不使用单引号进行处理。想知道怎么做

CREATED_ON----------MSG--------------------------------------------------------------------------------

05/09/2016          1.1 theDueDate '12/09/2016' tmp_theDueDate 12/09/2016 v_due_date

05/09/2016          1.2 theSubmittedDate '11/09/2016' tmp_theSubmittedDate 11/09/2016 v_submitted_date

05/09/2016          2.1 theSubmittedDate '11/09/2016' tmp_theSubmittedDate 11/09/2016 v_submitted_date 2016-11-09 00:00:00

05/09/2016          2.2 theDueDate '12/09/2016' tmp_theDueDate 12/09/2016 v_due_date 2016-12-09 00:00:00
根据,ADO不支持参数类型
adVariant
(即12)

为了使代码更具可读性,您应该使用常量,例如

Const adUseClient = 3
Const adOpenStatic = 3
Const adCmdText = 1
Const adCmdStoredProc = 4

Const adVarChar = 200 
Const adNumeric = 131 
Const adChar = 129
Const adBigInt = 20 
Const adInteger = 3

Const adParamInput = 1
Const adParamOutput = 2
Const adParamInputOutput = 3
Const adParamReturnValue = 4

cmd.Parameters.Append cmd.CreateParameter("theAccountId", adVarChar, adParamInput, , Request.Form ("aid"))
cmd.Parameters.Append cmd.CreateParameter("theAwardId", adNumeric, adParamInput, , award_id)
cmd.Parameters.Append cmd.CreateParameter("theDueDate", adVarChar, adParamInput, 100, theDueDt)
cmd.Parameters.Append cmd.CreateParameter("theSubmittedDate", adVarChar, adParamInput, 100, theSubmittedDt)
cmd.Parameters.Append cmd.CreateParameter("theReportDescription", adVarChar, adParamInput, 100, theReportDesc)
cmd.Parameters.Append cmd.CreateParameter("theFormId", adVarChar, adParamInput, 100, theFrmId)
cmd.Parameters.Append cmd.CreateParameter("theReturnCode", adNumeric, adParamOutput)
也许可以试试这个:

cmd.CommandType = adCmdText
cmd.CommandText = "{CALL deadlines_summary.PR_SUMMARY_IN(?,?,?,?,?,?,?)}"
数字参数不需要大小值

您还应该尝试使用参数类型
adDate
,而不是将日期转换为字符串值


使用bind参数时,必须删除引号,即只使用
submitteddt=submitteddt\u date
而不是
submitteddt=“””&submitteddtdt\u date&“”
。我是如何通过更改下面的代码来运行上面的代码的


发送参数值时不带引号,有效。需要找出根本原因和这种奇怪的行为。谢谢大家的建议。

您是否传入了与存储过程参数相应的参数类型?是否可以粘贴生成命令和添加参数等的asp代码?是否可以使用常量(如
adVariant
)而不是12(即
adVariant
)?10对于输出参数有什么用途?为什么
Request.Form(“aid”)
没有被引号包围?@shahkalpesh,我用一些发现更新了我的问题。1.1、1.2在场景之前,2.1、2.2在场景之后。硬编码的值被区别对待很抱歉我看不到你的帖子并回复了。但无论如何,我都会将您的帖子标记为submitteddt=submitteddt\u日期,而不是submitteddt=“”&submitteddt\u date&“”,作为答案。谢谢。但是如果可能的话,你能告诉我为什么会有这种行为吗?这是绑定参数的主要目的(即
cmd.parameters.Append cmd.CreateParameter…
),你不必关心任何引用机制。
       IF Len(due_date) = 0 THEN
            theDueDt = NULL
        ELSE
            theDueDt = "'" & due_date & "'"
        END IF

        submitted_date = Request.Form("submitted_date" & i)
        IF Len(submitted_date) = 0 THEN
            theSubmittedDt = NULL
        ELSE
            theSubmittedDt = "'" & submitted_date & "'"
        END IF
IF Len(due_date) = 0 THEN
        theDueDt = NULL
    ELSE
        theDueDt = due_date
    END IF

    submitted_date = Request.Form("submitted_date" & i)
    IF Len(submitted_date) = 0 THEN
        theSubmittedDt = NULL
    ELSE
        theSubmittedDt = submitted_date
    END IF