SQL convet .csv

PROCEDURE PROC_EXCEL (t_file varchar2,
t_sql varchar2) IS
connection_id EXEC_SQL.CONNTYPE default exec_sql.default_connection;
cursorID EXEC_SQL.CURSTYPE;
nIgn number;
columnValue varchar2(10000);
ncols number;
sep varchar2(1);
colName varchar2(1000);
colLen number;
coltype number;
tmp varchar2(32767);
file_nm text_io.file_type;
BEGIN
file_nm := text_io.fopen(t_file,'w');
--tmp := t_label||chr(13); 
--text_io.put(file_nm,tmp); 
tmp:='';
cursorID := EXEC_SQL.OPEN_CURSOR;
BEGIN
EXEC_SQL.PARSE(cursorID, t_sql, exec_sql.V7);
nIgn := EXEC_SQL.EXECUTE(cursorID);
EXCEPTION WHEN OTHERS THEN
MESSAGE('EXEC SQL ERROR, PLEASE CHECK YOUR SQL SCRIPT.. '||SQLERRM);
END;
sep := '';
for i in 1 .. 100000 loop
begin
exec_sql.describe_column(connection_id, cursorId, i, colName, colLen, colType);
exec_sql.define_column(cursorID, i, columnValue, 40000);
--title 
tmp:= tmp || sep ||colName;
sep := ',';
exception when exec_sql.invalid_column_number then
ncols := i-1;
exit;
end;
end loop;
--output title 
tmp:=tmp||chr(10);
text_io.put(file_nm,tmp);
tmp:='';
while (exec_sql.fetch_rows(cursorID) > 0)
loop
sep := '';
for i in 1 .. ncols loop
EXEC_SQL.COLUMN_VALUE(cursorID, i, columnValue);
tmp:= tmp || sep || columnValue;
sep := ',';
end loop;
tmp:=tmp||chr(10);
--tmp:=convert(tmp,'ZHT16BIG5','UTF8'); 
text_io.put(file_nm,tmp);
tmp:='';
END LOOP;
text_io.fclose(file_nm);
EXEC_SQL.CLOSE_CURSOR(cursorID);
EXEC_SQL.CLOSE_CONNECTION;
END;
Edited by: 928060 on 2012/8/30 下午 6:31

Hi,
What is the problem? What can anyone do with your code if you do not articulate your problem or what error you are getting?
What is your Forms version?

Similar Messages

  • SQL Loader - CSV Data file with carraige returns and line fields

    Hi,
    I have a CSV data file with occasional carraige returns and line feeds in between, which throws my SQL loader script off. Sql loader, takes the characters following the carraige return as a new record and gives me error. Is there a way I could handle carraige returns and linefeeds in SQL Loader.
    Please help. Thank you for your time.
    This is my Sql Loader script.
    load data
    infile 'D:\Documents and Settings\user1\My Documents\infile.csv' "str '\r\n'"
    append
    into table MYSCHEMA.TABLE1
    fields terminated by ','
    OPTIONALLY ENCLOSED BY '"'
    trailing nullcols
    ( NAME CHAR(4000),
    field2 FILLER,
    field3 FILLER,
    TEST DEPT CHAR(4000)
    )

    You can "regexp_replace" the columns for special characters

  • SQL 2014 CSV Disks and SCOM Technical Preview

    i'm trying to install system center technical preview on SQL 2014 using CSV but the setup cannot access the cluster name\c$ which has the clusterstorage mount points for CSV
    setup can detect the data and log paths "c:\clusterstorage\volume1\mssql12.mssqlserver\mssql\data\ but unable to create the database in that location
    Hesham Mousa

    Hi Hesham,
    Since the issue is more related to SCOM, I recommend you post the question in the
    System Center - Operations Manager forums. It is appropriate and more experts will assist you.
    Thanks,
    Lydia Zhang
    Lydia Zhang
    TechNet Community Support

  • PL/SQL-Generate CSV file

    I was told I was able to generate out a CSV file through UTL_FILE method. Can someone provide the skeleton of how should I create it in PL/SQL?
    I tried google search but it only says in words and not code itself.
    I have this PL/SQL that I will want to generate a CSV file.
    SET SERVEROUTPUT ON;
    SET TIMING ON;
    DECLARE
        CURSOR C1
        IS
        select balance from contract ;
    BEGIN
        FOR i IN C1 LOOP
    IF i.balance <> '0' THEN
          DBMS_OUTPUT.PUT_LINE('Amount is not 0 '); 
    I will like to put the statement 'Amount is not 0 ' in a CSV file here
         else
         DBMS_OUTPUT.PUT_LINE('Amount is 0 '); 
         END IF;
         end loop;
    END;
    /How am I suppose to do this?
    Edited by: JoannaLee on Aug 26, 2008 7:14 PM

    Your question is a bit confusing. In your subject line, and again in your question, you talk about generating a CSV file. That is a file of comma-separated values (hence the acryonym). But your question seems to be asking about generating a file with a sentence in it-- that would be a flat file but not a CSV file.
    The links that were provided show you exactly how to generate a CSV file based on an arbitrary query.
    If you are not looking to generate a CSV file, and instead you just want to generate a flat file to which you can write data, you'd just need to use the UTL_FILE package. Assuming you're on a recent version of Oracle, you would need to create a directory object, i.e.
    CREATE DIRECTORY directory_name AS 'path_to_directory_on_database_server'Then you'd grant privileges on that directory object to whatever user will own the procedure that wants to write to the directory
    GRANT read, write ON directory_name TO some_userIn your code, you'd just need to open the file and write to it
    DECLARE
      l_file utl_file.file_type;
    BEGIN
      l_file := utl_file.fopen( 'DIRECTORY_NAME', 'name_of_file', 'w' );
      <<Other code>>
      utf_file.put_line( l_file, 'String you want to write to the file' );
      <<More code>>
      utl_file.fclose( l_file );
    END;Justin

  • Writing into Excel file using PL/SQL and formatting the excel file

    Hi,
    I am writing into a excel file using PL/SQL and I want to make the first line bold on the excel. Also let me know if there are any other formatting options when writing into excel.
    Regards,
    -Anand

    I am writing into a excel file using PL/SQL
    Re: CSV into Oracle and Oracle into CSV
    check that thread or search in this forum...

  • SQL Developer Export hangs - version 3.2.20.09

    Hi,
    I installed SQL Developer Version 3.2.20.09 Build MAIN-09.87 and try to export a query into csv file,
    it hangs after writing 100 rows, I don't see the file grows on OS, the progress-bar keeps saying 100 row
    I also tried .xls format, the problem remains.
    the downloaded file is sqldeveloper-3.2.20.09.87.zip (with JDK included)
    Your help is appreciated.

    I ran export for a different SQL, the .csv file was generated.
    Not sure if the issue I encounter is data-related. I want to point out that some of the return data contains ASCII control characters:
    This is the exact SQL for the hanged-export:
    select c.email_addr,c.job_title, regexp_replace(c.job_title,'[[:cntrl:]]','#'),
    t.job_title, regexp_replace(t.job_title,'[[:cntrl:]]','#')
    from HZ_IMP_CONTACTS_T t, my_contact c
    where t.batch_id=100002764150299
    and t.REL_ORIG_SYSTEM_REFERENCE = c.pr_dept_ou_id || ':' || c.row_id
    and rownum < 200
    Hope you can reproduce this issue.
    Thanks,
    Wen

  • How to Create PR from exeternal SQL Server through IDOC

    Dear all,
    I am in trouble while creating PR from exeternal SQL Server through IDOC . although I have created PR from TCODE we19 giving input as well as from function writen below
    My scnerio is from external system(Sql) want to send data to sap to create PR return PR No to SQl Server
    Not having idea how to do
    Basic Type for Idoc : PREQCR01
    Message Type       : PREQCR
    Function Module    : BAP_Idoc_Input1
    Thanxs in Advance

    if you have XI installed,
    than it would be easy,
    just use JDBC channel->XI->SAP IDOC.
    otherwise,
    you can export the table from the SQL to CSV file,
    and import it with LSMW with IDOC PREQCR01.

  • Oracle data int CSV file

    Hello,
    Is there a tool that I can use that capture output of Oracle SQL into CSV files?
    Thanks

    There are many tools that do this - SQLDeveloper is a "free" one (assuming you have a valid database license). TOAD, SQLNavigator, Discoverer etc are other tools you can use for a fee. As noted above, none of these tools can represent LOB data in csv format - they can be only used to export traditional data to csv.
    HTH
    Srini

  • How to use sqlldr for loading data in Oracle 10g xe.

    I want to load data using SQL*LOADER in Oracle DB from a .csv file but it doesn't seems to be working can anyony please help me.I am not get getting how to use sqlldr.
    in CMD in giving this command
    sqlldr hr/hr control='c:/data/record.ctr'
    record.ctr>>load data
    infile 'c:\data\record.csv'
              into table record
    fields terminated by "," optionally enclosed by '"'          
    ( Name,uday, hemant )
    sql table in data base>>CREATE TABLE "RECORD"
    (     "NAME" VARCHAR2(50),
         "UDAY" VARCHAR2(50),
         "HEMANT" VARCHAR2(50)
    record.csv>>name,uday,hemant
    c1,45454,84894
    c2,489654,21322
    can you please tell me how can i get this simple example run.

    C:\>sqlldr scott/tiger
    control = data.ctl
    SQL*Loader: Release 10.1.0.2.0 - Production on Thu Sep 14 17:06:46 2006
    Copyright (c) 1982, 2004, Oracle.  All rights reserved.
    Commit point reached - logical record count 3
    SQL> conn scott/tiger
    Connected.
    SQL> create table data (col1 varchar2(40),col2 varchar2(40),col3 varchar2(40));
    Table created.
    SQL> select * from data;
    COL1                 COL2                 COL3
    name                 uday                 hemant
    c1                   45454                84894
    c2                   489654               21322
    SQL>
    data.csv
    name,uday,hemant
    c1,45454,84894
    c2,489654,21322data.ctl
    load data
    infile 'c:\data.csv'
    append
    into table data
    fields terminated by ','
    optionally enclosed by '"'
    (col1,col2,col3)i hope it will solve ur problem

  • Guide: how to extract text from any iOS notes app backup on your Mac

    Scenario: you had a sweet notes app like DailyNotes, perhaps one that your girlfriend installed while you weren't looking. So it was on her iTunes account, lets say. Then one day you upgrade to a new iOS version and backup all your data. For whatever reason you erase your iPad, install the new version, and recover back all the apps from the backup. (Maybe you were beta testin g prior to that so you wanted to wipe it clean.) Still your data is gone! Or is it?
    "Fortunately" you backed up. However all that this means is that the text you entered into DailyNotes is stored somewhere in your backup, inside of a file named something like
    "8f5d7ff4111c9b9e4c8dbb7395efdce9c260e0de-20110814-232318", encoded in a .sqlite database file wrapped inside that data.
    Now, if you reinstall the DailyNotes app (or whatever) off of the app store under your own user account, will you get your data back as well? I honestly don't know. But I tried to find out, and I could get no straight answers. Most people said I'd lose my data, and the only way to get back my data would be to restore from the old backup, which of course would erase my current data! So I'd have to backup, then restore from the older backup, then restore from the newer backup again. Does anyone realize how LONG these backups and restores take? FOREVER! I don't have that much time guys. I just need a fast way to access a simple text file. Why does iOS make this such a chore? It's my own content, my own data, which is mine, my copyright, my intellectual property, and the iOS is hiding it from me inside an anonymously-named text file.
    SO HERE'S WHAT YOU DO:
    Download mono framework here and install it: (free)
    http://www.go-mono.com/mono-downloads/download.html
    (this can be easily uninstalled later, it has an uninstaller app)
    Download iPhone Backup Extractor here and extract it in your Downloads directory: (free)
    http://www.iphonebackupextractor.com./free-download/
    (this can be easily uninstalled later, just delete the folder)
    Download SQLite Database Browser 2.0 b1, and extract it in your Downloads directory: (free)
    http://sourceforge.net/projects/sqlitebrowser/
    (this can easily be uninstalled later, just delete the app)
    You can move the two apps to your Applications directory if you intend to keep them long-term, but you can run them just fine from the Downloads directory which will make them easier to identify and erase after you're done, if you don't plan to keep them around.
    Go to Finder and open the iPhone Backup Extractor directory. Resize that window to the side of your screen.
    Go to Terminal and set the window where you can see part of it if the previously mentioned Finder window from the last step was floating on top of it.
    Type "cd " (yes that's c, d, space) in Terminal then hit command-Tab to switch to Finder.
    Drag the folder icon from the title bar of the finder window into the Terminal window that's now in the background. For you newbies, the "title bar" is the VERY topmost edge of the window (the frame of the window) which should have a folder next to the words, "iPhone Backup Extractor" visible in it. You're clicking and dragging THAT folder icon into the terminal window in the background. HIT ALT-TAB AGAIN WHEN DONE.
    Now you're back in the Terminal and it should say:
    "cd /Users/yourname/Downloads/iphonebackupextractor-latest" after the unix prompt. HIT ENTER.
    Now type:
    mono iPhoneBackupExtractor.exe
    This will run the iPhone Backup Extractor app. It takes a few minutes to load because mono is slow (it's emulating Windows basically). Be patient.
    NOTE: The Backup Extractor can only see backups stored on your boot drive that are in the users folder of whatever user you're currently logged in as. So if your backup is on an external drive or a CD, etc., just copy it to the desktop.
    Once iPhone Backup Extractor loads, you'll see its window where you can select the backup. Select whichever one you want to work with. Then hit Expert mode. Each app that was on your device at the time you made the backup will have a directory shown. It will be named something like:
    com.ramki.dailynotes
    Expand the one you want to recover data from by clicking the plus sign next to it. Then expand the Documents directory for it. You'll see a file called something like Daily_Notes.sqlite. Click the dark black box next to this and a checkmark should appear.
    Once you've checked the file to recover, click "Extract selected" below and save to your Desktop (or wherever!).
    Now quit iPhone Backup Extractor unless you have other data to also extract.
    NEXT... OPEN the app SQLite Database Browser 2.0 b1.
    Once it loads, open your Daily_Notes.sqlite file (or whatever .sqlite file you extracted, not necessarily Daily_Notes, that's just my example). If you followed my previous steps that file will be on your Desktop.
    Once it loads you'll see three buttons at the center of the window near the top called, "Database Structure," "Browse Data," and "Execute SQL." CLICK ON "Browse Data."
    Now on the left-hand side of the window there is a pop-up menu with the word "Table: [POP-UP-MENU-IS-HERE] "... CLICK on the pop-up menu. It will actually say the name of one of the database files that's within the SQLite database, something like "ZAPPSTATE" or "ZDAYDATA" or whatever (not "POP-UP-MENU-IS-HERE", that was just text I put as a placeholder since it could be anything really).
    Now that you've clicked the pop-up menu, select each item one by one and look at the data that appears in the table.
    (Don't worry, you're just working with a COPY of the file, so if you accidentally delete anything it's not a real problem, just delete the .sqlite file and start the steps over from the beginning of this message.)
    You should eventually find a table that has the text that you're looking for! Mine was called "ZDAYCONTENT".
    WHEN YOU ARE LOOKING AT THE DATABASE TABLE, it looks like an Excel spreadsheet. That means you may have to double-click on the database cell to get it to show you the entire contents of that part. (It only shows a truncated text string in each cell, but if you double-click, a new window will open on top of the current window, showing the full text that was in there.) Now you can copy the text out and paste it into another app like Text Edit or MS Word or Pages, etc. You can also export the data in the File Menu > Export to an SQL or CSV file. (CSV is a text file where the data is all there, just separated by commas. This can then be imported into Excel or Numbers or another database or printed, etc., or just opened into Pages or Word or BBEdit etc.)
    CAVEATS: Dates will often be shown as a weird number like 3780 or 2863 etc. You may have to figure out on your own what this date means. I honestly have no clue. SQLite Database Browser does not seem to support viewing or exporting PNG and image files.
    Other than that good luck. Post any questions here.
    AND HEY, APPLE: MAKE THIS EASIER! FILES BELONG IN FOLDERS, NOT INSIDE FOLDERS THAT ARE INSIDE APPS!!!

    Restore iPad data from backup files, with the help of iPad Data Extractor:
    1. Settings>General>Reset>Erase all content and settings
    2. You'll be asked twice to confirm
    3. You'll see Apple logo and progress bar
    4. You'll see a big iPad logo on screen
    5. Configuration start
    6. Set language
    7. Set country
    8. Select Network and input Password>Join
    9. Enable Location Service>Next
    10. You'll be given 3 options (a) Setup as New iPad (b) Restore from iCloud Backup (c) Restore from iTune Backup
    11. Select Restore from iTune Backup
    12. You will see picture of USB cable pointing towards iPad
    13. Connect iPad to iTune (make sure iTune is on standby)
    14. Tap Continue (computer)
    15. Restore iPad from Backup (computer)
    16. See progress bar with estimated time (computer)
    17. See Restore in Progress on iPad
    18. See Apple logo
    19. See Apple and Progress Bar
    20. Slide to Unlock
    21. Copying Apps back to iPad (computer)
    22. You'll see Loading/Installing/Waiting below the Apps (iPad)
    23. Sync Music/Podcast/Movies to iPad (computer)
    24. Sync completed (computer)

  • Help in finding the error

    Hi All,
    I have executed the folloowing scripts
    create or replace function aj_dump_csv( p_query in varchar2,
    p_separator in varchar2
    default ',',
    p_dir in varchar2 ,
    p_filename in varchar2 )
    return number
    AUTHID CURRENT_USER
    is
    l_output utl_file.file_type;
    l_theCursor integer default dbms_sql.open_cursor;
    l_columnValue varchar2(2000);
    l_status integer;
    l_colCnt number default 0;
    l_separator varchar2(10) default '';
    l_cnt number default 0;
    begin
    l_output := utl_file.fopen( p_dir, p_filename, 'w' );
    dbms_sql.parse( l_theCursor, p_query, dbms_sql.native );
    for i in 1 .. 255 loop
    begin
    dbms_sql.define_column( l_theCursor, i,
    l_columnValue, 2000 );
    l_colCnt := i;
    exception
    when others then
    if ( sqlcode = -1007 ) then exit;
    else
    raise;
    end if;
    end;
    end loop;
    dbms_sql.define_column( l_theCursor, 1, l_columnValue,
    2000 );
    l_status := dbms_sql.execute(l_theCursor);
    loop
    exit when ( dbms_sql.fetch_rows(l_theCursor) <= 0 );
    l_separator := '';
    for i in 1 .. l_colCnt loop
    dbms_sql.column_value( l_theCursor, i,
    l_columnValue );
    utl_file.put( l_output, l_separator ||
    l_columnValue );
    l_separator := p_separator;
    end loop;
    utl_file.new_line( l_output );
    l_cnt := l_cnt+1;
    end loop;
    dbms_sql.close_cursor(l_theCursor);
    utl_file.fclose( l_output );
    return l_cnt;
    end dump_csv;
    The above script runs successfully
    then I run the following script
    create or replace procedure aj_test_dump_csv
    as
    l_rows number;
    begin
    l_rows := dump_csv( 'select *
    from all_users
    where rownum < 25',
    ',', 'C:\Documents and Settings\amit_jaiswal01\My Documents\amit\Stuff\Pl-SQL', 'aj_from_rec.csv' );
    end;
    I get the error script executed with compile errors
    Can anyone help?
    Regards.

    Run the two scripts seperately.
    SQL> create or replace procedure aj_test_dump_csv
    as
    l_rows number;
    begin
    l_rows := aj_dump_csv( 'select *
    from all_users
    where rownum < 25',
    ',', 'C:\Documents and Settings\amit_jaiswal01\My Documents\amit\Stuff\Pl-SQL', 'aj_from_rec.csv' );
    end;
    If this gives you any error, then run the below statement to view the error,
    SQL>SHOW ERROR
    Copy the error message which you get and update us.

  • Inserting a tab delimited file

    Hi there,
    I am inserting data into a database from text files. I can easily do this in sql with csv files but I need to be able to do it with tab delimited files. I know you can do this from the built in Oracle tool (I am using express edition) but I was wandering if anyone know how to write a script for it in sql.
    Any help would be greatly appreciated.
    Thanks

    If you are using SQL Loader to load the data use below syntex
    FIELDS TERMINATED BY X'9'
    The X'9' is Hexadecimal Format -> X
    and Hex 9 is the ASCII code of the TAB character.
    Check out the link for more details:
    http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:533222350291
    Regards
    Arun

  • Export journalized data in real time

    Hello,
    I must pull journalized data in real time out of Oracle DB source.
    my package has ODIWaiForData operator and interface which triggers only in case of Journalized Data in my source table. Interface loads data to target Oracle table in real time and it works.
    Is it possible to send Journalized Data out of Oracle database in real time? Maybe some insert/update statements within sql file, csv file or through ODIOSCommand operator somehow?
    Regards

    Hi,
    did you already see about Logminer?
    Cezar Santos
    www.odiexperts.com

  • Links in excel tables for ilife 08

    So all my tables disappeared.
    I figured out how to paste a new table in. Although it's not as nice and easy as before, I can deal.
    I used tables to then link to other websites. However, copying & pasting from excel to iweb, I can't highlight to then link a word phrase to another site.
    Any suggestion on what I should do?
    I have to start from scratch so any suggestions would be appreciated. Even if it means not using excel.

    Hi,
    As far as I know, Excel is a good way to use as database file. Whether it is a personal list of phone numbers, a contact list for members of an organization or team, or a collection of coins, cards, or books, an Excel database file makes it easy to
    enter, store, and find specific information.
    You could choose Excel,SQL,Access, CSV or XML as database according to your goal.
    Here are some articles to introduce "How to use Excel table as database":
    http://chandoo.org/wp/2012/04/02/using-excel-as-your-database/
    http://spreadsheets.about.com/od/datamanagementinexcel/ss/excel_database.htm
    Please Note: Since the web site is not hosted by Microsoft, the link may change without notice. Microsoft does not guarantee the accuracy of this information.
    Regards,
    George Zhao
    TechNet Community Support

  • Excel tables for database usage in external programs such as game engines?

    Hello!
    Where can I find more information about using Excel tables for database usage in external programs such as game engines? Do I have to use SQL, CSV or XML?
    Thank you!

    Hi,
    As far as I know, Excel is a good way to use as database file. Whether it is a personal list of phone numbers, a contact list for members of an organization or team, or a collection of coins, cards, or books, an Excel database file makes it easy to
    enter, store, and find specific information.
    You could choose Excel,SQL,Access, CSV or XML as database according to your goal.
    Here are some articles to introduce "How to use Excel table as database":
    http://chandoo.org/wp/2012/04/02/using-excel-as-your-database/
    http://spreadsheets.about.com/od/datamanagementinexcel/ss/excel_database.htm
    Please Note: Since the web site is not hosted by Microsoft, the link may change without notice. Microsoft does not guarantee the accuracy of this information.
    Regards,
    George Zhao
    TechNet Community Support

Maybe you are looking for

  • Opening a PDF URL in Adobe Reader

    Hello All, I have a query, we use SharePoint 2010 and I've read and followed the Adobe article on how to integrate SharePoint 2010 with Adobe Reader X so that the PDF's held within a document library open within Adobe Reader X and checks out in Share

  • App Store apple ID problems

    I'm writing on behalf of my mum, Basically in the simplest way I can put it every time I try to update apps on my mums iPhone its asks for my dad apple ID password instead of my mums account, i go on settings and iCloud, apple ID are all logged in to

  • Is the MacMini package still availble at Costco?

    Does anyone know if Costco is still selling the G4 MacMini package with wireless mouse/keyboard and Applecare??? Suddenly I have found myself to be in the market for a MacMini and I recall seeing that hermetically sealed plastic package at some point

  • CVS with SSH Protocol 2 and Jdeveloper 9.0.3 production release

    I have configured WinCVS with NetworkSimplicity SSH using Protocol 2 key generation and it works fine. When I try to configure CVS in JDeveloper, on the test page I get: Testing connection... Timed out waiting for process to exit. Connection test fai

  • 7.5.5 not recognizing a game application

    I have a lovely little copy of 7.5.5 running via Basilisk II. However, it doesn't seem to recognize the games I've saved over the years, specifically Odyssey: Legend of Nemesis. According to the game designer, the game should run in 7 and 9 neatly. W