Use "set spool" command in pl/sql block

Hi,
I need to use the "set spool ..." command inside my pl/sql block.
could you please tell me how to do this.
Please help fast.
Thanks
Maria

I am aware that spool is not a pl/sql command.
I have to put the result of my query into a file without using util commands ( as I canot change the utl_file_dir). SO I was sondering if somehow I could use the pool command inside my pl/sql.
My data is too big to use dbms_output.
Thus can you suggest anything

Similar Messages

  • How to pass value to select-option parameter using SET PARAMETER Command

    Hi,
        Am passing values to selection-screen fields in report RV13A004 ( used in VK11, VK12 and VK13). using below statement but material number is select-option in this report. am able to pass  MATERIAL FROM using SET PARAMETER ID, can i know how to pass values MATERIAL TO range in select-options fields using SET PARAMETER Command ??
    Passing values to parameter id
    set parameter id 'VKS' field kschl.
    set parameter id 'VKO' field vkorg.
    set parameter id 'VTW' field vtweg.
    set parameter id 'KDA' field erdat.
    set parameter id 'MAT' field matnr_from.
    Change condition price.
    call transaction 'VK12' and skip first screen.
    Thanks in advance.
    Regards,
    Balamurugan.

    Hi,
    instead of using set parameters and dden call transaction use this..........
    submit RV13A004  WITH SELECTION-TABLE rspar
    Effect
    If you specify this addition, parameters and selection criteria on the selection screen are supplied from an internal table rspar. You must specify an internal table with the row type RSPARAMS for rspar. The structured data type RSPARAMS is defined in the ABAP Dictionary and has the following components, all of which are data type CHAR:
    SELNAME (length 8),
    KIND (length 1),
    SIGN (length 1),
    OPTION (length 2),
    LOW (length 45),
    HIGH (length 45).
    To supply parameters and selection criteria for the selection screen with specific values, the lines in the internal table rspar must contain the following values:
    SELNAME must contain the name of a parameter or selection criterion for the selection screen in block capitals
    KIND must contain the type of selection screen component (P for parameters, S for selection criteria)
    SIGN, OPTION, LOW, and HIGH must contain the values specified for the selection table columns that have the same names as the selection criteria; in the case of parameters, the value must be specified in LOW and all other components are ignored.
    If the name of a selection criterion is repeated in rspar, this defines a selection table containing several lines and passes it on to the selection criterion. If parameter names occur several times, the last value is passed on to the parameter.
    The contents of the parameters or selection tables for the current program can be entered in the table by the function module RS_REFRESH_FROM_SELECTOPTIONS.
    Notes
    In contrast to selection tables, the data types of the components LOW and HIGH in table rspar are always of type CHAR and are converted to the type of the parameter or selection criterion during transfer, if necessary.
    When entering values, you must ensure that these are entered in the internal format of the ABAP values, and not in the output format of the screen display.
    Cheers
    Will.

  • Running sqlldr command from PL/SQL Block

    DECLARE
    BEGIN
    END;

    In SQL * plus we can run DOS commands using the following command
    HOST DIR
    HOST DIR/P
    But When we can't run the HOST command in PL/SQL Block..
    I have to Run sqlldr command from PL/SQL Block..
    i tried as follows
    DECLARE
    BEGIN
    EXECUTE IMMEDIATE ' host sqlldr control= bad= ';
    END;
    By
    BalaNagaRaju

  • RMAN-06085: must use SET NEWNAME command to restore datafile 'MISSING00'

    Tried to restore again but got this message.
    RMAN-06085: must use SET NEWNAME command to restore datafile /oracle/Ora11g/dbs/MISSING00126

    no, im not restoring datafile to different location.
    this is what i encounter after a successfull restore and but failed recover.
    My original post is on the other thread.
    i was just desperate to start a new thread since there are nobody but only one who replied
    Hope you could go to that thread and help me... topic: (Success on RESTORE but failed on RECOVER-- need help)
    thanks in advance...

  • Using accept command within PL/SQL block

    Hi all i have a following Pl/SQL block which ia =as follows :-
    declare
    begin
    ...certain statements using while
    end;
    i need to take the user input using accept
    if i put the accept stmt betweeen begin and end i am getting following error :-
    accept myv number default 10 prompt 'Enter a number: '
    ERROR at line 48:
    ORA-06550: line 48, column 8:
    PLS-00103: Encountered the symbol "MYV" when expecting one of the following:
    := . ( @ % ;
    ORA-06550: line 48, column 30:
    PLS-00103: Encountered the symbol "PROMPT" when expecting one of the following:
    * & = - + ; < / > at in is mod remainder not rem
    <an exponent (**)> <> or != or ~= >= <= <> and or like
    between || multiset member SUBMULTISET_
    Let me know how can i include accept stmt in Pl/SQL block
    Thanks

    You're missing a fundamental concept here.
    PL/SQL = embedded 4GL programming language in the Oracle database.
    SQL*Plus = CLI (Command Line Interface) client for an Oracle database.
    The ACCEPT command is a SQL*Plus command. Not a PL/SQL command.
    The PL/SQL engine sits inside the Oracle Server Process that services your client (SQL*Plus) session. That server process does not know who/what/where you are as a physical client. It does not know what platform and o/s you are using. It does not know what client you are using. It is after all a server process and should not and need not to know that.
    Nor can that Oracle Server Process running on the Data Server Platform access you client's hard drive, keyboard, mouse, screen, printer and so on.
    PL/SQL running in this Oracle Server Process therefore cannot read your keyboard to accept end-user input. PL/SQL therefore cannot write data to your screen.
    You need to make a clear distinction between SQL*Plus (a client) and Oracle PL/SQL (the server).

  • Copy Command in Pl/Sql block

    Can I use Copy command in Pl/Sql.For example :-
    Declare
    cursor c1 is select table_name from all_tables
    where owner = 'LSP' and rownum = 1;
    v1 varchar2(2000);
    Begin
    for c2 in c1 loop
    v1:='copy from lsp/lsp123479@dvlaq to scott/[email protected] create '|| c2.table_name ||' using select * from '||c2.table_name;
    execute immediate v1;
    end loop;
    end;
    Its not running properly giving an error as invalid Sql statement .
    Is it bcoz Copy command cannot be used in a Pl/Sql Block.

    Is there any other way to move the Table & data to another Data Base .Database link is the obvious one. And the SQL statement would look something like this (on the target database):
    SQL> create table FOO nologging as select * from FOO@sourcedb;
    However, the first question I always ask if why? What one may think is the solution to a problem is not always the best solution. So one need to identify the problem first, and then see what solutions there are and which one is the best fit.
    Other options are replication (using materialised views for example), Data Pump (available with 10G) - even could be Data Guard, a standby database, or a Real Application Cluster... depending on just what the problem and actual requirements are.
    Also important to note that SQL*Plus has its own set of commands. Do not confuse these commands (like EXEC, COPY, CONNECT, HOST etc) with the SQL and PL/SQL Languages. Not only are they executed by different software products, SQL*Plus commands are executed on the client and SQL (and PL/SQL) runs inside the Oracle database instance.

  • Exec SQLPLUS command from PL/SQL Block

    Good Morning:
    How I can execute a SQLPLUS command (like SPOOL or DESCRIBE) from PL/SQL Block Procedure?:
    DECLARE
    BEGIN
    ls_command = 'DESCRIBE '||ls_table_name;
    EXECUTE SQLPLUS(ls_command);
    END;
    Thanks a lot for any idea.

    That's correct.
    However, in the case of the given example we can use DBMS_DESCRIBE package to get table descriptions. And we can use UTL_FILE to spool PL/SQL stuff to a file.
    Cheers, APC

  • SPOOL Command in PL/SQL developer

    Hi,
    Iam executing below command in PL/SQL Developer7.0
    SPOOL 'U:/MyFiles/test.txt';
    select sysdate from dual;
    spool off;
    Iam getting ORA-00900: Invalid SQL Statement. Please let me know what is the exact syntax for SPOOL in PL/SQL Developer.

    Hi;
    Please see below note which is mention to using of spool wiht example:
    http://www.scribd.com/doc/4542950/How-to-Spool-in-Oracle
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14357/ch12043.htm
    http://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:1317802337341
    spool sql*plus's output
    Regard
    Helios

  • Using item values in a pl/sql block or sql query in a process

    Hi,
    I am new to apex. Developing my first application.
    I have created a form with 2 items. Based on the values in these items, when I click a button, want to execute a
    query.
    eg: emp_name(item1), deptno(item2). When I clock on find button, I want to fetch the record and disply the resultant
    columns in other created items like sal,comm etc.
    How can I do this?
    I tried the following pl/sql block in a process
    begin
    select sal,comm into p1_sal,p1_comm from emp where name=p1_name and deptno=deptno;
    end;
    But it is not accepting the page items in the block.
    How to achieve this?
    Thanks,
    Kavitha

    We have many OBEs, tutorials, etc. Please visit the <a hef="http://www.oracle.com/technetwork/developer-tools/apex/learnmore/index.html" target="_window">Learn More</a> tab of our otn site.
    This is the section of the User's Guide that discusses session state -
    -- Sharon

  • Running a OS command from PL/sql Block.

    I am using UTL_FILE to write data to a text file from within a stored procedure.Before terminating the procedure i would like to run FTP command on the server to copy the file to a different server. Can this be done..... ? Or is this asking for too much..
    null

    Search the forums for 'external procedure'. There are examples that have been posted in the past few weeks.
    null

  • Spooling from PL/SQL Block

    Hi,
    Is it possible to do spooling from a pl/sql block.The spool cannot be the first command because I want to give the spool file name in a loop and each time the spool name should change based on the value.
    I tried all possiblities,but I couldn't can anyone give me some idea on how to do this.
    I cannot use UTL_FILE option ,because the client agreed only for spooling.
    Is it possible to write the spool data is excel format..
    Please find below an example of my requirement..
    DECLARE
    CurSor Cur_Designation IS
    Select Designation from tbl_Designation;
    N_Desig Cur_Designation%RowType;
    Cursor Cur_Emp(Desig Number) IS
    Select Emp_no,Emp_name
    From Employee Where Emp_Designation = Desig;
    N_Emp Cur_Emp%RowType;
    BEGIN
    Open Cur_Designation ;
    Loop
    Fetch Cur_Designation INTO N_Desig;
    EXIT WHEN Cur_Designation %NOTFOUND;
    --Here I want to give the spool file name
    Spool --Should be designation name
    Open Cur_Emp(N_Desig.Designation);
    Loop
    Fetch Cur_Emp INTO N_Emp ;
    EXIT WHEN Cur_Emp %NOTFOUND;
    -- All employee details I need to come to log file
    End Loop;
    Close Cur_Emp;
    End Loop;
    Close Cur_Desingnation;
    End;
    Please advice me how to do this..
    Thanks,
    Bindu

    << I cannot use UTL_FILE option ,because the client agreed only for spooling. >>
    << I want to use it in a PL/SQL Block.I have some variables to declare and some cursors to be used.
    So where should I use the spool command.
    I tried to given after a fetch command ,but it is not working. >>
    you can't use SPOOL inside PLSQL
    you may use dbms_output calls in PLSQL
    so create a procedure test2 instead of sqlscript test2 and you will be fine
    rem =========== procedure test2 ================
    create or replace
    procedure test2 (p_param number) is
    begin
                 dbms_output.enable (1000000);
                 dbms_output.put_line('A' || chr(9) || 'B' || chr(9) || 'C' ) ;
                 FOR i_rec in (select a,b.c from xyz where a = p_param) LOOP
                     dbms_output.put_line (to_char(a) || chr(9) || b || chr(9) || c ) ;
                 END LOOP ;
    end ;
    REM ====================================================                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Is it possible to automate the extraction using spool command?

    Hi,
    I am trying to export data from table to excel. But the result i am getting will be in million records. Till now i am manually extracting the data using plsql developer. but it is hampering my work alot when i am extracting.
    i am able to extract the data using below spool command in sqlplus
    set feed off markup html on spool on
    spool 'd:\filename.xls'
    select * from ca_trial_milestones;
    spool off
    set markup html off spool off
    But is it possible to run it in sql/plsql developer and schedule it on night time.
    U r replies will help me alot.
    Thanks alot in advance

    981145 wrote:
    Hi,
    I am trying to export data from table to excel. But the result i am getting will be in million records. Till now i am manually extracting the data using plsql developer. but it is hampering my work alot when i am extracting.
    i am able to extract the data using below spool command in sqlplus
    set feed off markup html on spool on
    spool 'd:\filename.xls'
    select * from ca_trial_milestones;
    spool off
    set markup html off spool off
    But is it possible to run it in sql/plsql developer and schedule it on night time.
    U r replies will help me alot.
    Thanks alot in advanceYou can create a batch file in window and then setting appropriate environment setting you can do
    sqlplus user/pass@connect @scriptnamewhere scriptname is you above script.
    You can then schedule this in windows schduler
    However excel can not handle more than 1,048,576 rown as of version 2010
    You can save the spool as html file and you will able to view the resultset.

  • How to generate text file using spool command

    How can I use a SPOOL command with DBMS_OUTPUT.PUT_LINE with PL/SQL to produce text file on oracle client machine.

    You could try using a REF CURSOR as an alternative. Bare bones example listed below:
    --- SQL Script
    SET FEEDBACK OFF
    COLUMN first_name FORMAT A25
    COLUMN last_name FORMAT A25
    VARIABLE example_data REFCURSOR
    BEGIN
    example.get_data(:example_data);
    END;
    SPOOL example_data.txt
    PRINT example_data
    SPOOL OFF
    -----Output in example_data.txt
    FIRST_NAME LAST_NAME
    First Name 1 Last Name 1
    First Name 2 Last Name 2
    First Name 3 Last Name 3
    First Name 4 Last Name 4
    First Name 5 Last Name 5
    First Name 6 Last Name 6
    First Name 7 Last Name 7
    First Name 8 Last Name 8
    First Name 9 Last Name 9
    First Name 10 Last Name 10
    -----Example package used in SQL Script
    CREATE OR REPLACE PACKAGE example
    IS
    TYPE result_set IS REF CURSOR;
    PROCEDURE get_data
    p_result_set OUT result_set
    END;
    SHOW ERRORS
    CREATE OR REPLACE PACKAGE BODY example
    IS
    PROCEDURE get_data
    p_result_set OUT result_set
    IS
    BEGIN
    -- replace this with your query
    OPEN p_result_set FOR
    WITH fake_data AS (
    SELECT
    'First Name ' || level first_name,
    'Last Name ' || level last_name
    FROM DUAL
    CONNECT BY LEVEL <= 10
    SELECT *
    FROM fake_data
    END;
    END;
    SHOW ERRORS
    SPOOL OFF

  • Trying to use spool command

    heyyall,
    am trying to use the spool command to save a file from an output but i get the message:
    SPOOL save.lis
    SP2-0606: Cannot create SPOOL file save.lis
    am using sql-plus 10.2.0.1.0
    ?

    No its not an advanced setup , its just i logged into database using putty, easy to use.
    In Command Promt we use dir command to list the directories , in the same way in database ls list the subfolders/subdirectories and files present in the current directory.
    I think you are using local database only right?.
    Then go to command prompt (i.e., go to run and type cmd)
    And from there i had done this scenario, please view it so that you can understand clearly
    Microsoft Windows [Version 6.1.7600]
    Copyright (c) 2009 Microsoft Corporation. All rights reserved.
    C:\Users\Balaji K>dir
    Volume in drive C has no label.
    Volume Serial Number is 0282-81BD
    Directory of C:\Users\Balaji K
    03/27/2011 12:04 AM <DIR> .
    03/27/2011 12:04 AM <DIR> ..
    03/26/2011 03:04 AM <DIR> .VirtualBox
    02/25/2011 04:57 PM <DIR> Contacts
    03/26/2011 06:07 PM <DIR> Desktop
    03/25/2011 06:00 PM <DIR> Documents
    03/25/2011 08:44 PM <DIR> Downloads
    03/04/2011 06:06 PM <DIR> Favorites
    02/25/2011 04:57 PM <DIR> Links
    02/25/2011 04:57 PM <DIR> Music
    02/25/2011 04:57 PM <DIR> Pictures
    02/25/2011 04:57 PM <DIR> Saved Games
    02/25/2011 04:57 PM <DIR> Searches
    03/26/2011 10:04 PM <DIR> Tracing
    02/25/2011 04:57 PM <DIR> Videos
    02/25/2011 06:07 PM <DIR> VirtualBox VMs
    0 File(s) 0 bytes
    16 Dir(s) 43,067,936,768 bytes free
    C:\Users\Balaji K>sqlplus sys as sysdba
    SQL*Plus: Release 10.2.0.1.0 - Production on Sun Mar 27 00:04:44 2011
    Copyright (c) 1982, 2005, Oracle. All rights reserved.
    Enter password:
    Connected to:
    Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production
    SQL> spool example.txt
    SQL> desc dba_users;
    Name Null? Type
    USERNAME NOT NULL VARCHAR2(30)
    USER_ID NOT NULL NUMBER
    PASSWORD VARCHAR2(30)
    ACCOUNT_STATUS NOT NULL VARCHAR2(32)
    LOCK_DATE DATE
    EXPIRY_DATE DATE
    DEFAULT_TABLESPACE NOT NULL VARCHAR2(30)
    TEMPORARY_TABLESPACE NOT NULL VARCHAR2(30)
    CREATED NOT NULL DATE
    PROFILE NOT NULL VARCHAR2(30)
    INITIAL_RSRC_CONSUMER_GROUP VARCHAR2(30)
    EXTERNAL_NAME VARCHAR2(4000)
    SQL> select username from dba_users;
    USERNAME
    SYS
    SYSTEM
    ANONYMOUS
    MDSYS
    OUTLN
    DIP
    TSMSYS
    FLOWS_FILES
    CTXSYS
    DBSNMP
    FLOWS_020100
    USERNAME
    XDB
    HR
    13 rows selected.
    SQL> exit
    Disconnected from Oracle Database 10g Express Edition Release 10.2.0.1.0 - Produ
    ction
    C:\Users\Balaji K>dir
    Volume in drive C has no label.
    Volume Serial Number is 0282-81BD
    Directory of C:\Users\Balaji K
    03/27/2011 12:04 AM <DIR> .
    03/27/2011 12:04 AM <DIR> ..
    03/26/2011 03:04 AM <DIR> .VirtualBox
    02/25/2011 04:57 PM <DIR> Contacts
    03/26/2011 06:07 PM <DIR> Desktop
    03/25/2011 06:00 PM <DIR> Documents
    03/25/2011 08:44 PM <DIR> Downloads
    03/27/2011 12:05 AM 2,398 example.txt
    03/04/2011 06:06 PM <DIR> Favorites
    02/25/2011 04:57 PM <DIR> Links
    02/25/2011 04:57 PM <DIR> Music
    02/25/2011 04:57 PM <DIR> Pictures
    02/25/2011 04:57 PM <DIR> Saved Games
    02/25/2011 04:57 PM <DIR> Searches
    03/26/2011 10:04 PM <DIR> Tracing
    02/25/2011 04:57 PM <DIR> Videos
    02/25/2011 06:07 PM <DIR> VirtualBox VMs
    1 File(s) 2,398 bytes
    16 Dir(s) 43,067,940,864 bytes free
    C:\Users\Balaji K>
    See now you can see the example.txt which we had spooled. Now if go with
    C:\Users\Balaji K>edit example.txt command you can see that all the data is spooled into it.
    And instead of exiting sqlplus, if you want to continue some other operations , then you can give spool off command .
    sql> spool off.
    Hope this helps you :)
    Thanks,
    Balaji K.
    Edited by: balaji k on Mar 26, 2011 11:42 AM
    Edited by: balaji k on Mar 26, 2011 11:43 AM

  • Content in PL/SQL block

    I am new to PL/SQL. I understand that I can run PL/SQL from sqlplus. But it does not work for me if I put sqlplus command in PL/SQL blocks. For example:
    BEGIN
    IF &1 IS NULL THEN CONNECT username/userpassword
    ELSE CONNECT username/userpassword@&1
    ENDIF;
    END;
    I wonder:
    1) What can be included in PL/SQL block? Can a sqlplus command (like CONNECT) be included in PL/SQL block?
    2) In sqlplus, how to check if the sql script has an command line input parameter,
    like "myscript.sql <input_parameter>"?
    Thank you.

    Just to add a few comments.
    PL/SQL is a formal procedural language. The CONNECT command is not part of this language. So just as PL/SQL cannot understand C/C++ commands, nor can it understand SQL*Plus macro commands.
    The & char is used in SQL*Plus as a substitution variable. SQL*Plus checks the PL/SQL or SQL code block before it sends it to Oracle. SQL*Plus substitutes all & variables first - and changes this code block. Then this changed code block is submitted by SQL*Plus to Oracle for execution.
    You need to grok the basics of client-server here and how the client (SQL*Plus in this case), interacts with the server (Oracle and is PL/SQL engine in this case).
    SQL*Plus does not have a "programming" language - it has a very simplistic macro language. It does not support conditional execution. It does not support loop structures. It is very primitive. And must not be confused with PL/SQL and cannot be mixed with PL/SQL (server-side) code.

Maybe you are looking for