Spool an output file to dynamic filename

Hi.
Let say I have an Oracle Script as following:
spool c:\hms_report\HMS.xls
SELECT
field1||chr(9)||field2
from table1;
spool off
exit
Question:
Currently the output file will be HMS.xls
If I run the script thrice a day, the HMS.xls will be overwrite.
Is there any way to name the output file to be HMS+sysdate ie: If I run the script on 05-Nov-2002 09:00,
the output file name will be HMS051120020900.xls
where 05 = dd
11 = mm
2002 = yyyy
0900 = hhmi
Thanks.

Have you actually tried what you proposed below? I think not. And I don't see that working. Still, if you do succed like
you have proposed, please tell me.This works, see this SQL*Plus session:
SQL> column file_name new_value fname noprint
SQL> select 'HMS'||TO_CHAR(SYSDATE, 'DDMONYYYYHH24MI')||'.xls' file_name from dual ;
1 row selected.
SQL> prompt &&fname
HMS05NOV20020908.xls
SQL> spool &&fname
SQL> select sysdate from dual ;
SYSDATE
05-NOV-2002
1 row selected.
SQL> spool off
SQL> exit
Disconnected from Oracle8i Enterprise Edition Release 8.1.7.4.1 - Production
With the Partitioning option
JServer Release 8.1.7.4.1 - Production
C:\TEMP\Test>dir
Volume in drive C is Windows NT 4.0
Volume Serial Number is F8F6-BE0C
Directory of C:\TEMP\Test
05-11-02  09:19a        <DIR>          .
05-11-02  09:19a        <DIR>          ..
05-11-02  09:19a                   378 HMS05NOV20020908.xls
05-11-02  09:18a                   139 script.sql
               4 File(s)            517 bytes
                            628,746,240 bytes free
C:\TEMP\Test>type HMS05NOV20020908.xls
SQL> select sysdate from dual ;
SYSDATE
05-NOV-2002
1 row selected.
SQL> spool off
C:\TEMP\Test>

Similar Messages

  • Adobe PDF printer - saves output file as filetype+filename need it to save only as filename

    I am using windows xp pro, when i create the pdf file with adobe PDF printer it creates the file name "Ami Pro - filename.pdf"  I really need it to create the file name as "filename.pdf".  Can you please help me - thank you

    Thank you Bernd - Explorer will let us change the file name one at a time, however I am creating numerous pdfs at a time, and its a pain to correct them one at a time, or to create a bat file to do this.  Does anyone know if the Adobe PDF printer has a feature that will eliminate the file type? thanks

  • Sender File Adapter - Dynamic Filename?

    Dear All,
    I have a simple requirement to retrieve a file named "XXX_ddmmyy" from an FTP site. The FTP site administrator will place a new file everyday. The date is part of the filename.
    I can find a lot of information on how to set the Filename for a "Receiver File Adapter", but none about dynamically setting of the filename for a "Sender File Adapter".
    Can you help please?
    Kind Regards
    Farshad

    Hi,
    You have mentioned over here that the requirement is to get the file "XXX_ddmmyy" from an FTP site.
    Is that site strictly for keeping files related to your requirement only or lot of other files are also being placed???
    If its strictly related to your requirement then you can use the filename "*.extension" and set the processing mode as "delete" so that once the File Adapter picks the file it will be automatically deleted.
    But here disadvantage is that the file wont be no longer present in FTP site once it is picked by File adapter.
    Thanks,
    Lekshmi.

  • Export query results to flat file with dynamic filename

    Hi
    Can anybody can point me how to dynamic export query serults set to for example txt file using process flows in OWB.
    Let say I have simple select query
    select * from table1 where daterange >= sysdate -1 and daterange < sysdate
    so query results will be different every day because daterange will be different. Also I would like to name txt file dynamicly as well
    eg. results_20090601.txt, results_20090602.txt, results_20090603.txt
    I cant see any activity in process editor to enter custom sql statment, like it is in MSSQL 2000 or 2005
    thanks in advance

    You can call existing procedures from a process flow the procedure can create the filename with whatever name you desire. OWB maps with file as target can also create a file with a dynamic name defined by an expression (see here ).
    Cheers
    David

  • File receiver: Dynamic Filenames error

    Hi
    I get an error in my File receiver adapter..
    Receiver Adapter v1730 for Party '', Service 'SenderSystem':
    Configured at 19:32:43 2005-08-01
    Last message processing started 19:33:26 2005-08-01, Error: Message processing failed with java.text.ParseException: Variable 'test' not found in variable substitution table
    We are currently on XI Sp12 patch level3.I have enabled the Variable substitution option and have defined a variable "test" used in defining the file name scheme.The reference points to a node value in the payload.
    I have checked the config xml for the channel which does contain this value test in the variable table..Am I missing anything???
    the config xml is as below:
    [code]2005-08-01 19:32:43 : ToFile
    Raw configuration data ***
    Transport protocol: File, version
    Message protocol: File, version 3.0.0527
    ftp.user|anonymous
    file.varSubstitution|true
    file.adapterStatus|active
    file.addParameterParams|*** TABLE , 0 ROWS DEFINED ***
    file.execute|
    file.targetFileName|%test%.xml
    ftp.overwrite|false
    file.counterMode|immediately
    file.encoding|
    file.overwrite|true
    ftp.transferMode|bin
    ftp.anonymous|false
    ftp.port|21
    file.advanced|false
    file.varSubstitutionDisableSecurity|true
    ftp.targetDir|null
    ftp.host|null
    file.counterSeparator|
    file.counterFormat|00000
    file.varSubstitutionParams|*** TABLE , 1 ROWS DEFINED ***
    file.varSubstitutionParams|file.varSubstitutionParams$0$file.varSubstitutionParamName$test
    file.varSubstitutionParams|file.varSubstitutionParams$0$file.varSubstitutionParamValue$payload:input,1,filenode,1,filename,1
    file.type|bin
    file.targetDir|//10.201.103.253/download
    ftp.password|***
    ftp.putSafe|YES
    file.writeMode|addTimeStamp
    ftp.writeMode|addTimeStamp
    file.recordsetStructure|null
    file.conversionParameters|*** TABLE , 0 ROWS DEFINED ***
    ftp.connection|permanently
    file.counterStep|1
    Used configuration data ***
    'MessageProtocol': 'File'
    'TransportProtocol': 'File'
    'file.adapterStatus': 'active'
    'file.advanced': 'false'
    'file.encoding': ''
    'file.execute': ''
    'file.overwrite': 'true'
    'file.targetDir': '//10.201.103.253/download'
    'file.targetFileName': '%test%.xml'
    'file.type': 'bin'
    'file.varSubstitution': 'true'
    'file.varSubstitutionDisableSecurity': 'true'
    'file.waitForExecute': '0'
    'file.writeMode': 'addTimeStamp'
    OK - initialized
    [/code]

    Sri,
    You have specified payload:input,1..... in ur variable substitution configuration. Is "input" the name of ur Message Type object in repository. If not, specify the name of the Message Type referred to in ur inbound interface.
    We tried this option and generated an additional field in the XML data given as input to the file receiver adapter, to be used for substitution purpose only. We avoided specifying this field in our content conversion , however it still gets written to the file!! if u able to crack it let us know
    -Saravana

  • Stored procedure : spool to output file

    i have to spool data from a stored proc to a csv file.I am using dbms_output.put command as i have mulitiple things to put in a row , comma delimited
    My proc looks like this
    create or replace proc xyz
    declare
    cursor c is select x y z .....
    form
    d f f f
    where ....
    variable declaration
    begin
    someting something ..
    for rec in cursor
    loop
    dbms_output.put(x1||',');
    dbms_output.put(x2||',');
    dbms_output.put(x3||',');
    dbms_output.put(x4||',');
    dbms_output.NEW_LINE;
    endloop
    This does not seem to be working ,Can you please tell me the correct way to do so .
    I need a comma delimited file at the end .

    I cannot use util_file .
    I am ussing dbms_output.put . Thats fine .
    i am spooling currently
    I want to know how I can set the SET variables that only the dbms_output.put variables are spooled to the .
    When you do spool get all the command s?.
    Currently i am doing this
    $ORACLE_HOME/bin/sqlplus -s <<EOI
    $CONNECT_STR
    WHENEVER SQLERROR EXIT FAILURE;
    SET FEED OFF TERM OFF
    SET SERVEROUTPUT ON
    SPOOL $SQL_LOG
    BEGIN
    ${PROCESS_SCHEMA_NM}.${STORED_PROC}.CONVERT_FLEX_2_TIMESHEET;
    END;
    is this correct ?

  • Making a script that generates an output file dynamic

    I've created the following script to run it from within SQL*Plus on my PC to generate a report regarding specific details about all my databases in one file. The idea is to get 1 result of all my databases.
    Spool C:\output.txt;
    -- start DB1
    CONNECT system/pass@DB1;
    COLUMN host_name format A18;
    select * from v$database;
    set line 380;
    set pagesize 50;
    select * from v$session order by username;
    DISCONNECT;
    -- end DB1
    -- start DB2
    CONNECT system/pass@DB2;
    .......................same code as for DB1..................................
    DISCONNECT;
    -- end DB2
    -- start DB3
    CONNECT system/pass@DB3;
    .......................same code as for DB1..................................
    DISCONNECT;
    -- end DB3
    Spool off;
    The above script, for instance, generates the name of the database and the sessions details of all my databases.
    I have 40 DBs and they all have the same password for user system.
    My question, is there a way to re-write this script to achieve the same thing but in a dynamic way. ie: the database connection string becomes dynamic, so that I write the code only once and if the code changes, I change it only one time instead of 40 times.
    Notes: I'd like to run the script from SQL*Plus on my Window PC, I know that the same thing can be achieved by running a script on the DB server by using /etc/oratab, but actually these 40 DBs are on 10 different DB servers and there is no oratab used.
    Many thanks for any tips,
    Thomas

    By awk on unix, or gawk or mawk on Windows (download http://www.klabaster.com/freeware.htm or ftp://garbo.uwasa.fi/pc/unix/gawk2156.zip) it's a easy task.
    File select.sql (your query which you want run)
    spool E:\Scripts\Sql\&1..log
    select table_name from user_tables;
    spool off
    exitFile db.txt :
    #col1 = ORACLE_HOME, col2=user, col3=pwd, col4=dbname, col5=script to run (cool if you run different scritps)
    e:\oracle\ora92 scott tiger DEMO92 E:\Scripts\Sql\select.sql
    e:\oracle\ora102 scott demo102 DEMO102 E:\Scripts\Sql\select.sqlFile select.awk (program calling by main prog)
    { print "set ORACLE_HOME="$1 }
    {print "set ORACLE_SID=" $4}
    {print "cd %ORACLE_HOME%"}
    {print "cd bin"}
    {print "sqlplus -s " $2"/"$3" @"$5" "$4}File run_select.cmd (the program which you will run)
    gawk\gawk -f select.awk db.txt>run_select.cmd
    run_select.cmdWell, now you have pfile and prog, you can work by simple enter name run_awk.cmd or scheduling by task windows :
    E:\Scripts\Sql>run_awk.cmd    <-- you have finish your job, all lines after this one are automatic
    E:\Scripts\Sql>gawk\gawk -f select.awk db.txt 1>run_select.cmd
    E:\Scripts\Sql>run_select.cmd
    E:\Scripts\Sql>set ORACLE_HOME=e:\oracle\ora92
    E:\Scripts\Sql>set ORACLE_SID=DEMO92
    E:\Scripts\Sql>cd e:\oracle\ora92
    E:\oracle\ora92>cd bin
    E:\oracle\ora92\bin>sqlplus -s scott/tiger @E:\Scripts\Sql\select.sql DEMO92
    TABLE_NAME
    A
    BONUS
    C
    DEPT
    EMP
    HARSIMRAT
    PLAN_TABLE
    SALGRADE
    T
    T2
    TAB1
    11 rows selected.
    E:\oracle\ora92\bin>set ORACLE_HOME=e:\oracle\ora102
    E:\oracle\ora92\bin>set ORACLE_SID=DEMO102
    E:\oracle\ora92\bin>cd e:\oracle\ora102
    E:\oracle\ora102>cd bin
    E:\oracle\ora102\BIN>sqlplus -s scott/demo102 @E:\Scripts\Sql\select.sql DEMO102
    TABLE_NAME
    DEPT
    EMP
    BONUS
    SALGRADE
    C
    TAB1
    TBL
    MATRIX
    TAB2
    TAB3
    TAB4
    TABLE_NAME
    TAB5
    TEMP
    TBL7
    TBL6
    IZZA
    TBLA
    TBLB
    TBLC
    TMP_LOOKUPS
    TMP_HIER
    TBL8
    TABLE_NAME
    TBL9
    MV1
    EMP2
    THE_TABLE
    26 rows selected.
    E:\oracle\ora102\BIN>Two logfiles were generate DEMO92.log and DEMO102.log.
    Now you can declinate this procedure to the infinity.
    Nicolas.
    Message was edited by:
    N. Gasparotto
    You have an alternative with mawk which seems more fast, command are same, just replace gawk by mawk.
    Message was edited by:
    N. Gasparotto

  • Using Spool to output data to file

    I am trying to write some sql scripts to do spooling of data to files automatically on the 1st day of each month. I use the spool command to output to text file but have problems setting the filename to tag with the date stamp.
    Script 1 : to get current year and month and then call script 2 to output to file
    ==================================================================================
    set linesize 800
    set pagesize 999
    set heading off
    Remark Get current year and month from database
    Remark
    variable v_yyyymm number;
    declare
    begin
    Select to_number(to_char(to_date(to_char(sysdate,'DD/MM/YYYY'))-1,'YYYYMM')) INTO :v_yyyymm From dual;
    end;
    print v_yyyymm
    @script2.sql :v_yyyymm
    exit
    script2.sql : spool to file
    ============================
    spool Monthly\Audit_Trail_&1..txt
    SELECT * FROM AUDIT_TRAIL WHERE TO_NUMBER(TO_CHAR(DATESTAMP,'YYYYMM')) = &1;
    spool off
    Upon execution in Windows environment, it says that unable to create spool file. It seem
    that i can't use a bind variable in the Spool Command. Any alternative ways of achieving that ??? I need the file name to be taged with the date stamp ?

    Yet another example:
    I usually create a ".cmd" file to run a sql script such as the following:
    spool j:\DailyMetrics.sql
    select 'spool j:\Daily_Metrics_'||to_char(sysdate,'mmddyy')||'.txt' from dual;
    select '@j:\DAILY_METRICS;' from dual;
    select 'spool off' from dual;
    spool off
    This, of course, allows me to then run the "j:\DailyMetrics.sql" script which now spools to a file with today's date as part of its filename and calls the reporting script to generate the data, and then spools off.
    Obviously, you can put everything in the ".cmd" file and just schedule it to be run each day.
    Good luck :)

  • Spooling queries output to text file

    Hi All,
    I need help to spool the output to a text file for a sequence of queries that I need to execute.
    Lets say, the queries would in a sql file as follows:
    Select * from emp where empId = 1
    Select * from emp where empId = 2
    Select * from emp where empId = 3
    The output in txt file should have the details as
    Employee Id Employee Name Employee Designation
    1 Alex Manager
    2 Conrad Sr Manager
    3 Herman Technical architect.
    I am trying to execute this from sql developer.
    Any pointers in this regard would be highly helpful.

    Hi,
    Welcome to the forum!
    Why not use just one query
    SELECT       *
    FROM       enp
    WHERE       empid     IN (1, 2, 3)
    ORDER BY  empid
    You can use "SPOOL filename APPEND" to re-open and add to an existing spool file after it has been closed, but there's no need to in this case.

  • FTP how to pass dynamic filename/directory location - reading a file in 11g

    Hi All,
    We r using FTP adapter(SOA 11g) for getting files in remote server, May i know how to pass dynamic filename and directory where the file exists for reading in server.
    Thanks,
    Rak

    Hey according to my understanding, the Dynamic partner links are set only for the Outbound invocations only. Is my understanding right? if so, how do we create the dynamic partnerlinks for the ftp get kind of stuff...??
    Thanks in advance

  • Dynamic file name in case of .txt output files

    Hi all,
    I have a query related to dynamic file name scenario.
    In case of IDOC-XI-FILE sceanrio,
    <b>Is it possible to generate .txt file name based on Plant number like</b>
    <b>%<Plantname>%_%<BusinessDay>_filename.txt</b>
    <b>Note:I have implemneted this for .xml output files but I am not able to implement it for .txt output files .</b>
    PLEASE HELP ME .
    Regards
    Prabhat

    Hi Prabhat,
    I think, the normal Dynamic File Name generation should work fine in your case also. Even if you perform Content Conversion, you can use Variable Name Substiution to create your Destination file name as, the name of the file is determined first and only then is the content converison perfromed.
    for info on content conversion, I would suggest that you go through this thread and check my reply,
    Re: Dynamic  File Name for Receiver File Adapter
    Regards,
    Bhavesh

  • Setting up FileName for Output file in SendPort

    Hi - I have a requirement setting up FileName in output file. For instance say, whatever I receive in the 'FathersName' field that Output File should be with that File Name.
    For e.g. if data received in FathersName field is JOHN, output file name should be JOHN.xml
    I am using File Adapters on Receive and send side.
    Can this be achieved just by Messaging Scenario or do I need to implement this using Orchestration ?
    If so, please advise on how to do this ?
    e.
    MBH

    To achieve this, you will have to set your filename value on one of the Context Properties available as a File Adapter macro. For example FILE.ReceivedFileName is mapped to the %SourceFileName% macro.
    You have several options to do this:
    Set FILE.ReceivedFileName in an Orchestration.  It does not have to be Promoted.
    Write the Property ReceivedFileName in namespace
    http://schemas.microsoft.com/BizTalk/2003/file-properties in a Custom Pipeline Component.
    If FathersName can be used in the file name unmodified, you set FathersName as a Promoted Property on the schema and Promote directly to FILE.ReceivedFileName.
    For 1 & 2, you will have to extract FathersName somehow, such as a distinguished field.
    A Custom Pipeline Component or direct Promotion are the only way to achieve this in Messaging only.

  • When I run this script nothing is output to the screen or spooled to a file

    When I run this script nothing is output to the screen or spooled to a file. What do I need to do to get output from this script.
    SET SERVEROUTPUT ON size 100000
    DECLARE
    v_schema     Varchar2(50);
    v_statement      Varchar2(500);
    v_name varchar2(30);
    v_id varchar2(8);
    v_pwd varchar2(16);
    v_acct varchar2(16);
    CURSOR get_schemas IS
    SELECT DISTINCT owner
    FROM all_tables
    WHERE table_name = 'USERID'
    ORDER BY owner;
    BEGIN
    OPEN get_schemas;
    LOOP
    FETCH get_schemas INTO v_schema;
    EXIT WHEN get_schemas%NOTFOUND;
              v_statement := 'SELECT name,usid,passwd,acctnum INTO v_name,v_id,v_pwd,v_acct FROM '||v_schema||'.userid';
              execute immediate v_statement;
              DBMS_OUTPUT.PUT_LINE('Name='||v_name||' ID='||v_id||' PW='||v_pwd||' AC='||v_acct);          
    END LOOP;
    CLOSE get_schemas;
    END;
    /

    Do I include several variables after the INTO or just
    one?
    How do I loop through the record and print the
    individual variables?
    I appreciate your assistance!He already gave you the answer above:
    v_statement := 'SELECT name,usid,passwd,acctnum FROM ' || v_schema ||
    '.userid';
    execute immediate v_statement
    INTO v_name, v_id, v_pwd, v_acct;
    If this is not printing any output, it is because you don't have a table named USERID... what are you trying to do?

  • Hello, How do I tell sql+ to spool output file from windows to Unix server?

    Hello, How do I tell sql+ to spool output file from windows to Unix server?
    I am new to SQL+ and just learned how to spool the file. But file is saved in my local windows enviroment and since it's 2GB in size...I want to spool it directly to another remote unix server.
    Pls answer in detail... I have been to most of the thread and didn't see relevant answer to above question.
    Am I suppose to develope some script which FTP the spool file directly to the server I want to
    or
    i Have to use UTL_FILE Package ?
    Thanks for reply

    You may not be able to...
    SQL*Plus can only spool to the local machine. If you have mapped a directory on the Unix server from your Windows machine, you can specify that directory in your SPOOL command.
    You could telnet to the Unix server, run SQL*Plus there, and spool the file to a local (Unix) directory.
    If the Unix server is also the Oracle database server, you could use the UTL_FILE package rather than using SQL*Plus to spool a file.
    If the Unix server is also an FTP server, you could also FTP the file from your local machine to the server.
    Of course, I would tend to re-examine a requirement to regularly generate a 2 GB text file. It seems likely that there is a better way...
    Justin

  • Trim whitespace in output file using spool program

    hi all,
    How do i can trim the space between the output?
    1000064426                                                   16-MAR-10 60355230028
    1000064269                                                   16-MAR-10 60355230002
    1000064251                                                   16-MAR-10 60355230000 Expected output :
    1000064426 16-MAR-10 60355230028
    1000064269 16-MAR-10 60355230002
    1000064251 16-MAR-10 60355230000 Kindly help me.
    Many thanks
    Edited by: BluShadow on 16-Mar-2011 10:22
    added {noformat}{noformat} tags so the issue can actually be seen                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    In your SQL, concatenate the columns.
    for e.g
    select object_id||object_name||owner
    from all_objects
    You'll always get a space between columns if you spool the output from sqlplus as the defualt column separator is a space. Also, it is generally best to have the columns delimited by a pre-defined character, so that any program that reads the file will know the start and end of a field or column.
    If you do want a fixed-length format file, you can use functions like LPAD or RPAD.
    e.g.
    select RPAD(object_id,10,'0')||RPAD(object_name,20,'N')||RPAD(owner,30,'N')
    from all_objects

Maybe you are looking for

  • HT1414 my handsfree is not working please help me

    Hi There! I am using Iphone 4s and ny handsfree in not working please help me

  • No Items Selected

    Dear Friends, Using T.code FINTAP - Item interest calculation, I entered Vendor account,Co.code,Interest Indicator,Interest Indicator , Interest Calculation upto:31.04.2009,Posting and Document date upto 31.01.2009. I am getting the error "No items s

  • Slideshow with music for a TV?

    I want to create a slideshow of images and use the Ken Burns effect and add music and burn the slideshow to DVD so it can be played on a TV. 1. Is the music added in iPhoto or iDVD? 2. How do I send the images from iPhoto to iDVD? Thanks!

  • Photosmart C8180 - how to remove black ink message window

    I recently changed my black ink cartridge and now every time I hit print a window appears saying the cartridge is empty and to replace it.  I have to hit "continue" in order to get the printer to print.  How do make this window go away?  Donna

  • Goods movement issue

    hi all we are working on project based scenarion, planning strtegy 21 (MTO with Project). we have following cysle. Master data creation. Prject builder creation sale order creation. linking wbs element with sale order. MRP run on Project using tcode