Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL function Instr()

I am having a column named DP as shown:

 07-APR-2011
 12-APR-2011
 26-APR-2011

Now to retrieve the query for selecting the payments made in the month of april i came across a query

select * from payments where instr(dp,'APR')<>0

Okay , i am well acquainted with INSTR function and > sign , but cant interpret the logic with<> sign here !

[UPDATE]

i am also aware that <> is equivalent of != . But my point is we could have used
instr(dp,'APR') instead of doing instr(dp,'APR')<>0

like image 253
HalfWebDev Avatar asked Nov 28 '25 17:11

HalfWebDev


1 Answers

<> means "is not equal to". You can also write !=, if you prefer.

instr(dp,'APR') returns zero if 'APR' is not a substring of dp, so instr(dp,'APR')<>0 means "'APR' is a substring of dp". It could also be written as dp LIKE '%APR%'.

Update for updated question:

But my point is we could have used instr(dp,'APR') instead of doing instr(dp,'APR')<>0

No, you couldn't have. Some dialects of SQL treat zero as "false" and other integers as "true", but Oracle does not do this. It treats integers and Booleans as separate types, and does not implicitly convert between them. WHERE 0 is not a valid WHERE-clause.

like image 89
ruakh Avatar answered Nov 30 '25 08:11

ruakh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!