Why this PL/SQL query doesn't execute using ODP.NET

谁说胖子不能爱 提交于 2019-12-11 23:12:06

问题


Somewhere in my code there's a query generated which is going to execute using:

command.ExecuteNonQuery();

but for the following query, it throws this exception:

{"ORA-01036: illegal variable name/number"}

The strange point is that if I copy this query to Toad and set its parameter values, It executes without any problem.

My query which is set in command.CommandText is:

declare vv2 number ; 
BEGIN 
:vv := '';

begin SKY.BUSINESS_OBJECT_PKG.REGISTER(B_TYPE_ID=>:B_a_TYPE_ID, B_ID=>:B_b_ID); end;

INSERT INTO GALAXY.E_CONTENTS(
    CONTENT,
    HASH_CODE,
    FILE_NAME,
    THUMBNAIL,
    ID,
    LOCKED_BY_ID,
    TYPE_ID
)
VALUES 
(
    :P_c_CONTENT,
    :P_d_HASH_CODE,
    :P_e_FILE_NAME,
    :P_f_THUMBNAIL,
    :P_g_ID,
    :P_h_LOCKED_BY_ID,
    :P_i_TYPE_ID
);

begin SKY.BUSINESS_OBJECT_PKG.REGISTER(B_TYPE_ID=>:B_j_TYPE_ID, B_ID=>:B_k_ID); end;

INSERT INTO EVENT_MANAGEMENT.UI_EVENT(
    NOTIFICATION_PORT,
    WORK_ITEM,
    WORK_ITEM_DESC,
    BO_DESC,
    BO_CHANGES_ID,
    SMART_SERVICE_VALUE,
    CONTEXT_ID,
    CONTEXT_TYPE_ID,
    DESCRIPTION,
    EVENT_DATE,
    CREATION_DATE,
    SENDER_ID,
    MACHINE,
    EVENT_CATEGORY,
    REFERENCE_ID,
    EVENT_MODE,
    HANDLED_DATE,
    HISTORY,
    IS_VIEWED,
    IS_ACTIVE,
    ID,
    LOCKED_BY_ID,
    TYPE_ID
)
VALUES 
(
    :P_l_NOTIFICATION_PORT,
    :P_m_WORK_ITEM,
    :P_m_WORK_ITEM_DESC,
    :P_o_BO_DESC,
    :P_p_BO_CHANGES_ID,
    :P_q_SMART_SERVICE_VALUE,
    :P_r_CONTEXT_ID,
    :P_s_CONTEXT_TYPE_ID,
    :P_t_DESCRIPTION,
    :P_u_EVENT_DATE,
    :P_v_CREATION_DATE,
    :P_w_SENDER_ID,
    :P_x_MACHINE,
    :P_y_EVENT_CATEGORY,
    :P_z_REFERENCE_ID,
    :P_aa_EVENT_MODE,
    :P_ab_HANDLED_DATE,
    :P_ac_HISTORY,
    :P_ad_IS_VIEWED,
    :P_ae_IS_ACTIVE,
    :P_af_ID,
    :P_ag_LOCKED_BY_ID,
    :P_ah_TYPE_ID
);

begin SKY.BUSINESS_OBJECT_PKG.REGISTER(B_TYPE_ID=>:B_ai_TYPE_ID, B_ID=>:B_aj_ID); end;

INSERT INTO ACCOUNTING.TRANSACTIONS(
    TITLE,
    LAST_CHANGE_ID,
    EFFECTIVE_DATE,
    CREATE_DATE,
    BO_REFRENCE_ID,
    CREATOR_ID,
    COMPANY_ID,
    VOUCHER_ID,
    TRANSACTION_TYPE_VALUE,
    FISCAL_YEAR_ID,
    TRANSACTION_STATE_VALUE,
    FYTB_ID,
    REVISORY_TRANSACTION_ID,
    BO_TYPE_VALUE,
    TRANSACTION_NUMBER,
    ID,
    LOCKED_BY_ID,
    TYPE_ID
)
VALUES 
(
    :P_ak_TITLE,
    :P_al_LAST_CHANGE_ID,
    :P_am_EFFECTIVE_DATE,
    :P_an_CREATE_DATE,
    :P_ao_BO_REFRENCE_ID,
    :P_ap_CREATOR_ID,
    :P_aq_COMPANY_ID,
    :P_ar_VOUCHER_ID,
    :P_as_TRANSACTION_TYPE_VALUE,
    :P_at_FISCAL_YEAR_ID,
    :P_au_TRANSACTION_STATE_VALUE,
    :P_av_FYTB_ID,
    :P_aw_REVISORY_TRANSACTION_ID,
    :P_ax_BO_TYPE_VALUE,
    :P_ay_TRANSACTION_NUMBER,
    :P_az_ID,
    :P_ba_LOCKED_BY_ID,
    :P_bb_TYPE_ID
);

END;

FYI, I'm using ODP.NET.

Why this exception is being thrown for such query?

Update 1: Before this problem I've confronted such problem before and following hints resolved them. But in this case, these hint's doesn't work.

  • Removing all "\n", "\r", "\t" characters from the query.
  • Renaming all variables with a name longer that 31 characters.

回答1:


Maybe it's because ODP.NET doesn't support the '\r' character in some situations... Try to remplace

command.ExecuteNonQuery();

by

command.CommandText = command.CommandText.Replace("\r", string.Empty);
command.ExecuteNonQuery();



回答2:


You should post the rest of your .net code, specifically the parameters you're adding to the command. In any case I see a couple of potential problems:

One, maybe toad is doing something special, but the following is not valid in a sql-plus window:

declare vv2 number ; 
BEGIN 
:vv := '';
end;
/

Bind variables with the colon are actually declared in the sql-plus "var" statement, not in the declare statement of the anonymous pl-sql block. It doesn't look like you're using that variable anyway. This alone could be the problem since it's throwing off the number of parameters that need to be bound.

Two, this might be a typical parameter missmatch issue (again, need to see your Parameter.Add calls). Could be mismatched number of params, parameter type, parameter order, etc. Please refer to a previous blog post of mine.

Last, I've not tried to execute two anonymous blocks in one statement. Maybe try one at a time just to rule them out? I've also have an in-depth write up of calling sql-plus scripts.



来源:https://stackoverflow.com/questions/21257429/why-this-pl-sql-query-doesnt-execute-using-odp-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!