Error when using REGEXP_LIKE with DB2 [duplicate] - sql

This question already has answers here:
Regular Expressions in DB2 SQL
(5 answers)
Closed 5 years ago.
I'm attempting what I thought was a pretty straight-forward SQL statement. I'm trying to use a REGEX expression to only grab records that have a name consisting of only 3 numbers.
However, I'm getting an error and I can't figure out why. Because it's DB2, there aren't nearly as many examples to draw from (as there would be with Postgres, for example), so I'm stuck.
Can anyone see what's wrong?
SELECT
ia.ID
,ia.DESCRIPTION
FROM INVENTORY.ACTIVITIES ia
WHERE
REGEXP_LIKE(ia.NAME, '[0-9]{3}')
Error:
[IBM][CLI Driver][DB2/LINUXX8664] SQL0104N An unexpected token ")" was found following "(ia.NAME,'[0-9]{3}')". Expected tokens may include: "<interval_qualifier>". SQLSTATE=42601.

Your code should compile. It doesn't do what you want though. You need markers for the beginning and end of the string:
SELECT ia.ID, ia.DESCRIPTION
FROM INVENTORY.ACTIVITIES ia
WHERE REGEXP_LIKE(ia.NAME, '^[0-9]{3}$')
My best guess for your error is a hidden character.

Related

decipher this postgresql syntax? [duplicate]

This question already has answers here:
How can I comment special \ commands in PostgreSQL's psql commandline tool?
(5 answers)
Closed 8 years ago.
I have a query in an excel file that I inherited from the previous user/creator of the tool. The external connection is to a PostgreSQL database. Here's the line of script that I need to decipher so that I can hopefully adjust the date range for the query:
with
icon_date as (select max(icon.date::date)/* '1/1/2014'::date*/ as icon_date from pmm.icon)
...
pmm is the schema and .icon is the table name
My specific question is what this part means:
/* '1/1/2014'::date*/
I have no clue what surrounding a date::data type with /* */ would do in the first part of the query. Any ideas? I can post more of query if that would help.
That is just a comment and it will be ignored.
There are (at least) two ways to put comments into SQL:
everything after -- until end of line
everything between /* and */ (even spanning lines)
My guess is that this is code left over from testing, where instead of the max you would select some fixed date (because it is faster, or data was missing).

How to Check the given string is a reserved keyword in sql server [duplicate]

This question already has answers here:
Check if string is SQL Server Reserved Keywords or not
(3 answers)
Closed 8 years ago.
How to check whether the given string is a reserved keyword in sql server.
I checked a lot in google ,but i didn't find one!!
for eg: If i am giving the input String as 'Order',sql statement should
return whether it is reserved keyword.
Is there any built-in stored procedures or function to do this? Any help would be appreciated.
There is no built-in function to do that.
Here is the list of the known identifiers.
http://technet.microsoft.com/en-us/library/ms189822.aspx
I suggest to put these in an table and use it in a function / stored procedure.

What does a colon (':') mean in SQL syntax? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
What does the colon sign “:” do in a SQL query?
Simple SQL question:
What does : stand for?
For example:
SELECT * FROM myTable
WHERE Employee_column = :P_EmplId;
The : isn't exactly easy to google when you don't know what this is called. Even searching here didn't help. I'm using Oracle 11g if that makes any difference.
It is a bind variable:
A placeholder in a SQL statement that must be replaced with a valid
value or value address for the statement to execute successfully. By
using bind variables, you can write a SQL statement that accepts
inputs or parameters at run time. The following example shows a query
that uses v_empid as a bind variable:
Most likely you took the query from a template. It is meant to be processed with php's MDB2 sql framework. The ":" (colon) signals a placeholder in the statement, meant to be replaced when the query is executed.

SQL Injection attempt, what does this query attempt to do? [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Site has been hacked via SQL Injection
Looks like one of my websites had a hacker attempt on it, my reports showed the following querystring data attempted:
QUERY_STRING = ID=-999.9%20UNION%20ALL%20SELECT%200x31303235343830303536,0x31303235343830303536,0x31303235343830303536,0x31303235343830303536,0x31303235343830303536,0x31303235343830303536,0x31303235343830303536,0x31303235343830303536,0x31303235343830303536,0x31303235343830303536,0x31303235343830303536,0x31303235343830303536,0x31303235343830303536,0x31303235343830303536,0x31303235343830303536,0x31303235343830303536,0x31303235343830303536,0x31303235343830303536,0x31303235343830303536,0x31303235343830303536-
It failed because any integer parameter I always cast to an integer so you get mismatch errors if anything like this is tried (classic ASP). But I'm confused what the query above is attempting? It doesn't look like anything I've seen before.
take a look at:
Site has been hacked via SQL Injection
at a first look a guess it was some automatic tool doing some blind sql injection.

IS vs AS keywords for PL/SQL Oracle Function or Procedure Creation [duplicate]

This question already has answers here:
What is the difference between "AS" and "IS" in an Oracle stored procedure?
(6 answers)
Closed 9 years ago.
I have been trying to find out what the difference is between the IS and AS keywords in PL/SQL when creating an Oracle function or procedure.
I have searched and have been unable to find any information on this. Does anyone know the difference?
I've never known there to be a difference. The Oracle documentation implies that they are synonyms:
The function body begins with the keyword IS (or AS) and ends with the keyword END followed by an optional function name.
Same as DISTINCT and UNIQUE in select statements.
i.e, there is no material difference between 'IS' and 'AS'.
Backwards compatibility and meeting standards