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

Thread: spooling

  1. #1
    Join Date
    Mar 2001
    Location
    south africa
    Posts
    401

    spooling

    Hello

    I have two questions

    1.what is the where condtion for generating last months data .I don't want to hard code month instead on the first of the month it will generate data for previous month(of course i will cron)

    2.i have orders table
    orderid,createddate and client_id
    currently i am spooling data for each client like this
    ----------
    spool \u01\client123.txt
    select * from orders where client_id=123;
    spool off
    -------------
    everytime we add a client or clients , it's just pain to go and edit this sql file to spool

    Is there way to automatically generates data into different file based on clientid automatically?

    Thanks for your time and help

  2. #2
    Join Date
    Mar 2007
    Location
    Ft. Lauderdale, FL
    Posts
    3,555
    1 - Use sysdate
    2 - Yes
    Pablo (Paul) Berzukov

    Author of Understanding Database Administration available at amazon and other bookstores.

    Disclaimer: Advice is provided to the best of my knowledge but no implicit or explicit warranties are provided. Since the advisor explicitly encourages testing any and all suggestions on a test non-production environment advisor should not held liable or responsible for any actions taken based on the given advice.

  3. #3
    Join Date
    Mar 2001
    Location
    south africa
    Posts
    401
    hello PAVB

    Do you have a sample query

    Thanks

  4. #4
    Join Date
    Mar 2007
    Location
    Ft. Lauderdale, FL
    Posts
    3,555
    Follows a template for each one of your needs...

    #1 - Select Last Month Data

    Code:
    select  *
    from    schema_name.table_name
    where   to_char(your_date_column, 'YYYYMM') = to_char(sysdate - 30, 'YYYYMM')
    ;
    #2 - Create Query on-the-fly

    Code:
    spool \u01\myquery.sql
    set pagesize 0
    set linesize 180
    select  'select * from orders where client_id=' ||
            "CLIENT" ||
            ';' 
    from
    (        
    select  distinct client_id "CLIENT"        
    from    orders
    );
    spool off
    spool \u01\client123.txt
    @\u01\myquery.sql
    spool off
    Hope it helps.
    Pablo (Paul) Berzukov

    Author of Understanding Database Administration available at amazon and other bookstores.

    Disclaimer: Advice is provided to the best of my knowledge but no implicit or explicit warranties are provided. Since the advisor explicitly encourages testing any and all suggestions on a test non-production environment advisor should not held liable or responsible for any actions taken based on the given advice.

  5. #5
    Join Date
    Mar 2001
    Location
    south africa
    Posts
    401
    thanks for your time .i will try these

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