Facing issue while running select query on DB2 - sql

I'm querying a DB2 table (STG_TOOL) with 2 columns - T_L_ID - Integer, Name - VARCHAR(20).
SELECT T_L_ID, Name FROM STG_TOOL;
The query returns answer. However, the below query gives error.
SELECT T_L_ID, RTRIM(Name) FROM STG_TOOL;
This query gives error at 78th row.
DB2 Database Error: ERROR [42815] [IBM][DB2] SQL0171N The data type,
length or value of the argument for the parameter in position "1" of
routine "SYSIBM.RTRIM" is incorrect. Parameter name: "". 1 0
The reason identified is that Name in 78th row has a replacement character - '�'.
Even, the same query with a where clause gives us the error.
SELECT T_L_ID, RTRIM(Name) FROM STG_TOOL WHERE T_L_ID = 78;
The sample date on 78th rows is T_L_ID = 1040 & Name = 'test�'
The above mentioned error re-occurs for the above query.
What does the error implies? How can this be handled/solved?
Adding details to the post:
Version: DSN11010 (version 11)
OS: z/OS
Encoding: Unicode
Toad for DB2 is being used for querying. Toad version - 5.5

Related

AWS Athena: Error parsing field value and unexpected query results

I have the following table schema prepared by AWS glue
When I query the table using SELECT * FROM "vietnam-property-develop"."sell" limit 10;, it throws an error:
HIVE_BAD_DATA: Error parsing field value '{"area":"85
m²","date":"14/01/2020","datetime":"2020-01-18
00:42:28.488576+00:00","address":"Quan Hoa - Cầu Giấy","price":"20
Tỷ","cat":"Bán nhà mặt
phố","lon":"105.7976502","avatar":"","id":"24169794","title":"Chính
chủ cần bán nhà mặt phố nguyễn văn huyên Quan Hoa Cầu Giấy, 2 tầng, dt
85m2. LH 0903233723","lat":"21.0376771","room":"0"}' for field 4:
org.openx.data.jsonserde.json.JSONObject cannot be cast to
java.lang.Double
Then I tired to just query the title column by using SELECT title FROM "vietnam-property-develop"."sell" limit 10;
It returns result which I didn't expect. It seems that the query return the whole json files instead of just the title column. And the number of rows is 4 but not 10 no matter how I modify the query.

Sybase Database Error: Invalid data conversion

I need help with this Query, I'm making some calculations based on some results, but I'm receiving the following error:
Sybase Database Error: Invalid data conversion.
The query is as follows:
SELECT
DC.DIM_DATE.DATE_ID,
DC.DIM_E_RAN_UCELL.RBS_ID,
(SUM(DC.DC_E_RAN_UCELL_RAW.pmSumBestDchPsIntRabEstablish)+SUM(DC.DC_E_RAN_UCELL_RAW.pmSumFachPsIntRabEstablish)+SUM(DC.DC_E_RAN_UCELL_RAW.pmSumBestPsHsAdchRabEstablish)+SUM(DC.DC_E_RAN_UCELL_RAW.pmSumBestPsEulRabEstablish))/720 AS '3G_DATA_ERLANG',
(SUM(DC.DC_E_RAN_UCELL_RAW.pmSumBestCs12Establish)+SUM(DC.DC_E_RAN_UCELL_RAW.pmSumBestAmr12200RabEstablish)+SUM(DC.DC_E_RAN_UCELL_RAW.pmSumBestAmr7950RabEstablish)+SUM(DC.DC_E_RAN_UCELL_RAW.pmSumBestAmr5900RabEstablish)+SUM(DC.DC_E_RAN_UCELL_RAW.pmSumBestAmr4750RabEstablish)+SUM(DC.DC_E_RAN_UCELL_RAW.pmSumBestAmrWbRabEstablish)+SUM(DC.DC_E_RAN_UCELL_RAW.pmSumBestAmrNbMmRabEstablish))/720 AS '3G_SPEECH_ERLANG',
(100*(SUM(DC.DC_E_RAN_UCELL_RAW.pmTotNoRrcConnectReqCsSucc)/(1+SUM(DC.DC_E_RAN_UCELL_RAW.pmTotNoRrcConnectReqCs)-SUM(DC.DC_E_RAN_UCELL_RAW.pmNoLoadSharingRrcConnCs))*(SUM(DC.DC_E_RAN_UCELL_RAW.pmNoRabEstablishSuccessSpeech)+SUM(DC.DC_E_RAN_UCELL_RAW.pmNoRabEstablishSuccessCs64)+SUM(DC.DC_E_RAN_UCELL_RAW.pmRabEstablishEcSuccess))/(SUM(DC.DC_E_RAN_UCELL_RAW.pmRabEstablishEcAttempt)+SUM(DC.DC_E_RAN_UCELL_RAW.pmNoRabEstablishAttemptSpeech)+SUM(DC.DC_E_RAN_UCELL_RAW.pmNoRabEstablishAttemptCs64)-SUM(DC.DC_E_RAN_UCELL_RAW.pmNoDirRetryAtt)))) AS '3G_CSSR_CS'
FROM
DC.DIM_DATE,
DC.DIM_TIME,
DC.DIM_E_RAN_UCELL,
DC.DC_E_RAN_UCELL_RAW
WHERE
(DC.DC_E_RAN_UCELL_RAW.HOUR_ID=DC.DIM_TIME.HOUR_ID and DC.DC_E_RAN_UCELL_RAW.MIN_ID=DC.DIM_TIME.MIN_ID)
AND (DC.DC_E_RAN_UCELL_RAW.DATE_ID=DC.DIM_DATE.DATE_ID)
AND (DC.DC_E_RAN_UCELL_RAW.OSS_ID=DC.DIM_E_RAN_UCELL.OSS_ID)
AND (DC.DC_E_RAN_UCELL_RAW.RNC=DC.DIM_E_RAN_UCELL.RNC_ID)
AND (DC.DC_E_RAN_UCELL_RAW.UtranCell=DC.DIM_E_RAN_UCELL.UCELL_ID)
AND
(
DC.DIM_DATE.DATE_ID IN ('2017-08-14')
AND
DC.DIM_E_RAN_UCELL.RBS_ID IN ('DN1U0441')
)
GROUP BY
DC.DIM_DATE.DATE_ID,
DC.DIM_E_RAN_UCELL.RBS_ID
The problem is with the last row of the SELECT statement, without it the result is this:
DATE_ID RBS_ID 3G_DATA_ERLANG 3G_SPEECH_ERLANG
8/14/2017 DN1U0441 421.8541 33.5055
When is included I got this error:
Lookup Error - Sybase Database Error: Invalid data conversion
Any Help? Is Sybase ASE DataBase

Not able to run SQL queries in AS400, run into Invalid Token errors

In AS400, how can i perform arithmetic operations (like +, -) on fields.
For the query Select id, sum(field1+field2) as Total from table
group by id, getting the following error msg in German "[IBM][System
i Access ODBC-Treiber][DB2 für i5/OS]SQL0104 - Token & ungültig.
Gültige Token: + - AS <IDENTIFIER>." English Translation is something
like "[IBM] [System i Access ODBC Driver] [DB2 for i5/OS] SQL0104 -
Token <END Instruction> invalid. Valid tokens: CL AS IN LOG OUT DATA
<identifier>."
For the query Select count(*) from (select distinct field1 from table where field2="abc", getting the following error msg "[IBM][System i Access ODBC-Treiber][DB2 für i5/OS]SQL0104 - Token <ENDE DER ANWEISUNG> ungültig. Gültige Token: AS CL IN LOG OUT DATA <IDENTIFIER>."
For a query with sub-query got the following error msg
"[IBM][System i Access ODBC-Treiber][DB2 für i5/OS]SQL0104 - Token & ungültig. Gültige Token: < > = <> <= !< !> != >= ¬< ¬> ¬= IN NOT."
Could someone please tell me what's wrong with my sql queries.
TABLE is a reserved word. SQL Reference: Reserved schema names and reserved words.
Single quotes escape a string literal
Double quotes escape a reserved word (similar to brackets in TSQL)
SQL Reference: Identifiers
The queries could be re-written as:
SELECT ID, SUM(FIELD1 + FIELD2) AS TOTAL FROM "TABLE" GROUP BY ID
SELECT COUNT(*) FROM (SELECT DISTINCT FIELD1 FROM "TABLE" WHERE FIELD2 = 'ABC')
UPDATE
DB/2 for i does not support your method of numeric to character conversion or the type of character comparison used in your LIKE query.
The query can be re-written as:
SELECT eds, SUM(INT(sds)) AS totalh
FROM tbl1
WHERE eds BETWEEN 20130500 AND 20130599
AND siteds IN (
SELECT DISTINCT site
FROM tbl2
WHERE H_04 IN ('1234') AND PERIOD = 201305
)
GROUP BY eds
ORDER BY eds
You may need to use DEC instead of INT depending upon the definition of field sds.
SQL Reference:
- INT
- DEC
- BETWEEN
Is the table's name really 'table'?
Odd as it seems, if I use the SQL statement you indicated as is, I get the same error... but if I change 'table' to 'table1', it just complains that it can't find 'table1'.

DB2 query error during the retrieval of a CLOB field

From Java I am doing the following query on DB2:
SELECT * FROM PRV_PRE_ACTIVATION WHERE TRANSACTION_ID = ?
The field TRANSACTION_ID is a VARCHAR of length 32. I set the parameter in the preparedStatement using the setString method.
I get the error:
com.ibm.db2.jcc.am.SqlSyntaxErrorException: DB2 SQL Error: SQLCODE=-270, SQLSTATE=42997, SQLERRMC=63, DRIVER=3.59.81
at com.ibm.db2.jcc.am.dd.a(dd.java:676)
at com.ibm.db2.jcc.am.dd.a(dd.java:60)
at com.ibm.db2.jcc.am.dd.a(dd.java:127)
at com.ibm.db2.jcc.am.bn.c(bn.java:2546)
at com.ibm.db2.jcc.am.bn.d(bn.java:2534)
at com.ibm.db2.jcc.am.bn.a(bn.java:2026)
at com.ibm.db2.jcc.t4.cb.g(cb.java:140)
at com.ibm.db2.jcc.t4.cb.a(cb.java:40)
at com.ibm.db2.jcc.t4.q.a(q.java:32)
at com.ibm.db2.jcc.t4.rb.i(rb.java:135)
at com.ibm.db2.jcc.am.bn.gb(bn.java:1997)
at com.ibm.db2.jcc.am.cn.pc(cn.java:3009)
at com.ibm.db2.jcc.am.cn.b(cn.java:3786)
at com.ibm.db2.jcc.am.cn.bc(cn.java:678)
at com.ibm.db2.jcc.am.cn.executeQuery(cn.java:652)
Where the sqstate means "Capability is not supported by this version of the DB2 application requester, DB2 application server, or the combination of the two." But I don't use any strange functionality.
I have tried using an squ client the query:
SELECT * FROM PRV_PRE_ACTIVATION where transaction_id='A'
And it goes ok.
What is the cause of the problem?
UPDATE: The code where the statement is prepared:
s = con.prepareStatement(sSQL,
ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE);
Try changing to a specified list of columns in the select list -- my guess is you have a user defined column type (or some other type) which is not supported by your driver. For example, does the statement
SELECT TRANSACTION_ID FROM PRV_PRE_ACTIVATION WHERE TRANSACTION_ID = ?
work? If so then start adding columns in and you will find the problem column.
I've came across this problem lately, and after some searching on web, I've came across this link:
DB2 SQL error: SQLCODE: -270, SQLSTATE: 42997, SQLERRMC: 63
, which specifies this:
A column with a LOB type, distinct type on a LOB type, or
structured type cannot be specified in the select-list of an
insensitive scrollable cursor.
With help from an colleague, we came to this conclusion:
1, Q: When will you get this "SQLCODE=-204, SQLSTATE=42704" exception?
A: When a scrollable PreparedStatement is prepared & executed, yet there are [B|C]LOB fields exist in the select list. e.g.:
String strQuery = "SELECT NUMBER_FIELD, CHAR_FIELD, CLOB_FIELD FROM TABLE_NAME WHERE CONDITION IS TRUE;"
Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, REsultSet.CONCUR_READ_ONLY);
rs = stmt.executeQuery(strQuery); //and this exception will be thrown here
2, Q: So what's the solution if we want to get rid of it when [B|C]LOB fields are queried?
A: Try to use ResultSet.TYPE_FORWARD_ONLY while creating the query statement.e.g.:
stmt = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
Or simply try this one:
stmt = conn.createStatement();
Note that the same rules apply to conn.prepareStatement() too. You may refer to Java API doc for more information.

Advantage Database 8.1 SQL IN clause

Using Advantage Database Server 8.1 I am having trouble executing a successful query. I am trying to do the following
SELECT * FROM Persons
WHERE LastName IN ('Hansen','Pettersen')
To check for multiple values in a column. But I get an error when I try to execute this query in Advantage.
Edit - Error
poQuery: Error 7200: AQE Error: State = 42000; NativeError = 2115; [iAnywhere Solutions][Advantage SQL Engine]Expected lexical element not found: ( There was a problem parsing the
WHERE clause in your SELECT statement. -- Location of error in the SQL statement is: 46
And here is the SQL i'm executing
select * from "Pat Visit" where
DIAG1 IN = ('43644', '43645', '43770', '43771', '43772', '43773', '43774',
'43842', '43843', '43845', '43846', '43847', '43848', '97804', '98961',
'98962', '99078')
Done
Does anyone have any Idea how I could do something similar in advantage that would be efficient as well?
Thanks
You have an extraneous = in the statement after the IN. It should be:
select * from "Pat Visit" where
DIAG1 IN ('43644', '43645', <snip> )