Results 1 to 5 of 5
  1. #1
    Join Date
    Aug 2009
    Posts
    1

    Question Unanswered: SQL / Oracle converting time and sorting

    Hi, I'll try to be short on my question. I'm am new to Oracle. My company use a sybase database that runs business jobs. Currently we run SQL queries from Perl to gather time information on the jobs. Now we have an application that is using Oracle. The server it is on, doesn't have perl, so I am using a shell script to login to sqlplus and run a query for a job and it's end time. I have accomplished this. However, here is the 2 problems I am having.

    1. The query reults are returned in Scientific time, I'm able to convert that to EPOCH time in the SQL syntax, however, it comes back with a 13 digit time, instead of 10. The last 3 digits are zero. How can you remove the last 3 digits in the query or convert the 13 digits to Human Time. Right now when you see the select statement, I am doing a to_char to get it to EPOCH time.

    2. How to only show the latest time in the query and not show ALL job end times from it's past runs.

    Here is my shell script, and I do realize this maybe a select statement syntax solution to one or both, but the UNIX time stamp is puzzling.

    #!/usr/bin/sh


    sqlplus -S username/password@JAWSPROD <<eof> myfile
    set heading off feedback off verify off
    select JAWS_APP.JAWSJOB.JOBNAME, to_char(JAWS_APP.JOBRUN.ENDTIME) from JAWS_APP.JAWSJOB, JAWS_APP.JOBRUN where JAWS_APP.JAWSJOB.JOBID = JAWS_APP.JOBRUN.JOBID and JAWS_APP.JAWSJOB.JOBNAME in ('pa_box_settle');
    exit

    EOF


    Thanks for any help or guidence.

  2. #2
    Join Date
    Aug 2009
    Posts
    16
    Why don't you try a MAX() function to get the last date/time of the job run. Something like this should work:
    select
    JAWS_APP.JAWSJOB.JOBNAME,
    MAX(JAWS_APP.JOBRUN.ENDTIME)
    from JAWS_APP.JAWSJOB, JAWS_APP.JOBRUN
    where JAWS_APP.JAWSJOB.JOBID = JAWS_APP.JOBRUN.JOBID and JAWS_APP.JAWSJOB.JOBNAME in ('pa_box_settle')
    GROUP BY JAWS_APP.JAWSJOB.JOBNAME;

    Regarding the time conversion, look at using a format with the to_char() function you are using. This should help:
    Using oracle date format

  3. #3
    Join Date
    Aug 2009
    Location
    Olympia, WA
    Posts
    337
    You're getting your results in milliseconds, just divide by 1000.

    The results of to_char() without a second format parameter are based on your NLS settings (NLS_DATE_FORMAT) which can be overridden at the session level. I'd recommend using that param so you stuff doesn't break when the dba changes stuff or work for some people but not others.

  4. #4
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,776
    Provided Answers: 1
    >The last 3 digits are zero. How can you remove the last 3 digits in the query or convert the 13 digits to Human Time.
    just divide by 1000

    All recent versions of Oracle are delivered with Perl & it is trivial to install DBI & DBD
    Last edited by anacedent; 08-28-09 at 13:16.
    You can lead some folks to knowledge, but you can not make them think.
    The average person thinks he's above average!
    For most folks, they don't know, what they don't know.
    Good judgement comes from experience. Experience comes from bad judgement.

  5. #5
    Join Date
    Jun 2004
    Location
    Liverpool, NY USA
    Posts
    2,509
    use a format mask. for example
    to_char(JAWS_APP.JOBRUN.ENDTIME,'mm/dd/yyyy hh24:mi.ss')

    fould return (for example) 08/31/2009 13:45.32

    see the following link for the masks. Format Models
    Bill
    You do not need a parachute to skydive. You only need a parachute to skydive twice.

Posting Permissions

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