How to write stored procedure to spool data into file

Hi ,
We get differnt excel sheets of differnt products.
We upload data from excel sheet to database . After uploading data , I run Preprossor (sql script) to check the data
This preprocessor script contains several select statements that query different tables in database .the output is spooled into a cvs file .
I need to change this script into a stored procedure and spool the output to cvs file.
File spooling should be done inside the stored procedure so that if I call this stored procedure from java program ,or any concurrent program,its output is .cvs file and in parameter should be productname.
But inside the stored procedure , we cannot spool the data to some .cvs file . Is any way.I do not want to spool to file when calling.It should be inside stored procedure.
Or do I need to create a table and insert all the select statements output into it .
Here is the sample preprocessor script.
spool Graco_Product.csv
set head off
set feedback off
set Pagesize 100
SELECT '1. EVERY ASSEMBLY GROUP ADDED IN sys_PRODUCT TABLE MUST HAVE AT LEAST ONE ITEM IN WOC_ASSEMBLY_ITEM'
     FROM DUAL;
SELECT 'ASSEMBLY_GROUP_NAME'
     FROM DUAL;
SELECT
     assembly_group_name
     FROM association
     WHERE product_model_name = 'Graco_Product'
     AND assembly_group_name NOT IN (SELECT DISTINCT assembly_group_name FROM woc_assembly_item);
SELECT '2. A RULE SHOULD HAVE AT LEAST ONE EXPRESSION FOR ITS ACTION SIDE.'
     FROM DUAL;
SELECT 'RELATION_ID , RELATION_TYPE'
     FROM DUAL;
SELECT wr.Relation_ID                    ||','||
     wr.Relation_Type                    
     FROM WOC_Relation wr
     WHERE NOT EXISTS (SELECT 'X' FROM WOC_Relation_Expression wre
WHERE wre.Relation_Side = 'Action'
AND wr.Relation_ID = wre.Relation_ID)
     AND wr.Relation_Type NOT IN ( 'Rule Warning','Rule Resource','Rule Default');
SELECT '3. PROPERTIES USED IN RULES SHOULD EXIST IN WOC_PROPERTY_MASTER -- EXP_LHS_VALUE'
     FROM DUAL;
SELECT
     'RELATION_OWNER,EXP_LHS_OPERAND,RELATION_SIDE,RELATION_ID,EXP_LHS_VALUE,RELATION_TYPE'     
     FROM DUAL;
SELECT
     b.relation_owner               ||','||
     a.exp_lhs_operand               ||','||
     a.relation_side                    ||','||
     a.relation_id                    ||','||
     a.exp_lhs_value                    ||','||
     b.relation_type
     FROM woc_relation_expression a, woc_relation b
     WHERE a.exp_lhs_value IS NOT NULL
     AND a.exp_lhs_value_type = 'Property'
     AND a.exp_lhs_value NOT IN (SELECT property_name FROM woc_property)
     AND b.product_model_name = 'Graco_Product'
     AND a.relation_id = b.relation_id;
SELECT '--------------------------------------------------------------------------------'
from dual;
spool off
set head on
set feedback on

High level description
Full documentation
Note that the UTL_ and DBMS_ packages are all covered in the PL/SQL Packages and Types Reference.
You may also want to read up on the CREATE DIRECTORY statement, which lets you refer to an actual OS directory (which you create separately) via a database object.

Similar Messages

  • How to write stored procedures

    hi
    how you will write stored procedures in jdbc .could u pls tell me the procedure?what is key in jdbc where you will use that in which situation?could ugive me the answer briefly
    thanks
    nag

    Hi
    A stored procedure is a subroutine available to applications accessing a relational database system. Stored procedures (sometimes called a sproc or SP) are actually stored in the database.
    Stored procedures are similar to user-defined functions (UDFs).
    A stored procedure is a group of SQL statements that form a logical unit and perform a particular task, and they are used to encapsulate a set of operations or queries to execute on a database server
    Use this
    http://www.ics.com/support/docs/dx/1.5/tut6.html
    http://java.sun.com/docs/books/tutorial/jdbc/basics/sql.html
    http://www.sqlteam.com/article/stored-procedures-an-overview
    Thanks

  • How to write a procedure to retrieve data in a collection from a table?

    create or replace type Subject as object(
    subject_id number,
    subject_Desc varchar2(50)
    create or replace type Subjects_All as varray(10) of Subject
    create table student(
    StudentID varchar(10),
    Subjects Subjects_all
    so how do i write a procedure to display info such as this:
    Subjects:
    101 'Maths'
    102 'Science'
    Subjects:
    I wrote a procedure like the following but it didn't quite work :(
    CREATE OR REPLACE PROCEDURE StudentLoop AS
    all_subj subjects_all;
    each_subj subject;
    CURSOR all_subjectsrow IS select * from student;
    BEGIN
    FOR all_subj IN all_subjectsrow LOOP
    FOR each_subj IN all_subj LOOP
    DBMS_OUTPUT.PUT_LINE('Last row selected has ID ' || each_subj.subject_id || each_subj.subject_desc );
    END LOOP;
    END LOOP;
    END StudentLoop ;
    Any Advice?

    Hello,
    1.) Don't store Types in Tables. It will become a nightmare when you want to query your data any other way then retrieving your object types. Just don't do it.
    2.) A more relational model is much easier. Considering students and subjects is a n:n relation (a student can have more subjects and a subject can have more students) this might look like this:
    SQL> r
      1  declare
      2    cursor cStudents is
      3      with student as (
      4        select 1 student_id, 'test1' name from dual
      5        union all
      6        select 2 student_id, 'test2' name from dual
      7      ),
      8      subjects as (
      9        select 1 subject_id, 'Maths' subject_desc from dual
    10        union all
    11        select 2 subject_id, 'Science' subject_desc from dual
    12      ),
    13      student_subjects as (
    14        select 1 student_id, 1 subject_id from dual
    15        union all
    16        select 1 student_id, 2 subject_id from dual
    17        union all
    18        select 2 student_id, 2 subject_id from dual
    19      )
    20      select a.name name, b.subject_desc subject
    21      from student a, subjects b, student_subjects c
    22      where a.student_id = c.student_id
    23      and b.subject_id = c.subject_id;
    24  begin
    25    for rS in cStudents loop
    26      dbms_output.put_line('Student '||rS.name||': '||rS.subject);
    27    end loop;
    28* end;
    Student test1: Maths
    Student test2: Science
    Student test1: Sciencecheers

  • How to write Stored Procedures in JDBC

    Hello EveryBody,
    I have written the following code.
    String str="create procedure info @tempdate varchar(15),@tfno varchar(10)" +
    "as" +
    "begin" +
    "if exists ( select * from details where tdate=@tempdate,fno=@fno"
    ......is there any error...i am getting error at line1.."asbeginif"

    duffymo's point about newlines is exactly on target. Once the stored procedure is stored in the database, you want it to be human readable with the standard utilities, not stored as one long run-on single line. Back when I was consulting, we sometimes charged large sums for simply reformatting a SP to make it readable. On one memorable job, 95% of the bill was for cleaning up that and other formatting issues; the rest was for tracing through execution paths to find the ">" that should have been a ">=".
    You can and probably should put the newlines directly in your java source, e.g.:
    final String str="create procedure info @tempdate varchar(15),@tfno varchar(10)\n" +
    "as\n" +
    "begin\n" +
    "if exists ( select * from details where tdate=@tempdate,fno=@fno\n"
    ...

  • How to search stored procedures being used by rpt files?

    Post Author: Wah!
    CA Forum: General
    Dear all,
    I have a lot of rpt files, each of them at least use one stored-procedure.
    If I want to know a specific stored-procedure is being used by which rpt files,
    is there any fast methods rather than opening the rpt files one by one to check manually?
    Thank you very much!
    Wah!

    Post Author: synapsevampire
    CA Forum: General
    Try one of the 3rd party report documenters, such as Report Miner. Not sure, most do a crappy job about returning the data source...
    Another means would be to run a trace on the database and execute the reports, which is pretty kludgy as well.
    I put documentation into every report, so that exporting to report definition supplies this info.
    A good tip is to add a suppressed report header section and place documentation, revision history, etc., in there.
    -k

  • How to write stored procedures and triggers in oracle

    hai friends ,
    i don't know about storedprocedures and trigger.please help on this
    issues

    Have you tried the documentation yet? PL/SQL Architecture seems to be a good start.
    C.

  • How to call stored procedure in data services?

    Hi, all,
    I'm a newbie and am trying to evaluate Flex for our
    development environment. We use a lot of Oracle stored packages in
    the database to process the business logic. However, I can't seem
    to find a good example to call a stored procedure in flex data
    services.
    Here is a part of my data-management-config.xml:
    <destination id="oracle2">
    <adapter ref="java-dao" />
    <properties>
    <use-transactions>true</use-transactions>
    <source>flex.data.assemblers.SQLAssembler</source>
    <scope>application</scope>
    <metadata>
    <identity property="GKEY"/>
    </metadata>
    <network>
    <session-timeout>20</session-timeout>
    <paging enabled="false" pageSize="10" />
    <throttle-inbound policy="ERROR" max-frequency="500"/>
    <throttle-outbound policy="REPLACE"
    max-frequency="500"/>
    </network>
    <server>
    <database>
    <driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
    <url>jdbc:oracle:thin:xxxxxxxxxxx:1521/racdev</url>
    <login-timeout>15</login-timeout>
    </database>
    <actionscript-class>History</actionscript-class>
    <fill>
    <name>by_nbr</name>
    <sql>select to_char(POSTED,'dd-Mon-yyyy hh:mi:ssAM')
    POSTED, GKEY, EQUSE_GKEY,WTASK_ID,VSL_ID,VOY_NBR,STATUS from
    equipment_history where eq_nbr = #sNbr# order by posted
    desc</sql>
    </fill></server>
    </properties>
    </destination>
    How do I call a stored procedure named
    pk_equipment_history.get(eq_nbr varchar2, o_resultset out
    sys_refcursor) in place of the sql select in the above file? The
    o_resultset output parameter will return exactly the same result as
    the sql. How do I bind the output parameter?
    TIA

    Hi,
    Your question isn't related to Java Programming and should be asked in a [Hibernate forum|http://forum.hibernate.org/]
    Kaj

  • How do I run a database procedure that inserts data into a table from withi

    How do I run a database procedure that inserts data into a table from within a Crystal report?
    I'm using CR 2008 with an Oracle 10i database containing a number of database tables, procedures and packages that provide the data for the reports I'm developing for my department.  However, I'd like to know when a particular report is run and by whom.  To do this I have created a database table called Report_Log and an associated procedure called prc_Insert_Entry that inserts a new line in the table each time it's called.  The procedure has 2 imput parameters (Report_Name & Username), the report name is just text and I'd like the username to be the account name of the person logged onto the PC.  How can I call this procedure from within a report when it's run and provide it with the 2 parameters?  I know the procedure works, I just can't figure out how to call it from with a report.
    I'd be grateful for any help.
    Colin

    Hi Colin, 
    Just so I'm clear about what you want: 
    You have a Stored procedure in your report.  When the report runs, you want that same procedure to write to a table called Report_Log. 
    If this is what you want the simple answer is cannot be done.  Crystal's fundamental prupose is to read only, not write.  That being said, there are ways around this. 
    One way is to have a trigger in your database that updates the Report_Log table when the Stored Procedure is executed.  This would be the most efficient.
    The other way would be to have an application run the report and manage the entry. 
    Good luck,
    Brian

  • How to write a procedure

    hii am new to oracle , can u help me how to write a procedure for the following query
    Transfer Funds between Accounts:
    Table: AccountMaster (AcctNo (primary key), AcctHolderName, currentBal
    Data: 1, 'A', 1000
    2, 'B', 3000
    3, 'C', 4000
    Function: getBalance (AcctNo)
    Stored Proc: tranferFunds (FromAcctNo IN, ToAcctNo IN, Amt IN, result OUT)
    The proc should use the function getBalance (AcctNo) to find out the current balance for account.
    The proc should return a value of 1 if the transfer was successful.
    It should return a value of -1 if the funds are not sufficient in the fromAccount to transfer.
    Thanx ,
    Raj0412

    I would start by asking your teacher to clarify the parts of the assignment that are not clear to you.
    You may also want to read some books.
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/toc.htm
    http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14261/toc.htm

  • Can I create a Stored Procedure That access data from tables of another servers?

    I'm developing a procedure and within it I'm trying to access another server and make a select into a table that belongs to this another server. When I compile this procedure I have this error message: " PLS-00904: insufficient privilege to access object BC.CADPAP", where BC.CADPAP is the problematic table.
    How can I use more than one connection into an Oracle Stored Procedure?
    How I can access tables of a server from a Stored Procedure since the moment I'm already connected with another server?
    Can I create a Stored Procedure That access data from tables of another servers?

    You need to have a Database Link between two servers. Then you could do execute that statement without any problem. Try to create a database link with the help of
    CREATE DATABASE LINK command. Refer Document for further details

  • How to use Stored Procedures in form 6i Blocks

    Dear Friends,
    I would like to know how to use Stored Procedures while creating blocks in Data Block Wizard in forms 6i application.
    Please send me sample code of stored procedure.
    Regards,
    Khader.

    The Data Block Wizard is not for creating stored procedures. It will allow you to use a stored procedure in your form. See the help documentation for how to use the wizard.
    Here's an example of a simple procedure. If you search the database forum or the web, you will find many examples.
    CREATE OR REPLACE PROCEDURE procedure_name (value OUT NUMBER ) AS
    BEGIN
    SELECT COUNT(*) INTO value
    FROM your_table;
    END;
    Message was edited by:
    Mark Roberts

  • How to handle Stored Procedure and Views

    Dear All
    While dealing with Oracle database related scenario. I came across Stored Procedures and Views. Which are complex in nature. Using SAP XI how we can handle them ?
    Is JDBC adaptor is capable of that.? Can you help me Data type structure for oracle.
    How max occur play important role in that. How to identify root and item level structure for oracle
    I am dealing with stored procedures while inserting data. and using views i need to get data from oracle database.
    What is the syntax of query we use to put while using JDBC adaptor?
    Please help and provide bit detail information over this so that i can execute scenario
    Thanks
    Gaurav

    1) jdbc:oracle:thin:@xxx.xxx.xxx.xxx:1521:sid
    2)Occurence==> o,1, >1 , Unbounded
    Occurrence=> ready to accept 0 / 1 / more than 1/ multiple record  (for source) and how it will be passed to target.
    http://help.sap.com/saphelp_erp2004/helpdata/en/b6/0b733cb7d61952e10000000a11405a/frameset.htm
    3)
    <StatementName5>
    <storedProcedureName action=” EXECUTE”>
        <table>realStoredProcedureeName</table>
    <param1 [isInput=”true”] [isOutput=true] type=SQLDatatype>val1</param1>
    </storedProcedureName >
      </StatementName5>
    refer
    http://help.sap.com/saphelp_nw04/helpdata/en/22/b4d13b633f7748b4d34f3191529946/frameset.htm
    http://help.sap.com/saphelp_nw04/helpdata/en/2e/96fd3f2d14e869e10000000a155106/frameset.htm

  • How to implement Stored procedure in OBIEE

    Hi experts
    How to implement Stored Procedure in OBIEE..
    My Input is Date..
    Thanks in advance
    Regards
    Frnds

    Double post :
    Re: How to get the previous monthend data and currentdate data in OBIEE report
    You don't need a stored procedure.
    If you want the amount only for one date, you can use the filter option in the formula :
    FILTER("Sales Facts"."Amount Sold" USING (Time.Day = '31 jan'))You can calculate the last day with the timestampdiff function
    31Jan = 1 Feb - 1 dayIf you want the amount of the month see my post here :
    Re: How to get the previous monthend data and currentdate data in OBIEE report

  • How to move stored procedure output to file

    Hi All,
    Thanks in advance.
    Please let me know how to move the oracle stored procedure output to the flat file.
    By
    Pyarajan

    Hi Pyarajan,
    As David posted, in the Data Flow Task (DFT), you can add an OLE DB Source, and create a connection manager to connect to the Oracle server using the Microsoft OLE DB for Oracle provider. Then, in the OLE DB Source Editor, you can set the “Data access mode”
    to “SQL command” and input the query to execute your Oracle stored procedure. To export the data to a flat file, we need to add a Flat File Destination to the DFT.
    Besides, also note that you need to install the Oracle client on this server, and you may need to edit the tnsnames.ora and sqlnet.ora files to establish the connection to Oracle successfully.
    References:
    http://commerceserverguy.wordpress.com/2011/12/04/ssis-package-tutorial/ 
    http://sqlblog.com/blogs/jorg_klein/archive/2011/06/09/ssis-connect-to-oracle-on-a-64-bit-machine.aspx 
    Regards,
    Mike Yin
    TechNet Community Support

  • How to test Stored Procedure

    I am a MS SQL developer shifting to Oracle PL/SQL...
    I am able to write Stored procedure without problem but don't know how to test it.... Testing is a problem...
    As of now i am asking front end guys to test it, mainly these Stored Procedure are select , insert , update....
    Please help....

    The SQL Developer homepagehas links to demos and tutorials that cover PL/SQL editing and debugging and UnitTesting.
    Sue

Maybe you are looking for

  • New MBP and installed wrong administrator

    Please help, Yesterday I bought me a new MBP (lion) and wanted to transfer all the information from my previous MBP (died on me) from TimeCapsule. First I could not get access with my administrator password which I use for years, so I reset the passw

  • AppleTV 3 only showing Apple logo when connected to very new Panasonic plasma - worked Ok with older Panasonic (2007)

    AppleTV 3 only showing Apple logo when connected to very new Panasonic plasma - worked Ok with older Panasonic (2007) - have reset AppleTV, tried 3 HDMI cables.

  • Missing_indexes

    Hi gurus I have a issue where the secondary indexes are missing on production and i have checked the status and found that the index is not avilable in the database.I have created the index with help of se14 and its solving my issue. Problem is when

  • Sort order changes from ios photos to iphoto

    My photos in an album in the the ios Photo app are in a particular order.  When accessed fro iPhoto, the order is completely different.  How can I mantain the original order?

  • Mass Change for Service master

    Dear Experts, I've tried to do Mass change for service master.. in transaction MASS, i couldnot able to find the object for service master there.. Is there any possiblity to do mass change for Service Master thanks