How to create a procedure in oracle to write the data into file

Hi All,
I am just wondered on how to create a procedure which will do following tasks:
1. Concat the field names
2. Union all the particular fields
3. Convert the date field into IST
4. Prepare the statement
5. write the data into a file
Basically what I am trying to achieve is to convert one mysql proc to oracle. MySQL Proc is as follows:
DELIMITER $$
USE `jioworld`$$
DROP PROCEDURE IF EXISTS `usersReport`$$
CREATE DEFINER=`root`@`%` PROCEDURE `usersReport`(IN pathFile VARCHAR(255),IN startDate TIMESTAMP,IN endDate TIMESTAMP )
BEGIN
SET @a= CONCAT("(SELECT 'User ID','Account ID','Gender','Birthdate','Account Registered On') UNION ALL (SELECT IFNULL(a.riluid,''),IFNULL(a.rilaccountid,''),IFNULL(a.gender,''),IFNULL(a.birthdate,''),IFNULL(CONVERT_TZ(a.creationDate,'+0:00','+5:30'),'') INTO OUTFILE '",pathFile,"' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '' LINES TERMINATED BY '\n' FROM account_ a where a.creationDate>='",startDate,"' and a.creationdate <='",endDate,"')");
PREPARE stmt FROM @a;
EXECUTE stmt;
DEALLOCATE PREPARE stmt ;
END$$
DELIMITER ;
Regards,
Vishal G

1. Concat the field names
Double Pipe (||) is the concatenation operator in Oracle. There is also a function CONCAT for this purpose
2. Union all the particular fields
Not sure what do you mean by UNION ALL particular fields? UNION ALL is a set operation applied on two different result sets that have the same projection.
3. Convert the date field into IST
SQL> select systimestamp "Default Time"
  2       , systimestamp at time zone 'Asia/Calcutta' "IST Time"
  3    from dual;
Default Time                                       IST Time
05-05-15 03:14:52.346099 AM -04:00                 05-05-15 12:44:52.346099 PM ASIA/CALCUTTA
4. Prepare the statement
What do you mean by prepare the statement?
5. write the data into a file
You can use the API UTL_FILE to write to a file.

Similar Messages

  • How to write the data into EEPROM using Labview?

    How to write the data into EEPROM using Labview?

    You would need some sort of EEPROM programmer. Typically might
    communicate with it via serial. I don't know how you would do this in
    LV. You would need to have the command protocol for the programming
    device to start with.
    Doug De Clue
    gpibssx wrote in message news:<[email protected]>...
    > How to write the data into EEPROM using Labview?

  • How to create a calendar picker that auto populates the date in adobe XI Professional?

    I'm looking to do this in a  form i'm creating.

    There is no built-in date picker (for Acrobat/Reader on Windows/Mac at least) for forms created with Acrobat. I'm hoping that will change someday, but in the mean time you can use the date picker provided by: http://www.formrouter.com/tools/
    There is also a PDF developer (not me) who sells a JavaScript-based date picker using custom dialogs, which is much more convenient. You can PM me if you want contact information.

  • How to writing the data into the file at the same frequency of data acquisition using myRIO

    Hi everyone,
    I have a question regarding data acquisition fequency and data recording frequency of myRIO. Hope you guys can help me out.
    Basically, I want to acquire voltage input at analog input 0 at the frequency of 1kHz and then write the data into a file (tdms format). 
    However, I always found there were only 55 or 56 data points recorded every second in the data file (see the excel sheet). 
    To confirm my data acquisition was performed at the correct frequency, I added a small function in the main loop to indicate the time spent between two acquisition events. 
    To my surprise, the period of data acquistion is correct (1ms or 1kHz) but there are only 55 or 56 data point per second recorded in the data file.
    How can I record every data point acquired by the analog input?
    Thank you!
    P.S. I am very new to myRIO. How can I manually set the system time for myRIO? The default time of my myRIO is wrong. 
    Best,
    Tengyang
    Attachments:
    test result.xlsx ‏16 KB
    Main with timed loop.vi ‏122 KB
    test result.xlsx ‏16 KB

    Have a look at the Jakarta POI project, they have a Java API for creating Word documents.
    http://jakarta.apache.org/poi/hwpf/index.html

  • How to create a procedure function with a return value of ref cursor?

    Can anybody provide a sample about how to create a procedure function with a return value of REF CURSOR?
    I heard if I can create a function to return a ref cursor, I can use VB to read its recordset.
    Thanks a lot.

    http://osi.oracle.com/~tkyte/ResultSets/index.html

  • How to create a user in oracle.

    how to create a user in oracle level.i know how to create from front end.can any body suggest.how to create oracle user from backend.
    Thanks,
    Dave

    Hi,
    We can use the 'hr_user_acct_internal.create_fnd_user' API to create the users. The sample code is as follows:
    BEGIN
    apps.hr_user_acct_internal.create_fnd_user
    (p_user_name => 'XXX',
    p_password => 'XXX',
    p_employee_id => 1234(This is the person id from per_all_people_f),
    p_user_id => x_user_id,
    p_user_start_date => SYSDATE,
    p_email_address => 'XXX',
    p_description => 'XXX',
    p_password_date => NULL
    COMMIT;
    END;
    and to add the responsibility to the user, we can use the following code.
    BEGIN
    fnd_user_pkg.addresp
    (username => 'XXX',
    resp_app => user_res_rec.application_short_name,
    resp_key => user_res_rec.responsibility_key,
    security_group => 'STANDARD',
    description => 'DESCRIPTION',
    start_date => SYSDATE,
    end_date => NULL
    END
    Best Regards
    Arun Kumar S.R
    Apps Associates

  • How to create a wallet in oracle RAC environment

    How to create a wallet in oracle RAC environment.
    While running following command "alter system set encryption key identified by "thalesdata4";
    I am getting error message "cannot auto create wallet" or "failed to open wallet.
    Please suggest correct way to create a wallet in RAC environment.
    Thanks
    Sudhir

    hi,
    please refer for detailed explanation
    Master Note for SSL Configuration in Fusion Middleware 11g [ID 1218695.1]
    regards

  • How to create a database in ORACLE 8i

    How to create a database in ORACLE 8i

    hello ...
    enter in
    http://www.oracle.com/pls/db102/portal.portal_db?selected=2 between demand and type in "create database"
    or read others docs ORACLE.
    AF

  • How to create xml file from Oracle and sending the same xml file to an url

    How to create xml file from Oracle and sending the same xml file to an url

    SQL/XML (XMLElement, XMLForest, XMLAgg, etc) and UTL_HTTP.
    Whether that works for you with the version of Oracle you have, your requirements, and needs is another story. A little detail goes a long way.

  • How To create Connection Pooling in Oracle 10.1.2.0 Application Server

    Hi,
    How to create Conncetion Pooling in Oracle 10g Application Server. I am using 10.1.2.0 version.
    Thanx
    Dhans

    Hi,
    How about these tutorials?
    http://www.oracle.com/technology/tech/java/newsletter/articles/oc4j_data_sources/oc4j_ds.htm
    http://www.oracle.com/technology/products/jdev/tips/duff/mysql_and_oc4j3.html

  • How to create  a procedure to send a mail if the Database is down?

    Hi,
    I have created the below procedure to send a mail if the count is less than 1300. It scheduled daily @ 15 30 hrs. Its fine.
    CREATE OR REPLACE procedure SCOTT.hrsmail
    is
    v_count number;
    begin
    Select count(*) into v_count from emp;
    if v_count < 1300
    then
    UTL_MAIL.send(sender => '[email protected]',
    recipients => '[email protected]',
    cc => '[email protected]',
    bcc => '[email protected]',
    subject => 'Testing the UTL_MAIL Package',
    message => 'If you get this, UTL_MAIL package
    else
    null; --what you want to do here
    end if ;
    end;
    Sometime the Database is down, so the job is not running.
    How to create a procedure to send a mail if the database is down?
    Pls help me. Its highly appreciated.
    Thanks
    Nihar

    nihar wrote:
    How to create a procedure to send a mail if the database is down?And what if the database is up, but the network down? Or the database up and mail server down? Or mail server undergoing maintenance?
    There are loads of "+What if's+" - and in that respect, playing "+What if database is down..+" in this case does not make any sense. You do not use the database to monitor its own up/down status. You do not rely just on SMTP as notification protocol that the database is down.
    The correct approach would be using something like SNMP as the monitoring protocol. A monitoring system that can process SNMP and perform some basic root cause analysis (e.g. network to the database server down, database server status unknown). And this system supporting notification methods like SMTP, SMS and so on.

  • How to create ODBC connection between Oracle 10g and MS SQL Server

    Hi,
    Can someone help us with the steps to create an ODBC connection between Oracle APPS using Oracle 10g database and MS SQL Server.
    Requirement is to extract the transactional data from MS SQL Server on a daily basis and dump it into Oracle tables for an interface to be run. Currently it is being done through Dataloader tool which we feel is causing the data issue with Arabic characters. We want to create the ODBC directly between Oracle and MS SQL Server and check if the data is being pulled correctly.
    The data is in sql server 2000 which has data in Arabic_CI_AS character set which is moved to Oracle 10.2.0.3 database with characterset AL32UTF8. The table data is moved to oracle using the dataloader 3.6 standard edition licensed version. We cannot change the character set of Sql Server 2000.
    Please help
    Thanks
    Shanil

    Hi,
    If you're trying to PULL data from SQLServer into an Oracle database, you wouldnt use Oracle ODBC driver for that, so you may want to post in the Heterogeneous Services forum instead:
    Heterogeneous Connectivity
    If you're trying to PUSH data from SQLServer into an Oracle database, you could use ODBC but most folks use OLEDB for that, and the following note on MOS should help:
    How to Create a Sql Server Linked Server With The Oracle Provider for OLE DB     (Doc ID 191368.1)
    As with any NLS related issue, the first thing to do is dump the codepoints of the data in the Oracle database to see if it is stored validly, rather than relying on what the data "looks like" from some tool or other. It's best to check a single row, with only a few characters in it if you can, and you can do that via
    SELECT DUMP(<columname>,1016) FROM <tablename> WHERE ...
    Hope it helps,
    Greg

  • How to create database link from oracle to sql server

    Please help with how to create database link from oracle to sql server
    Best regards,
    Vishal

    Please help with how to create database link from oracle to sql server
    Best regards,
    Vishal
    Hi Vishal,
    I found a lof of information regarding how to create a database link from Oracle to SQL Server, please see:
    https://www.google.co.in/?gws_rd=cr&ei=vd3XUvGFO8TgkAXqlYCADg#q=how+to+create+database+link+from+oracle+to+sql+server
    We discuss SQL Server related issue in this forum. If you have any more question regarding Oracle, please post it in Oracle communities forum for better support.
    Regards,
    Elvis Long
    TechNet Community Support

  • How to create new database on Oracle 10g

    Hi All,
    Can any one tell me how to create new database on oracle 10g.
    Thanks in Advance for your help.

    again some confusion here.....
    u said u need a new database in your first post and now you saying u need a new schema..
    one database has many schemas(users)..... ex: scott,sys,system are few of them...
    now it depends you need seperate database for test,dev environment - this is in the case u have many schemas under each database and many tables(objects) under each schema.
    OR
    You just need a separate schema (in same db) for test,dev environment...where in you will have multiple tables in each schema...U need to know the dba credentials of the db to create a new schema.
    ideally u need to have different database...You can create one with out sys/system(oracle users) password as these passwords are db dependent.
    what you need is access to the any machine where server is installed(can be the same mc where you have your dev db or a diff machine) and that will be the machine where your db will be installed (can do it through database configuration assistance),ofcourse you will need windows authentication for this.
    so you login to the same machine or access it from your machine using remote login.
    I hope that is clear.Hope i am not listing things that you already know..Just did it coz of confusion between db and schema
    Message was edited by:
    coolguy

  • How to create Invoice Approval in oracle Payable R12 ?

    Hi All..
    Can any one let me know how to create Invoice Approval in oracle payable R12?

    pl.go thru following link.
    http://oracleerpfunctional.blogspot.in/2012/08/ap-invoice-approval-workflow-setup-and.html
    http://oracleerpfunctional.blogspot.in/2012/08/oracle-approvals-management-ame-setup.html
    http://www.scribd.com/doc/101107120/Oracle-Payables
    HTH
    Sanjay

Maybe you are looking for