英文:
Invalid Number Exception in SQL when trying to call select statement from Java
问题
我正在尝试从我的Java程序中调用一个select
查询,但是我得到了无效数字
的错误。
我正在尝试像这样调用查询:
code
String[] l_arr = new String[]{"CUSTOMERCUMULATIVELIMIT"};
l_rs = JDBCEngine.executeQuery(MessageFormat.format(
" SELECT LIMITS, P.PACKAGE_ID FROM MSTGLOBALLIMITSPACKAGE P ,MSTCUSTOMERPROFILE C WHERE P.PACKAGE_ID = {0} AND C.ID_CUST = ? AND C.ID_ENTITY = ? AND C.TYPEUSER = ? AND C.ID_ENTITY = P.ID_ENTITY AND P.PACKAGE_ID NOT LIKE ?",l_arr );
我得到的查询如下:
Result
SELECT LIMITS, P.PACKAGE_ID
FROM MSTGLOBALLIMITSPACKAGE P, MSTCUSTOMERPROFILE C
WHERE P.PACKAGE_ID = CUSTOMERCUMULATIVELIMIT
AND C.ID_CUST = '00000144'
AND C.ID_ENTITY = 'B001'
AND C.TYPEUSER = 'ECU'
AND C.ID_ENTITY = P.ID_ENTITY
AND P.PACKAGE_ID NOT LIKE '*%'
我在这一行P.PACKAGE_ID = {0}
中得到了无效数字错误。我经过了研究,了解到如果我使用to_char
,我可以避免这个错误。但我不确定如何在P.PACKAGE_ID = {0}
中使用to_char
。
另外,PACKAGE_ID
的类型是Varchar2
,而CUSTOMERCUMULATIVELIMIT
是MSTCUSTOMERPROFILE
中类型为Number
的列。
任何帮助或建议将不胜感激。谢谢。
英文:
I am trying to call a select
query from my Java Program but i am getting Invalid Number
error.
I am trying to call the query something like this
code
String[] l_arr = new String[]{"CUSTOMERCUMULATIVELIMIT"};
l_rs = JDBCEngine.executeQuery(MessageFormat.format(
" SELECT LIMITS, P.PACKAGE_ID FROM MSTGLOBALLIMITSPACKAGE P ,MSTCUSTOMERPROFILE C WHERE P.PACKAGE_ID = {0} AND C.ID_CUST = ? AND C.ID_ENTITY = ? AND C.TYPEUSER = ? AND C.ID_ENTITY = P.ID_ENTITY AND P.PACKAGE_ID NOT LIKE ?",l_arr );
I am getting query something like this:
Result
SELECT LIMITS, P.PACKAGE_ID
FROM MSTGLOBALLIMITSPACKAGE P, MSTCUSTOMERPROFILE C
WHERE P.PACKAGE_ID = CUSTOMERCUMULATIVELIMIT
AND C.ID_CUST = '00000144'
AND C.ID_ENTITY = 'B001'
AND C.TYPEUSER = 'ECU'
AND C.ID_ENTITY = P.ID_ENTITY
AND P.PACKAGE_ID NOT LIKE '*%'
I am getting the error Invalid number in the line P.PACKAGE_ID = {0}
. I gone through and come to know that if i use to_char
i can avoid this error. But I am not sure how to use to_char
in P.PACKAGE_ID = {0}
.
Also PACKAGE_ID
is of type Varchar2
and CUSTOMERCUMULATIVELIMIT
is a column in MSTCUSTOMERPROFILE
of type Number
.
Any help or suggestion will be appreciated. Thanks.
答案1
得分: 1
只需在你的SQL中添加 to_char,将 {0} 更改为 to_char({0})
l_rs = JDBCEngine.executeQuery(MessageFormat.format("SELECT LIMITS, P.PACKAGE_ID FROM MSTGLOBALLIMITSPACKAGE P, MSTCUSTOMERPROFILE C WHERE P.PACKAGE_ID = to_char({0}) AND C.ID_CUST = ? AND C.ID_ENTITY = ? AND C.TYPEUSER = ? AND C.ID_ENTITY = P.ID_ENTITY AND P.PACKAGE_ID NOT LIKE ?", l_arr););
英文:
just add to_char to your sql, change {0} to to_char({0})
l_rs = JDBCEngine.executeQuery(MessageFormat.format( " SELECT LIMITS, P.PACKAGE_ID FROM MSTGLOBALLIMITSPACKAGE P ,MSTCUSTOMERPROFILE C WHERE P.PACKAGE_ID = to_char({0}) AND C.ID_CUST = ? AND C.ID_ENTITY = ? AND C.TYPEUSER = ? AND C.ID_ENTITY = P.ID_ENTITY AND P.PACKAGE_ID NOT LIKE ?",l_arr );
答案2
得分: 0
你正在处理以下代码行:
WHERE P.PACKAGE_ID = CUSTOMERCUMULATIVELIMIT
由于没有单引号,SQL将CUSTOMERCUMULATIVELIMIT视为数字,而不是字符串。
添加单引号应该可以解决这个问题。
l_rs = JDBCEngine.executeQuery(MessageFormat.format(
" SELECT LIMITS, P.PACKAGE_ID FROM MSTGLOBALLIMITSPACKAGE P ,MSTCUSTOMERPROFILE C WHERE P.PACKAGE_ID = '{0}' AND C.ID_CUST = ? AND C.ID_ENTITY = ? AND C.TYPEUSER = ? AND C.ID_ENTITY = P.ID_ENTITY AND P.PACKAGE_ID NOT LIKE ?", l_arr );
英文:
You are working with this line :
WHERE P.PACKAGE_ID = CUSTOMERCUMULATIVELIMIT
As there are no single quotes, SQL consider CUSTOMERCUMULATIVELIMIT as a number, not a string.
Adding quotes should solve this.
l_rs = JDBCEngine.executeQuery(MessageFormat.format(
" SELECT LIMITS, P.PACKAGE_ID FROM MSTGLOBALLIMITSPACKAGE P ,MSTCUSTOMERPROFILE C WHERE P.PACKAGE_ID = '{0}' AND C.ID_CUST = ? AND C.ID_ENTITY = ? AND C.TYPEUSER = ? AND C.ID_ENTITY = P.ID_ENTITY AND P.PACKAGE_ID NOT LIKE ?",l_arr );
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论