I need help with a query Im trying to write, I cant for th life of me think of the code to query a table to search for a specific date...Its bugging the hell out of me!
Any ideas?
Printable View
I need help with a query Im trying to write, I cant for th life of me think of the code to query a table to search for a specific date...Its bugging the hell out of me!
Any ideas?
Please explain your question in more detail.
Certainly,
I have a table called 'orders' and I need to run a query to product an output of all the orders that were placed on a specific date.
This is how far Ive got...:-
undef vday
undef vname
DECLARE
vday INTEGER;
vname VARCHAR2(255);
BEGIN
vday := '&&days';
SELECT cust_name
INTO vname
FROM Customers C, Orders O
WHERE C.cust_id = O.cust_id
AND O.order_date = '&&days'
;
END;
/
Im sure Im probably doing it all wrong, but hey, this is MY first query, and Ive not even been trained properly (sigh)
Hope that helps!
You don't need a pl/sql for that. Your query in itself is fine. But you can also select other columns apart from the customer name.
eg.
SELECT cust_name, other columns u want
FROM Customers C, Orders O
WHERE C.cust_id = O.cust_id
AND trunc(O.order_date) = '&days'
You can use query like this,
SELECT cust_name
FROM Customers C, Orders O
WHERE C.cust_id = O.cust_id
AND O.order_date = '&days'
make sure when you input value of days, input it in the default date format set on your database.
Or, you have to mask the input as
to_date('&days','mm-dd-yyyy')
SELECT cust_name
FROM Customers C, Orders O
WHERE C.cust_id = O.cust_id
AND O.order_date = to_date('&days','mm-dd-yyyy')
Input the value of days in the format mentioned.