Convert date format
DBAsupport.com Forums - Powered by vBulletin
Results 1 to 5 of 5

Thread: Convert date format

  1. #1
    Join Date
    Sep 2001
    Location
    UK, Surrey
    Posts
    14

    Unhappy

    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?

    Lewis @ Homebase.co.uk

  2. #2
    Join Date
    Nov 2000
    Posts
    224
    Please explain your question in more detail.

  3. #3
    Join Date
    Sep 2001
    Location
    UK, Surrey
    Posts
    14
    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!
    Lewis @ Homebase.co.uk

  4. #4
    Join Date
    Oct 2000
    Posts
    467
    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'


    Vinit

  5. #5
    Join Date
    Nov 2000
    Posts
    224
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Click Here to Expand Forum to Full Width