I'm running a rather large query (~83k results) through my Java Application that is producing the following error:
java.sql.SQLException: [SQL0901] SQL system error. Cause . . . . . : An SQL system er
ror has occurred. The current SQL statement cannot be completed successfully. The error will not prevent other SQL statements from being processed. Previous messages may indicate that there is a problem with the SQL statement and SQL did not correctly diagnose the error. The previous message identifier was MCH1210. Internal error type 3002 has occurred. If precompiling, processing will not continue beyond this statement. Recovery: See the previous messages to determine if there is a problem with the SQL statement. To view the messages, use the DSPJOBLOG command if running interactively, or the WRKJOB command to view the output of a precompile. An application program receiving this return code may attempt further SQL statements. Correct any errors and try the request again.
From this page, it appears as though Error SQL0901 means I may have a Driver issue.
Digging into the MCH1210 error, yielded this StackOverflow question so I thought that maybe I would have the same issue, however there are a few differences.
When I attempt to run my query in the System iNavigator, it works just fine. When it runs in my application, I get the above error.
This is my query:
SELECT
DWVNDN, DWINVN, DWDTEI, DWRTPE, DWINAM, DWCHKN, DWJCDE
FROM HSDATA4.DWRECAP
WHERE DWDTEI > 20180901 AND (DWRTPE = 2 OR DWRTPE = 3) AND DWINVN IN
(SELECT DW.DWINVN
FROM HSDATA4.DWRECAP DW
INNER JOIN HSDATA4.FXVNDCP FX ON DW.DWVNDN = FX.FXVNDN
WHERE DW.DWRTPE = 1 AND DW.DWDTEI BETWEEN 20180904 AND 20190904)
ORDER BY DWDTEI ASC, DWVNDN ASC;
I should note that when changing the inner query from SELECT ... to SELECT COUNT(*) to get a tally of records coming back, the returned value is 83314, so the main query is using over 83k parameters.
I was originally going to ignore it because I was getting results, however it appears that some of the results end up getting cut off so I don't know how to proceed.
Also, if you hate the column names in the database...so do I. It wasn't my choice...
Doesn't the inner join give you everything that you need?
SELECT
DW.DWVNDN, DW.DWINVN, DW.DWDTEI, DW.DWRTPE, DW.DWINAM, DW.DWCHKN, DW.DWJCDE
FROM HSDATA4.DWRECAP DW
INNER JOIN HSDATA4.FXVNDCP FX ON DW.DWVNDN = FX.FXVNDN
WHERE DW.DWRTPE = 1 AND DW.DWDTEI BETWEEN 20180904 AND 20190904
AND DW.DWDTEI > 20180901 AND DW.DWRTPE IN (2,3)
ORDER BY DW.DWDTEI ASC, DW.DWVNDN ASC;
How about an outer join
SELECT
DW2.DWVNDN, DW2.DWINVN, DW2.DWDTEI, DW2.DWRTPE, DW2.DWINAM, DW2.DWCHKN, DW2.DWJCDE
FROM
(( HSDATA4.DWRECAP DW INNER JOIN HSDATA4.FXVNDCP FX
ON DW.DWVNDN = FX.FXVNDN AND DW.DWRTPE = 1
AND DW.DWDTEI BETWEEN 20180904 AND 20190904)
LEFT OUTER JOIN HSDATA4.DWRECAP DW2
ON DW.DWVNDN = DW2.DWVNDN
AND DW2.DWDTEI > 20180901 AND DW2.DWRTPE in (2,3))
The inner join selects the initial invoice type of 1 between your valid date ranges and the left outer join selects matching invoice numbers where there was a modification
Related
I am trying to run few SQL queries using Java Spark libraries.
All SQLs are running fine except one:
(SELECT CMM.BENEFIT, (length(CMM.HIERARCHY) - length(replace(CMM.HIERARCHY,'>','')) + 1) BNFT_CMPNT_LVL_NBR, LBCX.SERVICE_DEF_TGT_CD, LBCX.SERVICE_DEF_DESC, LBCX.BENEFIT_CMPNT_DESC, LBCX.SERVICE_DEF_TGT_CD, CMM.HIERARCHY FROM EHUB_PROD_RAW.cs90_master_mapping CMM INNER JOIN EHUB_PROD_RAW.wpd_spider_benefit_hierarchy WSBH ON CMM.HIERARCHY = WSBH.HIERARCHY INNER JOIN EHUB_PROD_RAW.legacy_bnft_cmpnt_xref LBCX ON CMM.BENEFIT = LBCX.BENEFIT_CMPNT_NM)
Same query runs fine from SQL Developer!
I am guessing something with hidden char or quotes.
Any guidance please.
You are selecting the same column twice:
( select
cmm.benefit,
( length(cmm.hierarchy) - length(replace(cmm.hierarchy,'>','') ) + 1 ) bnft_cmpnt_lvl_nbr,
lbcx.service_def_tgt_cd,
lbcx.service_def_desc,
lbcx.benefit_cmpnt_desc,
--lbcx.service_def_tgt_cd, <-- this one is duplicated
cmm.hierarchy
from
ehub_prod_raw.cs90_master_mapping cmm
inner join ehub_prod_raw.wpd_spider_benefit_hierarchy wsbh on cmm.hierarchy = wsbh.hierarchy
inner join ehub_prod_raw.legacy_bnft_cmpnt_xref lbcx on cmm.benefit = lbcx.benefit_cmpnt_nm
)
If you need it twice in the result set, then you should use aliases. I think SQL Developer will auto-alias it by appending a _1 to one of the ambiguous columns.
Hibernate (HQL) generated the following SQL for which I inserted the parameters:
select
sum(activity0_.calculated_work) as col_0_0_
, employee2_.id as col_1_0_
, projectele1_.id as col_2_0_
from
activity activity0_
inner join generic_object activity0_1_ on activity0_.id=activity0_1_.id
left outer join project_element projectele1_ on activity0_.project_element_id=projectele1_.id
left outer join employee employee2_ on activity0_.owner_id=employee2_.id
left outer join org_unit orgunit3_ on employee2_.org_unit_id=orgunit3_.id
where
activity0_1_.deleted=0 and
activity0_.client_id=22
group by
employee2_.id order by SUM(activity0_.calculated_work) DESC
Error message: Column 'project_element.id' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
I executed this SQL directly in the SQL Server Studio with the same result. I commented this line:
, projectele1_.id as col_2_0_
The SQL was then accepted by the SQL Server
The table project_element definitely has a column with the name id it is also referenced in the LEFT OUTER JOIN and there this column is not causing an error.
Removing the alias projectele1_ had no effect.
To me this looks like a really simple SQL statement. I cannot imagine what is wrong with it and the error message is not helping at all. Any ideas what could be wrong with the SQL?
Your SQL syntax is wrong.If you add projectele1_.id to group by clause it will work.Only aggregate functions work in select statement with group by clause.Or if you remove projectele1_.id from select it will work fine.
My mistake. I should have read the error message several times. projectele1_id is not in the group by clause. MS SQL does not allow to include such a column into the select list. This seems to be a consistency check.
Too bad though that the usage of HQL leads to such an exception in SQL Server but not in MySQL Server.
so tried to put that SQL code into my java-aplication:
SELECT DISTINCT
StRzImRo.Rohstoff, StRo.Bezeichnung,
CAST (SUM(BwLsImAt.Lieferungen * StRzImRo.Menge * StAt.PROD__REZEPTURGEWICHT / Coalesce(StRz.PARM__BEZUGSGROESSE,1)) AS NUMERIC (9,3)) Rohstoffverbrauch_Gesamt FROM BwLsImAt
JOIN StAt ON (StAt.IntRowId = BwLsImAt.Artikel)
JOIN StRz ON (StRz.IntRowId = StAt.PROD__REZEPTUR)
JOIN StRzImRo ON (StRzImRo.Master = StRz.IntRowId)
JOIN StRo ON (StRzImRo.Rohstoff = StRo.IntRowId)
WHERE StAt.IntRowId > 0
GROUP BY StRzImRo.Rohstoff, StRo.Bezeichnung
-- GROUP BY StRzImRo.Rohstoff, StRzImRo.Menge, StAt.PROD__REZEPTURGEWICHT, Coalesce(StRz.PARM__BEZUGSGROESSE,1)
The code is fully funcional and tested in IBSQL but not working in my java-application.
My app does work properly with other code. I get this error:
org.firebirdsql.jdbc.FBSQLException: GDS Exception. 335544569. Dynamic SQL Error
SQL error code = -104
Token unknown - line 1, column 266
ON
I would be very happy if someone could help me with this problem. Thanks!
P.S.: Sorry for my bad language, but i´m not a native speaker
The error suggests there is an ON in an unexpected place in your query, and as the query itself looks fine, my guess is the problem is with the way you construct the query in your Java application. There might be some whitespace missing in your query.
My guess is that you have something like
query = "SELECT * " +
"FROM table1" +
"JOIN table2 ON " //.....
The missing whitespace will make the SQL:
SELECT * FROM table1JOIN table2 ON ....
For the parser, this is perfectly valid until it encounters the ON token, which triggers the error. Eg the parser identifies it is a SELECT with * (all) columns from table1JOIN with alias table2. During parsing the server doesn't check if the table actually exists, so it doesn't trip over the fact that table1JOIN doesn't exist. That is checked after parsing is successfully completed.
This is HQL query :
SELECT COUNT(s)
FROM Site s JOIN s.topics t
INNER JOIN t.topicExpertAssignment tea
INNER JOIN tea.expert u
INNER JOIN u.userinfo info
WHERE tea.assignedBy.id = 1 AND s.createdBy = tea.expert.id
ORDER BY s.name
when i try to run this HQL query first time , it Generate org.hibernate.exception.SQLGrammerException: could not execute query exception and when i try to run again this query it generates org.hibernate.exception.GenericJDBCEXception: could not execute query exception. without COUNT() the query run successfully. how to resolve this exceptions and thanks in Advance.
Query is incorrect, because ORDER BY references to s.name, and s.name is not one of the items in select list.
Most likely correct solution is to remove ORDER BY s.name. It does not make too much sense to define order when result is one value.
I facing with a strange situation with a sql query on mysql 5.1.41 environment on a Ubuntu machine.
The code follow
SELECT spedizione0_.idspedizione,
spedizione0_.*,
(
SELECT COUNT(n.idnegozio)
FROM negozio n
LEFT JOIN confezione c
ON n.idnegozio = c.idnegozio
AND c.idspedizione = spedizione0_.idspedizione
WHERE n.datainizio <= spedizione0_.dataspedizione
AND n.datafine >= spedizione0_.dataspedizione
OR c.idspedizione != 0
) AS formula5_
FROM orocashgenerico.spedizione spedizione0_
ORDER BY spedizione0_.dataspedizione DESC
In this case the error says : [Err] 1054 - Unknown column 'spedizione0_.idspedizione' in 'on clause'
The only way to run this query is to change the .. on n.idnegozio=c.idnegozio and c.idspedizione=spedizione0_.idspedizione into on n.idnegozio=c.idnegozio and c.idspedizione=12
The most strange things for me is: if i move the and condition to the where clause the query run correctly, of course the results is not what I excepted.
My question is where is the problem?
Is something related to the MySQL version?
It's because spedizione0_ is not found with the scope of your subquery. Try this one,
SELECT spedizione0_.idspedizione, // add additionl columns
COUNT(n.idnegozio) AS formula5_
FROM spedizione spedizione0_
LEFT JOIN confezione c
ON c.idspedizion = spedizione0_.idspedizione
LEFT JOIN negozio n
ON n.idnegozio = c.idnegozio
WHERE (
n.datainizio <= spedizione0_.dataspedizione AND
n.datafine >= spedizione0_.dataspedizione
)
OR c.idspedizione != 0
GROUP By spedizione0_.idspedizione
ORDER BY spedizione0_.dataspedizione DESC
as I can see, you are using the wrong syntax here. When you use a Left Outer join, you cannot mention more than one condition in ON clause.
In your case, you need to use one more Left join clause after that ON clause to join 3rd table which is giving error.