I am building an Oracle APEX application in which journalists can bring in articles, which a director selects for a broadcast, along with a newsreader (who can read the articles if the broadcast is created). I am kind of stuck with the following:
I would like to create an Oracle SQL query which selects the first and last name of a record in the "user" table, when its availability (which is stored in another table, "Beschikbaarheid") meets the given circumstances (user begin time at broadcast day >= broadcast begin time AND user end time at broadcast day <= broadcast end time).
I myself have written the following query.
SELECT voornaam || ' ' || achternaam AS display_value, id AS return_value
FROM Gebruiker
WHERE id NOT IN (SELECT Nieuwslezerselectie.nieuwslezerid FROM Nieuwslezerselectie
WHERE -- other conditions
AND id IN (SELECT gebruikerid
FROM Beschikbaarheid
WHERE (dag = to_char(to_date(:P91_DATUM,'DD-MON-YYYY'),'Day'))
AND (to_date(:P91_BEGINTIJD,'HH24:MI') >= to_date(begintijd,'HH24:MI'))
AND (to_date(:P91_EINDTIJD,'HH24:MI') <= to_date(eindtijd,'HH24:MI'))
);
(Excuse me if you are having trouble reading this, I use Dutch naming. Feel free to ask if something is unclear.)
However, the APEX select list to which this query is linked is not showing anything if the newsreader is available at the time of the broadcast. I think the problem is "Begintijd" and "Eindtijd" are stored as time stamps, as the values should be date-independent (which time stamps are not), but I have no clue how to store them otherwise. As a varchar maybe?
I sincerely hope you have any ideas. Thank you in advance!
Luc
update 1
With help I have rewritten the query, it now looks like this:
AND id IN (SELECT gebruikerid
FROM Beschikbaarheid
WHERE (dag = to_char(to_date(:P91_DATUM,'DD-MON-YYYY'),'Day','NLS_DATE_LANGUAGE=Dutch'))
AND (
to_date('01-01-2000' || ' ' || to_char(to_timestamp(:P91_BEGINTIJD),'HH24:MI'),'DD-MM-YYYY HH24:MI')
BETWEEN
to_date('01-01-2000' || ' ' || to_char(begintijd,'HH24:MI'),'DD-MM-YYYY HH24:MI')
AND
to_date('01-01-2000' || ' ' || to_char(eindtijd,'HH24:MI'),'DD-MM-YYYY HH24:MI')
)
AND (
to_date('01-01-2000' || ' ' || to_char(to_timestamp(:P91_EINDTIJD),'HH24:MI'),'DD-MM-YYYY HH24:MI')
BETWEEN
to_date('01-01-2000' || ' ' || to_char(begintijd,'HH24:MI'),'DD-MM-YYYY HH24:MI')
AND
to_date('01-01-2000' || ' ' || to_char(eindtijd,'HH24:MI'),'DD-MM-YYYY HH24:MI')
)
);
However, I am now getting the ORA-01840: input value not long enough for date format error when trying to access the page. I haven't discovered what causes that error yet. Does anyone have any clues?
update 2
Now I am confused. It turned out I didn't need to_char etc. for my page variables, so I removed those (to_char etc.). Now I am normally send to the correct page, but the last value I entered in the "set these items / with these values" text fields on the previous page, isn't send. This is what I have in these text fields right now:
In this image, P85_BEGINTIJD isn't send. I also switched the values around, but that didn't make a difference. Is there a limit to the amount of values you can send with a request, or something?

Beschikbaarheid? Can you show some sample data? What happens if you run your sub-select on it's own - do you get any rows back. What is the purpose of your firstNOT INstatement, I can't see how it fits your question? - WW.dag? Does theNLS_DATE_LANGUAGEmatch? Note,TO_CHAR(..., 'Day')makes a right-padding with spaces, tryTO_CHAR(..., 'fmDay')- Wernfried Domscheit