when i execute the following select statement i am getting the below error.
I am trying to execute the below statement in Oracle server 9.1.
I believe due to this i am getting this error.
I know we can excute the query for single quotes by '%Blondeau D''Uva%'. But i am looking for query which will pass the special character value as parameter.
Kindluy let me know how to escape single quotes in old oracle server
ERROR :
ORA-00933: SQL Command not properly ended
Error at line : 1 Column : 50
Query:
Select * FROM TABLEA where UI_FNAME like q'[%Michael%]' and UI_LNAME like q'[ %Blondeau D'Uva%]';
On oracle the following should work
Select *
FROM TABLEA
where UI_FNAME like '[%Michael%]'
and UI_LNAME like '[ %Blondeau D''Uva%]';
So no duplicate where
And you have to quote the ' between D und Uva
And probably the q before the ' is wrong ... so I have removed it as well.
Ok tried it out with the q operator:
Select *
FROM employees
where first_name like q'[%Michael%]'
and last_name like q'[ %Blondeau D'Uva%]';
No errors no row ...
Two things about your query:
Two times usage of where where there should be just one.
About the second condition. You have used q'[ %Blondeau D'Uva%]' in like clause. I think that won't give you the result you might be looking for. This has nothing to do with your error, but still, it would not hurt to re-check the query.
Try this, this shouldn't run you into any error :
Select * FROM TABLEA
where UI_FNAME like q'[%Michael%]'
and UI_LNAME like q'[%Blondeau D'Uva%]';
Cheers!
As others have tried to give you an answer, but I think you probably need to keep % outside brackets -
Select *
FROM TABLEA
where UI_FNAME like '%[Michael]%'
and UI_LNAME like '%[ Blondeau D''Uva]%';
Related
How do I get the column "count(division)" instead of getting the actual number of counts?
select * from num_taught;
gets me this
select count(division) from num_taught;
gets me this, but I actually want the third column "count(division)" from the previous image
I want to know this because I'm doing this right now:
sql> select * from num_taught as a, num_taught as b
...> where a.count(division) = b.count(division);
Error: near "(": syntax error
but as you can see, there's a syntax error and I think it's because the code is not referencing the "count(division)" columns but actually finding the count instead.
My end goal is to output the "Titles" that have the same "Division" and have the same count(division).
So for example, the end table would have the rows "Chief Accountant", "Programmer Trainee", "Scrivener", "Technician", "Wizard". Since these are the rows that have a match in division and count(division)
Thanks!
What does DESC num_taught return? I am curious how the third column is populated - is it some kind of pseudo-column? You may want try wrapping the column name with [], see: How to deal with SQL column names that look like SQL keywords?
i.e. try:
select [count(division)] from num_taught;
You need to escape your column name using quotes (in case it's Sqlite like you mentioned in the comments).
select "count(division)" from num_taught;
or:
select * from num_taught as a, num_taught as b
where a."count(division)" = b."count(division)";
If you don't you are using the count-function provided by your Database-system.
It's very unusual to name a column like this, it might be either a trap by your tutor or an error while initializing the table in your case.
I think you just want a count(distinct):
select count(distinct division)
from num_taught;
Impala Version: 5.12.2
I need to match string which contains \%, for example, a\%b. In impala shell,I use the following sql for test:
select 'a\\%b' like 'a\\\%b';
The result is right:
sql result
select '\\%' like '\\\%';
I expected the result to be true, but actually I got false:
sql result
I think both \ and % should be escaped in like, so I use '\\\%'. I don't known why the second sql doesn't work, could anyone explain it?
By the way, if I need to match string which contains two slash, for example a\b\c, I tried the flowing sql:
select 'a\\b\\c' like '%\\%\\%';
but the result is false:
sql result
Here,the % is used as wildcard, so I don't escape it. could anyone give a right sql?
Thanks for any advice.
The first result that you are listing does not match with your query, it should be True. Your second query is wrong, you need to escape the backlash as this \\\\
This query should do the job
select 'a\\b\\c' like '%\\\\%\\\\%';
Anyway I would recommend use regex
select regexp_like('a\\b\\c','(.*?)\\\\{1}(.*?)\\\\{1}(.*?)'); -- true
select regexp_like('a\\bc','(.*?)\\\\{1}(.*?)\\\\{1}(.*?)'); -- false
select regexp_like('a\\\\','(.*?)\\\\{1}(.*?)\\\\{1}(.*?)'); -- true
select regexp_like('\\\\','(.*?)\\\\{1}(.*?)\\\\{1}(.*?)'); -- true
select regexp_like('\\b\\c','(.*?)\\\\{1}(.*?)\\\\{1}(.*?)'); -- true
select regexp_like('ab\\','(.*?)\\\\{1}(.*?)\\\\{1}(.*?)'); -- false
To Increase Speed of search in the database, i want to do something like this:
If field TheFieldName (without any space in it) was equal with test then show the record(s)
how can i do it?
This did'nt work for me:
"SELECT * FROM TheTableName WHERE REPLACE(TheFieldName, ' ', '')=test"
Error: Undefined function 'REPLACE' in expression
It seems unlikely to me that replace() is not known in SQL Server (or almost any other database). But, check to be sure you are using the database you think you are.
Your query, as written, does have an error -- because you seem to want test as a string. Does the query really look like this:
SELECT *
FROM TheTableName
WHERE REPLACE(TheFieldName, ' ', '') = 'test';
Note the quotes around 'test'.
This should work.
"SELECT * FROM TheTableName WHERE rtrim(ltrim(TheFieldName))=test"
I am trying to run simple query on Google Bigquery. But each time when I run the query SELECT COUNT(totals.visits) FROM 122443995.ga_sessions_20160817 I get following error
Encountered " "FROM" "FROM "" at line 1, column 29. Was expecting: <EOF>
What could be the possible error in the query syntax?
You probably need to escape the table name. With legacy SQL, you would use square brackets, e.g.:
SELECT COUNT(totals.visits) FROM [122443995.ga_sessions_20160817];
With standard SQL, you would use backticks, e.g.:
SELECT COUNT(totals.visits) FROM `122443995.ga_sessions_20160817`;
For me, using parentheses to surround the clause in FROM solved it for me.
So instead of
SELECT totals FROM t1
use
SELECT totals FROM (t1)
I'm having some trouble understanding WHY a select statement isn't working in a query I'm making.
I've got the SELECT and FROM lines functioning. With just those, ALL results from my selected table are displayed - 517 or so
What I want to do is display results based on a pattern using LIKE - What I have so far
SELECT *
FROM Tbl_ServiceRequestMatrix
WHERE Tbl_ServiceRequestMatrix.[Application/Form] LIKE 'P%';
This returns 0 results - despite the fact that the column selected DOES have entries that start with 'P'
I also tried utilising brackets, see if that was the issue - still displays 0 results:
SELECT *
FROM Tbl_ServiceRequestMatrix
WHERE ((Tbl_ServiceRequestMatrix.[Application/Form])='p%');
Can any one help me understand why my WHERE ** LIKE statement is causing 0 results to be displayed?
The wildcard character in MS Access is (by default) * instead of %:
WHERE Tbl_ServiceRequestMatrix.[Application/Form] LIKE "P*"
LIKE Statement has different parameters in different sql languages.
In MS Access you need * Instead of % in LIKE Statement.