I need to get a value 1 or 0 from DB query which in its turn should do next:
- get some field value from a table
- compare that field value to some literal (defined in query itself)
- if value will not match the literal and query is executed in certain time period (i.e. from 9:00 AM to 10:00 AM) it should return 0, else 1
- it includes multiple result sets (rows) response (see further)
So far I have next thing:
select instr(field, ‘literal’) from table_name where trunc(time) = trunc(sysdate)
which returns 1 if field from table table_name contains ‘literal’ (where clause checks if truncated time in table_name is equal to truncated system time).
What I can’t get is how I can:
- introduce a time constraint (basically, if its from 9:00 AM to 10:00 AM always return 1)
- handle several response rows, meaning that if any of the response rows will return 1 then I need only 1 row with 1 value in it
Thanks in advance.
P.S.: Please comment on the question if something is left vague.
It sounds like you want a CASE statement. It would be helpful if you posted the DDL to create the table, some DML to populate the data, and the expected output. You seem to have conflicting requirements about what you want returned if the query is run between 9 and 10:00 am. You say “if … query is executed in certain time period … it should return 0, else 1” initially but then later you say “if its from 9:00 AM to 10:00 AM always return 1”). My guess is that you want something like