Issues with a query on the AS/400 with LIKE clause - sql

We are using Hibernate to connect to AS/400. We are having issues with a query on the AS/400
with the LIKE clause.
The following error is shown:
java.sql.SQLException: [SQL0131] Operands of LIKE not compatible or not valid
My query is its auto generated by Hibernate:
select tab_parame0_.C1IMCD as C1_560_, tab_parame0_.C1NINB as C2_560_,
tab_parame0_.C1JXCD as C3_560_, tab_parame0_.C1HLTX as C4_560_, tab_parame0_.C1HMTX as C5_560_,
tab_parame0_.C1HDST as C6_560_, tab_parame0_.C1NGNB as C7_560_, tab_parame0_.C1NJNB as C8_560_,
tab_parame0_.C1NFNB as C9_560_, tab_parame0_.C1NHNB as C10_560_, tab_parame0_.C1HCST as C11_560_
from RYC1REP tab_parame0_
where lower(tab_parame0_.C1HLTX) like lower(?)
order by tab_parame0_.C1IMCD asc
fetch first 10 rows only

SQL0131 indicates a type mismatch.
What datatype is tab_parame0_.C1HLTX? What datatype is your query parameter?
Please include your HQL/JPQL query source code for comparison.
You may have to set up an SQL trace to see exactly what the AS/400 is receiving.
See How do I obtain trace information from my Java program using the Toolbox?
I recommend you change LIKE LOWER(:parameter) to LIKE :parameter in your source query and use .toLowerCase() when you set the parameter and see how that works.

Related

select globalmap using tDBinput with Talend give the error: Invalid character constant

I have to remove the accents from the person's name, but I cannot apply the function in Talend while it works in SQL oracle.
this query works in my tDBInput component :
"SELECT '"+((String)globalMap.get("copyOfSORTIE.NOM"))+"' as nom_nom_compl,
'"+((String)globalMap.get("copyOfSORTIE.ENTETE"))+"' entete
FROM DUAL"
However, when I want to add the convert function, it doesn't work
this query does not work :
"SELECT '"+((String)globalMap.get(CONVERT("copyOfSORTIE.NOM",'US7ASCII')))+"' as nom_nom_compl,
'"+((String)globalMap.get("copyOfSORTIE.ENTETE"))+"' entete
FROM DUAL"
In my talend :
I am getting this error
What is the syntax for it to work?
Thank you!
Two things there :
I don't know the CONVERT method, but I can see that you are applying it to the key of your globalMap variable , and not the value (as if you wanted to convert "myKey" and not "myValue" which is attached to the key). Are you sure this is what you want to achieve ? if not, the syntax should be something similar to "SELECT CONVERT('"+((String)globalMap.get("copyOfSORTIE.NOM"))+"','US7ASCII') "
A useful java method implemented in talend is TalendString.removeAccents("") that you can apply directly on your talend variable, thus not using a SQL method.

Why does my online SQL editor not understand group_concat_max_len?

I don't have extensive experience in sql but I know basic.
I use online sql executor to receive the json file which will be prodiced from this sql query.
SET group_concat_max_len=18446744073709547520;
SELECT
CONCAT(
'[',
GROUP_CONCAT(
JSON_OBJECT(
'id',messages.message_id,
'mailing_list_url',messages.mailing_list_url,
'type_of_recipient',messages_people.type_of_recipient,
'email_address',messages_people.email_address,
'message_body',messages.message_body,
'is_response_of',messages.is_response_of
) SEPARATOR ',\r'),
']') AS list
FROM messages
LEFT JOIN messages_people
ON messages.message_id = messages_people.message_id
AND messages.mailing_list_url = messages_people.mailing_list_url
WHERE email_address IN ('dr#gorsvet.kz', 'mathews#uk2.net', 'd.jentsch#fu-berlin.de', 'atul.soman#microfocus.com', 'kkrugler_lists#transpac.com', 'hcorg#minions.org.pl', 'bruno.ronchetti#mac.com', 'christophe.thiebaud#sap.com', 'kc.baltz#copart.com', 'havanki4j#gmail.com', 'joseph.obernberger#ngc.com', 'goran#roseen.se', 'hboutemy#apache.org', 'johann#gyger.name', 'fredrik#jonson.org', 'jose-marcio.martins#mines-paristech.fr', 'dmytro.kostiuchenko#gmail.com', 'jochen.wiedmann#softwareag.com', 'guyskk#qq.com', 'alejandroscandroli#gmail.com', '1983-01-06#gmx.net', 'jstrayer#proofpoint.com', 'daniel#degu.cl', 'hontvari#flyordie.com', 'david#andl.org', 'gholmes#pinsightmedia.com', 'dennis.geurts#luminis.eu', 'carlspring#gmail.com', 'jozef.koval#protonmail.ch', 'gabriele.ctn#gmail.com', 'ashish.disawal#evivehealth.com', 'aarslan2#anadolu.edu.tr', 'kshukla#yahoo-inc.com', 'alex.huang#gmail.com', 'markus#openindex.io', 'marohn#sipgate.de', 'ea#apache.org', 'krzysztof.szalast#gmail.com', 'kfoskey#tpg.com.au', 'krauss#in.tum.de', 'kenhans#hotmail.co.uk', 'jokin.c#odeian.com', 'eitch#eitchnet.ch', 'm.kristian#web.de', 'bob.sandiford#sirsidynix.com', 'asandstrom2#eastlink.ca', 'kelly#apache.org', 'antony.blakey#linkuistics.com.au', 'ashawki#hotmail.com', 'h.klocker-mark#tsn.at');
However from the first line I receive error.
As instructions are not friendly for me please can you help me how could I take the final file?
I had no clue that there are such things as online sql executors. Basically SQL injections as a service, nice.
Anyways, the command:
SET group_concat_max_len=18446744073709547520;
is not part of the official SQL standard and specific to the database server you are using (here MYSQL). From the manual for group_concat_max_len:
The maximum permitted result length in bytes for the GROUP_CONCAT() function. The default is 1024.
For this very reason a "online SQL executor" (wow, I am still puzzled) won't be able to run this. Anyways if you need this, you probably won't get around setting up a MYSQL server yourself. Or you could just use a container.

Why this simple query is failing in a mule flow?

I have to make some changes in a existing mule flow with little knowledge and although I've spent some days reading online documentation and possible solutions to this, I cannot figure out why this query is failing, as I also have more dynamic queries in my flow with #[xxx] parameters. The query is as follows:
select times from user_request where
ip_address=SUBSTR(#message.inboundProperties.MULE_REMOTE_CLIENT_ADDRESS],2,INSTR(#[message.inboundProperties.MULE_REMOTE_CLIENT_ADDRESS], ':')-2)
and request_date=CAST(CURRENT_DATE as varchar2(8))
And the error I got is:
Message : Index: 0
(java.lang.IndexOutOfBoundsException). Payload :
{fecha_solicitud=2016-06-22, moneda=USD, client_id=RIVERA,
user_ip=127.0.0.1, request_times=0} Payload Type :
java.util.LinkedHashMap Element :
/OANDAFlow/processors/3 # oanda:oanda.xml:126 Element XML :
select times from user_requestwhere
ip_address=SUBSTR(#[message.inboundProperties.MULE_REMOTE_CLIENT_ADDRESS],2,INSTR(#[message.inboundProperties.MULE_REMOTE_CLIENT_ADDRESS],
':')-2)and request_date=CAST(CURRENT_DATE as
varchar2(8))>
Note: The transformation to varchar of the date is because the column request_date is varchar.
I've tried this query directly in the Oracle SQL developer replacing #[message.inboundProperties.MULE_REMOTE_CLIENT_ADDRESS]
with and example like /127.0.0.1:55406 and it worked fine so why through mule is failing???
In the first: #message.inboundProperties.MULE_REMOTE_CLIENT_ADDRESS] you are missing a [
One of the fields in your query expects a string value try to put a single quote..it would work ,
Try this
select times from user_request where
ip_address=SUBSTR('#message.inboundProperties.MULE_REMOTE_CLIENT_ADDRESS]',2,'INSTR(#[message.inboundProperties.MULE_REMOTE_CLIENT_ADDRESS]', ':')-2)
and request_date=CAST(CURRENT_DATE as varchar2(8))

How to convert SOQL query to SQL query?

I am working on SQL query, I have pre-created SOQL query, I am looking for a way to convert it to SQL query. The query is:
SELECT CronJobDetail.Name, Id, CreatedDate, State
FROM CronTrigger
WHERE CronjobDetail.JobType = 'bla bla'
AND CronJobDetail.Name LIKE '%bla bla2%'
But It does not run on terminal when I try to create monitoring script in Ruby. The error that I get:
(Got exception: INVALID_FIELD: No such relation 'CronJobDetail' on
entity 'CronTrigger'. If you are attempting to use a custom field, be
sure to append the '__c' after the custom field name. Please reference
your WSDL or the describe call for the appropriate names. in
/Users/gakdugan/.rvm/gems/ruby-1.9.3-p547/gems/restforce-2.2.0/lib/restforce/middleware/raise_error.rb:18:in
`on_complete'
Do you have any idea how can I fix it and make it run on SQL?
You are trying to access a relation without adding it to your FROM clause. Alternatively, if that's a custom field name, then do what the error message suggests you to do (add __c after the custom field name).
You probably want to do something like this:
SELECT CronJobDetail.Name, CronTrigger.Id, CronTrigger.CreatedDate, CronTrigger.State
FROM CronTrigger
INNER JOIN CronJobDetail ON CronJobDetail.id = CronTrigger.foreign_id // this you have to do yourself
WHERE CronjobDetail.JobType = 'bla bla'
AND CronJobDetail.Name LIKE '%bla bla2%'

ActiveRecord where clause error

I'm a newbie to rails.I have a model called OfflineExport. In the table I have data like this
#<OfflineExport id: 2,
parameters:
{"project_id"=>"3",
"type"=>"submissions",
"filters"=>{"task_type"=>"",
"corrections"=>"", "grade"=>"",
"min_duration"=>"", "after"=>"",
"max_duration"=>"", "reviews"=>"",
"before"=>""},
"send_email"=>"true",
"options"=>{"offline_record_id"=>2}}>
Am trying to fetch parameters["project_id"] in where clause like
OfflineExport.where("parameters[project_id] = '3'")
But am getting error like:
ActiveRecord::StatementInvalid: PGError: ERROR: cannot subscript type text because it is not an array
can anyone help me in solving this?
It seems that you have a serialized column in your model. Something like this: serialize :parameters. This means the data is stored in the database not in an easily readable format, which leads that you can not query on it. Same as here.
Solution: extract the field you want to query on, and make a column for it.