Apache Derby Like clause with boolean expression error - derby

I am trying to run the following query to Apache Derby Embedded DB
select ProjectName , CompaignNumber ,JobNumber from arcproject
where Projectname like '%' OR CompaignNumber like '%' OR JobNumber like '%'
but it creates the following error
ERROR: No authorized routine named 'LIKE' of type 'FUNCTION'
having compatible arguments was found.
Error Code: 30000
I am unable to understand what is the problem.

I suspect that you didn't include the exact syntax of your program in your question, because when I cut-and-pasted your query into Derby it worked fine:
ij> create table arcproject (ProjectName varchar(10),CompaignNumber varchar(10),JobNumber varchar(10));
0 rows inserted/updated/deleted
ij> insert into arcproject values ('a','b','c');
1 row inserted/updated/deleted
ij> select ProjectName , CompaignNumber ,JobNumber from arcproject where Projectname like '%' OR CompaignNumber like '%' OR JobNumber like '%';
PROJECTNA&|COMPAIGNN&|JOBNUMBER
--------------------------------
a |b |c
Remember, when asking a question, it is crucial that you include all the details, including the exact syntax you used, particularly when you are asking about a syntax error.

First thanks for your reply. Now I am sending the every detail(The queries give below are working queries).
First I created the table with the query
CREATE TABLE "APP"."ARCPROJECT"(
PROJECTNAME VARCHAR PRIMARY KEY not null,
COMPAIGNNUMBER VARCHAR default 'NULL',
JOBNUMBER INTEGER default 'NULL',
RESPONSIBLEPERSON VARCHAR not null,
PROJECTSTARTDATE DATE default 'NULL',
PROJECTENDDATE DATE default 'NULL')
Then I inserted the values
insert into "APP"."ARCPROJECT" (PROJECTNAME, COMPAIGNNUMBER, JOBNUMBER, RESPONSIBLEPERSON, PROJECTSTARTDATE, PROJECTENDDATE) values ('proje-1', 'cmp-123', 89, 'person-xyz', '2012-12-8', '2013-12-8');
Then when I try this query it gave me the same error I mentioned above.
select ProjectName , CompaignNumber ,JobNumber, Responsibleperson,ProjectStartDate, projectEndDate
from arcproject
where Projectname like '%' OR CompaignNumber like '%' OR JobNumber like '%' OR Responsibleperson like '%';
Note : When I take only two OR expression (e.g. "where Projectname like '%' OR CompaignNumber like '%'") then it works fine but when I add another one it start showing error message mentioned before.

Thank you for the update; it is clearer now.
What version of Derby are you using? I was unable to run your CREATE TABLE statement as is; I had to make two changes:
1) I had to change "VARCHAR" to "VARCHAR(10)"
2) I had to change "INTEGER default 'NULL'" to "INTEGER default 0"
After I did those two changes, I get the message that you described.
The problem is with the JOBNUMBER column, which you have declared as INTEGER.
You cannot use 'LIKE' on an "INTEGER" column; it only works on strings
If you change your SELECT statement from "JobNumber like '%'" to "JobNumber != 0", then the statement works fine.
I agree that the message is not very clear; I will open an issue at the Derby project to try to improve the message, because I think it could have been much clearer for you.
You can follow the results of that issue here: https://issues.apache.org/jira/browse/DERBY-6020

Related

How to use Nested functions substr(), cast() and Max() in query builder in laravel 8?

I posted this question yesterday but I think it's unclear so I deleted it and posted it again with more details.
In my oracle database I have a USERS table with id_user defined as varchar and this varchar is like this: '145/1' ...... '145/9' so to add a new user I check the maximum value ('145/9') and add 1 to the second part of id_user (after the slash) so that the id_user is '145/10'.
The steps are like this:
First: I'm using substr() to get the second part (after the slash) of all id_user.
Second: I use Cast() to convert it to Int.
Third: I use Max() to get the maximum value of Int numbers.
Finally in my laravel code I use the result of this query(the result is 9) and add 1 to it and insert a new user in the users table with id_user = '145/10' and so on.
This query works fine but I need it in the Query Builder so I am trying a lot of queries but they didn't work.(please help me)
SELECT MAX(CAST(SUBSTR(id_user, INSTR (id_user, '/') + 1) AS INT)) AS Aggregate
FROM "users"
WHERE "ID_USER" LIKE '145/%';
Finally, this query gives me the correct maximum:
DB::table('users')->select(DB::raw('MAX(CAST(SUBSTR(id_user,INSTR(id_user, \'/\') + 1) AS INT)) as max')) ->where('id_user','like','145'.'/%')->get()[0];

How to modify Oracle SQL query to Snowflake

Using Oracle SQL, there is a function, noted below, that will allow you to create a "list" of names, phone numbers, etc., without using
multiple DUAL queries and UNION/UNION ALL to get more than one record.
The query below produces a list in this case of 10 names.
SELECT COLUMN_VALUE USERNAME
FROM TABLE(SYS.DBMS_DEBUG_VC2COLL(
'WARNER,JEFF',
'MALITO,CARL',
'MOODY,JEANNE',
'PHILLIPS,HUGH & KELLY',
'PATSANTARAS,VICTORIA',
'BROWN,ROLAND',
'RADOSEVICH,MIKE',
'RIDER,JACK',
'MACLEOD,LENARD',
'SCOTT,DAN' ))
However, when trying to run this same query in Snowflake, it will not work.
I receive this error: SQL compilation error: Invalid identifier SYS.DBMS_DEBUG_VC2COLL
Is there a "Snowflake version" of this query that can be used?
Here are some options, you can see which works best for you.
This works if you can get your SQL to look similar:
SELECT $1::VARCHAR AS column_value
FROM (VALUES ('WARNER,JEFF'), ('MACLEOD,LENARD'), ('SCOTT,DAN'));
This also works if you can get your list to be in a single string, delimited by a pipe or similar:
SELECT value::VARCHAR AS column_value
FROM LATERAL FLATTEN(INPUT=>SPLIT('WARNER,JEFF|MACLEOD,LENARD|SCOTT,DAN', '|'));
If you have the strings in the format 'a','b' and find it painful to do one of the above, I'd do something like this:
SELECT value::VARCHAR AS column_value
FROM LATERAL FLATTEN(INPUT=>SPLIT(ARRAY_TO_STRING(ARRAY_CONSTRUCT('WARNER,JEFF', 'MALITO,CARL', 'MOODY,JEANNE'), '|'), '|'));
Similar to the above suggestions, you can try this:
SELECT VALUE::VARCHAR as column_name
FROM TABLE(FLATTEN(INPUT => ARRAY_CONSTRUCT('WARNER,JEFF', 'MALITO,CARL', 'MOODY,JEANNE'), MODE => 'array'));

ORA-00923 FROM key word is not specifed

I know this quesion has a lot of answers but to be honest i really can't found any fixes to my issue and i relly don't see what i am doing wrong.
I am trying to insert some data via a select and a few changes, but everytime i get this FROM keyword not found where excepted
I tried to qote it multiple times differently but it didn't worked as well i know my select "Normally" work.
exec :='INSERT INTO TALEND_CONTEXT_GROUP (PROJECT_ID,CONTEXT_NAME,CONTEXT_TYPE,CONTEXT_DESC,ENV_ID,DATE_CREATION,USER_CREATION)
SELECT PROJECT_ID, CONTEXT_NAME, CONTEXT_TYPE, CONTEXT_DESC, '||New_Env_Id||', '||Current_Date||',USER_CREATION
FROM TALEND_CONTEXT_GROUP
WHERE PROJECT_ID = '||Project_Id||'';
EXECUTE IMMEDIATE(exec) ;
Of course the 2 used variable in here are working and returns 2 numbers
I would want it to simply insert nearly the same data in the same table except changing the ENV_ID and the DATE_CREATION
I think you have a , in one of your numbers - better use bind then concatination:
EXECUTE IMMEDIATE 'INSERT INTO TALEND_CONTEXT_GROUP (PROJECT_ID,CONTEXT_NAME,CONTEXT_TYPE,CONTEXT_DESC,ENV_ID,DATE_CREATION,USER_CREATION)
SELECT PROJECT_ID, CONTEXT_NAME, CONTEXT_TYPE, CONTEXT_DESC, :New_Env_Id, :CURRENT_DATE,USER_CREATION
FROM TALEND_CONTEXT_GROUP
WHERE PROJECT_ID = :Project_Id' using New_Env_Id, CURRENT_DATE, Project_Id;
Then again why do you even use dynamic sql? Why not directly:
INSERT INTO TALEND_CONTEXT_GROUP (PROJECT_ID,CONTEXT_NAME,CONTEXT_TYPE,CONTEXT_DESC,ENV_ID,DATE_CREATION,USER_CREATION)
SELECT PROJECT_ID, CONTEXT_NAME, CONTEXT_TYPE, CONTEXT_DESC, New_Env_Id, CURRENT_DATE,USER_CREATION
FROM TALEND_CONTEXT_GROUP
WHERE PROJECT_ID = Project_Id;

please suggest how to update column by replacing multiple '/' in single '/' in string in 10g

IMAGE_PATH(its column name) Such type of value in column given below
sph/images///////30_Fairhall_Court.jpeg
sph/images///8_Furnival_Court.jpeg
sph//images/9_Pennethorne_House.jpeg
rbkc/images/TAVISTOCK_CRESCENT.jpeg
haringey///images///399932thumb.jpg
urbanchoice//images//18190862.jpg
westminster/images//7_Glarus_Court.jpeg
I want to update all row of column where have more then one '/' like as
sph/images/30_Fairhall_Court.jpeg
sph/images/8_Furnival_Court.jpeg
sph/images/9_Pennethorne_House.jpeg
rbkc/images/TAVISTOCK_CRESCENT.jpeg
haringey/images/399932thumb.jpg
urbanchoice/images/18190862.jpg
westminster/images/7_Glarus_Court.jpeg
please suggest how to update column by replacing multiple '/' in single '/'
You can use regexp_replace for this.
select regexp_replace( 'sph/images///////30_Fairhall_Court.jpeg', '(/){2,}','\1' )
from dual
sph/images/30_Fairhall_Court.jpeg
So your update statement would be something like the following:
update yourtable
set filename_column = regexp_replace( filename_column, '(/){2,}','\1' )
where instr(filename_column,'//')>0

Oracle Select where NCLOB is Like some string

I have an Oracle table, and in this table I have a column of type NCLOB. I would like to perform a SELECT LIKE on it like so:
SELECT
*
FROM
T_WEB_TASK_IT
WHERE DBMS_LOB.substr( T_WEB_TASK_IT.ISSUE_DESCRIPTION , 32000, 1)
LIKE '%Turning on the%'
But it isn't working, I get an error saying:
String buffer too small
But I don't understand how can that be, cause I know for a fact that there aren't that many characters in that column for that particular record!
You can use DBMS_LOB.INSTR function to search for strings in the lob. Like this:
SELECT *
FROM T_WEB_TASK_IT
WHERE DBMS_LOB.INSTR( T_WEB_TASK_IT.ISSUE_DESCRIPTION , 'Turning on the') > 0
Apart from DBMS_LOB.INSTR, you could also use Regular Expressions:
SELECT *
FROM T_WEB_TASK_IT
WHERE regexp_like(issue_description, 'Turning on the')

Resources