Export data into text file

Hi all,
I want to export table data into a delimeted text file with SQL*Plus.
[edit]
Sorry, non delimited text file
[edit]
Example:
CREATE TABLE delim (
col_a VARCHAR2(20),
col_b VARCHAR2(40)
value stored in
col_a = FISH_1
col_b = FISH_2
spool x:\test_1.lst
set feedback off;
set HEADING off;
set pagesize 0;
set linesize 60;
select col_a, col_b
from table delim;
spool off;
=>
FISH_1
FISH_2
When I now do the same with
set linesize 62;
the reslut is like this
=>
FISH_1 FISH_2
In the output of the second example there is a blank between col_a and col_b.
I have to export the column data without this one blank between columns.
Is there any way to do this?
Thanks and cheers,
ben
Message was edited by:
ben512

Well in your example there is one space between the two columns, anyway you can see in my previous example that there is a set colsep and that show what you want.
But here is another example:
Oracle Database 10g Enterprise Edition Release 10.2.0.2.0 - 64bit Production
With the Partitioning, OLAP and Data Mining options
SQL> create table test (
  2  col_a VARCHAR2(5),
  3  col_b VARCHAR2(3)
  4  );
Table created.
SQL>
SQL> insert into test (col_a, col_b)
  2  values('abc', 'FA');
1 row created.
SQL>
SQL> insert into test (col_a, col_b)
  2  values('def', 'KL');
1 row created.
SQL> insert into test values ('12345','123');
1 row created.
SQL> rem if you don't want to have a space between the two columns then
SQL> set head off
SQL> set colsep ""
SQL> select col_a, col_b from test;
abc  FA
def  KL
12345123
SQL> rem if you want to have one space between the two columns then
SQL> set colsep " "
SQL> select col_a, col_b from test;
abc   FA
def   KL
12345 123
SQL>

Similar Messages

  • Exporting data into text file

    Hi!
    I use this process in apex to export data from table into txt files with fixed length, so without any delimeter
    >
    declare
    v_file_name VARCHAR2 (2000) := 'test.txt';
    id varchar2(9);
    worker varchar2(30);
    address varchar2(26);
    begin
    OWA_UTIL.mime_header ('application/txt', FALSE);
    htp.p('Content-Disposition:attachment;filename="'|| v_file_name|| '"');
    OWA_UTIL.http_header_close;
    FOR x in (select id id from workers where col00 like '1000')
    LOOP
    select col01,col02,col03 into id, worker, addressfrom un_web_prenosi where id = x.id;
    htp.p(id||worker||address);
    END LOOP;
    apex_application.g_unrecoverable_error:=true;
    exception when others then
    null;
    end;
    and I have problem, because if I open file with notepad is everything in one line, but if I open file in notepad++ or I copy content of file in word then I see contents just like it should be (each record in one line). Do you know how can I solve this problem?

    I solved my problem. I forget to put chr(13) into htp.p(id||worker||address); so this line must be like htp.p(id||worker||address||chr(13));

  • Spool SQl data into text file using dynamic sql

    Hi,
    I am spooling output data into text file using command
    select 'select t.mxname,bo.lxtype,t.mxrev'||chr(10)||'from mx_1234567'||chr(10)||
    'where <condition>';
    here mxname varchar(128),lxtype(128),mxrev(128) all are of varchar type.I want the output in format
    e.g Part|1211121313|A
    but due to column width the output,I am getting is with spaces.
    "Part then blank spaces |1211121313 then blank spaces |A"
    how can I remove these spaces between columns.I used set space 0 but not working.
    Thanks in advance.
    Your help will be appreciated.

    Hi Frank,
    I have seen your reply for SET LINE SIZE function. But, I could not be able to understand it.
    I am facing similar kind of issue in my present project.
    I am trying spool more than 50 columns from a table into flat file. Because of more column lengths in few columns, i am getting space. There are so many columns with the same issue. I want to remove that space.so that, data can fit perfectly in one line in .txt file without any wrap text.
    Below is my sample query.sql. Please let me know the syntax. My mail id : [email protected]
    --Created : Sep 22,2008, Created By : Srinivasa Bojja
    --Export all Fulfillments
    --Scheduled daily after 1:00am and should complete before 3:30am
    WHENEVER SQLERROR EXIT SQL.SQLCODE
    SET LINESIZE 800
    SET WRAP OFF
    SET PAGESIZE 800
    SET FEEDBACK OFF
    SET HEADING ON
    SET ECHO OFF
    SET CONCAT OFF
    SET COLSEP '|'
    SET UNDERLINE OFF
    SPOOL C:\Fulfillment.txt;
    SELECT SRV.COMM_METHOD_CD AS Method,
    SRV.SR_NUM AS "Fulfillment Row_Id",
    CON.LAST_NAME AS "Filled By"
    SRV.SR_TITLE AS Notes,
    SRVXM.ATTRIB_04 AS "Form Description"
    FROM SIEBEL.S_SRV_REQ SRV,
    SIEBEL.S_SRV_REQ_XM SRVXM,
    SIEBEL.S_USER USR,
    SIEBEL.S_CONTACT CON
    WHERE SRV.ROW_ID = SRVXM.PAR_ROW_ID AND
    SRV.OWNER_EMP_ID = USR.ROW_ID AND
    CON.ROW_ID= SRV.CST_CON_ID;
    SPOOL OFF;
    EXIT;

  • Help to export data into a file

    Hi,
      I am having more than 200 columns in a table. Client wants to export the data into a file with all 215 columns data. When i write the select * from tablename into a spool file. It is getting the data into a multiple lines however client wants each record into a single line.(right now records are getting into multiple lines). I tried to use to_nclob(columnname1)....to_nclob(column215), this way it is getting a single line for each record but it is taking much time(means in a table we have 10M records and explain plan is showing 3 days to export the file). Could you please help me how we can achieve these type of functionalities.
    Thanks in advance

    user586 wrote:
    Hi,
      I am having more than 200 columns in a table. Client wants to export the data into a file with all 215 columns data. When i write the select * from tablename into a spool file. It is getting the data into a multiple lines however client wants each record into a single line.(right now records are getting into multiple lines). I tried to use to_nclob(columnname1)....to_nclob(column215), this way it is getting a single line for each record but it is taking much time(means in a table we have 10M records and explain plan is showing 3 days to export the file). Could you please help me how we can achieve these type of functionalities.
    Thanks in advance
    Hardly surprising it's taking ages to export 10 million rows, if you're doing it through SQL*Plus, as that involves transporting all the data over the network to the client, which is then rendering all that data in the display (which can be slow to scroll, depending on the size of the window) etc.
    Better to get the database to access the file system directly, using UTL_FILE (though this does mean that the file is produced on the server) and then transfer the resultant file to where it needs to go.
    Example of a generic template to use as a starting point...
    As sys user:
    CREATE OR REPLACE DIRECTORY TEST_DIR AS '\tmp\myfiles'
    GRANT READ, WRITE ON DIRECTORY TEST_DIR TO myuser
    As myuser:
    CREATE OR REPLACE PROCEDURE run_query(p_sql IN VARCHAR2
                                         ,p_dir IN VARCHAR2
                                         ,p_header_file IN VARCHAR2
                                         ,p_data_file IN VARCHAR2 := NULL) IS
      v_finaltxt  VARCHAR2(4000);
      v_v_val     VARCHAR2(4000);
      v_n_val     NUMBER;
      v_d_val     DATE;
      v_ret       NUMBER;
      c           NUMBER;
      d           NUMBER;
      col_cnt     INTEGER;
      f           BOOLEAN;
      rec_tab     DBMS_SQL.DESC_TAB;
      col_num     NUMBER;
      v_fh        UTL_FILE.FILE_TYPE;
      v_samefile  BOOLEAN := (NVL(p_data_file,p_header_file) = p_header_file);
    BEGIN
      c := DBMS_SQL.OPEN_CURSOR;
      DBMS_SQL.PARSE(c, p_sql, DBMS_SQL.NATIVE);
      d := DBMS_SQL.EXECUTE(c);
      DBMS_SQL.DESCRIBE_COLUMNS(c, col_cnt, rec_tab);
      FOR j in 1..col_cnt
      LOOP
        CASE rec_tab(j).col_type
          WHEN 1 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_v_val,2000);
          WHEN 2 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_n_val);
          WHEN 12 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_d_val);
        ELSE
          DBMS_SQL.DEFINE_COLUMN(c,j,v_v_val,2000);
        END CASE;
      END LOOP;
      -- This part outputs the HEADER
      v_fh := UTL_FILE.FOPEN(upper(p_dir),p_header_file,'w',32767);
      FOR j in 1..col_cnt
      LOOP
        v_finaltxt := ltrim(v_finaltxt||','||lower(rec_tab(j).col_name),',');
      END LOOP;
      --  DBMS_OUTPUT.PUT_LINE(v_finaltxt);
      UTL_FILE.PUT_LINE(v_fh, v_finaltxt);
      IF NOT v_samefile THEN
        UTL_FILE.FCLOSE(v_fh);
      END IF;
      -- This part outputs the DATA
      IF NOT v_samefile THEN
        v_fh := UTL_FILE.FOPEN(upper(p_dir),p_data_file,'w',32767);
      END IF;
      LOOP
        v_ret := DBMS_SQL.FETCH_ROWS(c);
        EXIT WHEN v_ret = 0;
        v_finaltxt := NULL;
        FOR j in 1..col_cnt
        LOOP
          CASE rec_tab(j).col_type
            WHEN 1 THEN DBMS_SQL.COLUMN_VALUE(c,j,v_v_val);
                        v_finaltxt := ltrim(v_finaltxt||',"'||v_v_val||'"',',');
            WHEN 2 THEN DBMS_SQL.COLUMN_VALUE(c,j,v_n_val);
                        v_finaltxt := ltrim(v_finaltxt||','||v_n_val,',');
            WHEN 12 THEN DBMS_SQL.COLUMN_VALUE(c,j,v_d_val);
                        v_finaltxt := ltrim(v_finaltxt||','||to_char(v_d_val,'DD/MM/YYYY HH24:MI:SS'),',');
          ELSE
            DBMS_SQL.COLUMN_VALUE(c,j,v_v_val);
            v_finaltxt := ltrim(v_finaltxt||',"'||v_v_val||'"',',');
          END CASE;
        END LOOP;
      --  DBMS_OUTPUT.PUT_LINE(v_finaltxt);
        UTL_FILE.PUT_LINE(v_fh, v_finaltxt);
      END LOOP;
      UTL_FILE.FCLOSE(v_fh);
      DBMS_SQL.CLOSE_CURSOR(c);
    END;
    This allows for the header row and the data to be written to seperate files if required.
    e.g.
    SQL> exec run_query('select * from emp','TEST_DIR','output.csv');
    PL/SQL procedure successfully completed.
    Output.csv file contains:
    empno,ename,job,mgr,hiredate,sal,comm,deptno
    7369,"SMITH","CLERK",7902,17/12/1980 00:00:00,800,,20
    7499,"ALLEN","SALESMAN",7698,20/02/1981 00:00:00,1600,300,30
    7521,"WARD","SALESMAN",7698,22/02/1981 00:00:00,1250,500,30
    7566,"JONES","MANAGER",7839,02/04/1981 00:00:00,2975,,20
    7654,"MARTIN","SALESMAN",7698,28/09/1981 00:00:00,1250,1400,30
    7698,"BLAKE","MANAGER",7839,01/05/1981 00:00:00,2850,,30
    7782,"CLARK","MANAGER",7839,09/06/1981 00:00:00,2450,,10
    7788,"SCOTT","ANALYST",7566,19/04/1987 00:00:00,3000,,20
    7839,"KING","PRESIDENT",,17/11/1981 00:00:00,5000,,10
    7844,"TURNER","SALESMAN",7698,08/09/1981 00:00:00,1500,0,30
    7876,"ADAMS","CLERK",7788,23/05/1987 00:00:00,1100,,20
    7900,"JAMES","CLERK",7698,03/12/1981 00:00:00,950,,30
    7902,"FORD","ANALYST",7566,03/12/1981 00:00:00,3000,,20
    7934,"MILLER","CLERK",7782,23/01/1982 00:00:00,1300,,10
    The procedure allows for the header and data to go to seperate files if required.  Just specifying the "header" filename will put the header and data in the one file.
    Adapt to output different datatypes and styles are required.

  • Data convertion while exporting data into flat files using export wizard in ssis

    Hi ,
    while exporting data to flat file through export wizard the source table is having NVARCHAR types.
    could you please help me on how to do the data convertion while using the export wizard?
    Thanks.

    Hi Avs sai,
    By default, the columns in the destination flat file will be non-Unicode columns, e.g. the data type of the columns will be DT_STR. If you want to keep the original DT_WSTR data type of the input column when outputting to the destination file, you can check
    the Unicode option on the “Choose a Destination” page of the SQL Server Import and Export Wizard. Then, on the “Configure Flat File Destination” page, you can click the Edit Mappings…“ button to check the data types. Please see the screenshot:
    Regards,
    Mike Yin
    TechNet Community Support

  • How to export waveform data into text file

    Hi..
        I am trying to export my waveform graph data into write spreadsheet file. When running the proram, I am getting graph values (values in a matrix) when checking with the probe. But once I save it to a text file, the values recorded are just zeros. I have attached the text file along with this. Could anyone please tell me why the graph data is not recorded in the spreadsheet? I have extracted the Y component of the graph and then wired it to the write to spreadsheet function. It seems like the labview is getting the data.. but now the problem is how to get the data out of labview?

    Please find the attched image of the whole program. I tried running the program after removing the array to matrix but still I am not able to export the graph values to spreadsheet. The program as a whole is working as I am able to display the oscilloscope graph into the waveform graph but I am not able to export the values. When I tried using probes, I am getting differnet matrix values till the end of the connection given to 'write to spreadsheet' but not able to export the values. The second image shows the write to spreadsheet file inside the while loop as i thought it will reduce the memory.. but it is still not working...
    Attachments:
    Scanner complete program.jpg ‏713 KB
    full scanner program 2.jpg ‏664 KB

  • Exporting table data into text files

    I got a request to export the data from about 85 tables into 85 text files. I assume that they will want a header row and some delimiter character. This is a process that must run every night by a sql job.
    Obviously I want it to be flexible. Tables could be addede and removed and columns could be added and removed. There will probably be a control table that has the list of tables to export.
    Looked at bcp - but seems that it is command line only?
    SSIS package?
    What other options are there?

    Wanted to post my solution. Ended up using bcp in a PowerShell Script. I was unable to use bcp in SQL because it requires xp_cmdshell and that is not allowed at many of our client sites. So wrote a Powershell script that executes bcp. The ps script
    loops through a table that contains a row for each table/view to export along with many values and switches for the table/view export: export path, include column headers, enclose each field in double quotes, double up embedded double quotes, how to format
    dates, what to return for NULL integers - basically the stuff that is not flexible in bcp. To get this flexibility I created a SQL proc that takes these values as input and creates a view. Then the PS bcp does a SELECT on the view. Many of my tables are
    very wide and bcp has a limit of 4000/8000. Some of my SELECT statements ended up being GT 35k in length. So using a view got around this size limitation.
    Anyway, the view creation and bcp download is really fast. It can download about 4 gb of data in 20 minutes. It can download it faster the 7z can zip it.
    Below is the SQL proc to format the SELECT statement to create the view for bcp (or some other utility like SQLCMD, Invoke-SQLCMD) or SQL query by "SELECT * from v_ExportData". the proc can be used from SQL or PS, or anything that can call a SQL
    Proc and then read a SQL view.
    IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ExportTablesCreateView]') AND type in (N'P', N'PC'))
    DROP PROCEDURE [dbo].[ExportTablesCreateView]
    GO
    CREATE PROCEDURE [dbo].[ExportTablesCreateView]
    ExportTablesCreateView
    Description:
    Read in a tablename or viewname with parameters and create a view v_ExportTable of the
    data. The view will typically be read by bcp to download SQL table data to flat files.
    bcp does not have the options to include column headers, include fields in double quotes,
    format dates or use '0' for integer NULLS. Also, bcp has a limit of varhar 4000 and
    wider tables could not be directly called by bcp. So create the v_ExportTable and have
    bcp SELECT v_ExportTable instead of the original table or view.
    Parameters:
    @pTableName VARCHAR(128) - table or view to create v_ExportTable from
    @pColumnHeader INT =1 - include column headers in the first row
    @pDoubleQuoteFields INT = 1 - put double quotes " around all column values including column headers
    @pDouble_EmbeddedDoubleQuotes INT = 1 - This is usually used with @pDoubleQuoteFields INT = 1. 'ab"c"d would be 'ab""c""d.
    @pNumNULLValue VARCHAR(1) = '0' - NULL number data types will export this value instead of bcp default of ''
    @pDateTimeFormat INT = 121 - DateTime data types will use this format value
    Example:
    EXEC ExportTablesCreateView 'custname', 1, 1, 1, '0', 121
    @pTableName VARCHAR(128),
    @pColumnHeader INT = 1,
    @pDoubleQuoteFields INT = 1,
    @pDouble_EmbeddedDoubleQuotes INT = 1,
    @pNumNULLValue VARCHAR(1) = '0',
    @pDateTimeFormat INT = 121
    AS
    BEGIN
    DECLARE @columnname varchar(128)
    DECLARE @columnsize int
    DECLARE @data_type varchar(128)
    DECLARE @HeaderRow nvarchar(max)
    DECLARE @ColumnSelect nvarchar(max)
    DECLARE @SQLSelect nvarchar(max)
    DECLARE @SQLCommand nvarchar(max)
    DECLARE @ReturnCode INT
    DECLARE @Note VARCHAR(500)
    DECLARE db_cursor CURSOR FOR
    SELECT COLUMN_NAME, ISNULL(Character_maximum_length,0), Data_type
    FROM [INFORMATION_SCHEMA].[COLUMNS]
    WHERE TABLE_NAME = @pTableName AND TABLE_SCHEMA='dbo'
    OPEN db_cursor
    FETCH NEXT FROM db_cursor INTO @ColumnName, @ColumnSize, @Data_type
    SET @HeaderRow = ''
    SET @ColumnSelect = ''
    -- Loop through each of the @pTableColumns to build the SELECT Statement
    WHILE @@FETCH_STATUS = 0
    BEGIN
    BEGIN TRY
    -- Put double quotes around each field - example "MARIA","SHARAPOVA"
    IF @pDoubleQuoteFields = 1
    BEGIN
    -- Include column headers in the first row - example "FirstName","LastName"
    IF @pColumnHeader = 1
    SET @HeaderRow = @HeaderRow + '''"' + @ColumnName + '"'' as ''' + @columnname + ''','
    -- Unsupported Export data type returns "" - example "",
    IF @Data_Type in ('image', 'varbinary', 'binary', 'timestamp', 'cursor', 'hierarchyid', 'sql_variant', 'xml', 'table', 'spatial Types')
    SET @ColumnSelect = @ColumnSelect + '''""'' as [' + @ColumnName + '],'
    -- Format DateTime data types according to input parameter
    ELSE IF @Data_Type in ('datetime', 'smalldatetime', 'datetime2', 'date', 'datetimeoffset')
    -- example - CASE when [aaa] IS NULL THEN '""' ELSE QUOTENAME(CONVERT(VARCHAR,[aaa], 121), CHAR(34)) END AS [aaa],
    SET @ColumnSelect = @ColumnSelect + 'CASE WHEN [' + @columnname + '] IS NULL THEN ''""'' ELSE QUOTENAME(CONVERT(VARCHAR,[' + @columnname + '],' + CONVERT(VARCHAR,@pDateTimeFormat) + '), CHAR(34)) END AS [' + @ColumnName + '],'
    -- SET Numeric data types with NULL value according to input parameter
    ELSE IF @Data_Type in ('bigint', 'numeric', 'bit', 'smallint', 'decimal', 'smallmoney', 'int', 'tinyint', 'money', 'float', 'real')
    -- example - CASE when [aaa] IS NULL THEN '"0"' ELSE QUOTENAME([aaa], CHAR(34)) END AS [aaa],
    SET @ColumnSelect = @ColumnSelect + 'CASE WHEN [' + @columnname + '] IS NULL THEN ''"' + @pNumNULLValue + '"'' ELSE QUOTENAME([' + @columnname + '], CHAR(34)) END AS [' + @ColumnName + '],'
    ELSE
    -- Double embedded double quotes - example "abc"d"ed" to "abc""d""ed". Only applicible for character data types.
    IF @pDouble_EmbeddedDoubleQuotes = 1
    BEGIN
    -- example - CASE when [aaa] IS NULL THEN '""' ELSE '"' + REPLACE([aaa],'"','""') + '"' END AS [aaa],
    SET @ColumnSelect = @ColumnSelect + 'CASE WHEN [' + @ColumnName + '] IS NULL THEN ''""'' ELSE ''"'' + REPLACE([' + @ColumnName + '],''"'',''""'') + ''"'' END AS [' + @ColumnName + '],'
    END
    -- DO NOT PUT Double embedded double quotes - example "abc"d"ed" unchanged to "abc"d"ed"
    ELSE
    BEGIN
    -- example - CASE when [aaa] IS NULL THEN '""' ELSE '"' + [aaa] + '"' END AS [aaa],
    SET @ColumnSelect = @ColumnSelect + 'CASE WHEN [' + @ColumnName + '] IS NULL THEN ''""'' ELSE ''"'' + [' + @ColumnName + '] + ''"'' END AS [' + @ColumnName + '],'
    END
    END
    -- DO NOT PUT double quotes around each field - example MARIA,SHARAPOVA
    ELSE
    BEGIN
    -- Include column headers in the first row - example "FirstName","LastName"
    IF @pColumnHeader = 1
    SET @HeaderRow = @HeaderRow + '''' + @ColumnName + ''' as ''' + @columnname + ''','
    -- Unsupported Export data type returns '' - example '',
    IF @Data_Type in ('image', 'varbinary', 'binary', 'timestamp', 'cursor', 'hierarchyid', 'sql_variant', 'xml', 'table', 'spatial Types')
    SET @ColumnSelect = @ColumnSelect + ''''' as [' + @ColumnName + '],'
    -- Format DateTime data types according to input parameter
    ELSE IF @Data_Type in ('datetime', 'smalldatetime', 'datetime2','date', 'datetimeoffset')
    -- example - CASE when [aaa] IS NULL THEN '''' ELSE CONVERT(VARCHAR,[aaa], 121) END AS [aaa],
    SET @ColumnSelect = @ColumnSelect + 'CASE WHEN [' + @columnname + '] IS NULL THEN '''' ELSE CONVERT(VARCHAR,[' + @columnname + '],' + CONVERT(VARCHAR,@pDateTimeFormat) + ') END AS [' + @ColumnName + '],'
    -- SET Numeric data types with NULL value according to input parameter
    ELSE IF @Data_Type in ('bigint', 'numeric', 'bit', 'smallint', 'decimal', 'smallmoney', 'int', 'tinyint', 'money', 'float', 'real')
    -- example - CASE when [aaa] IS NULL THEN '"0"' ELSE CONVERT(VARCHAR, [aaa]) END AS [aaa],
    SET @ColumnSelect = @ColumnSelect + 'CASE WHEN [' + @columnname + '] IS NULL THEN ''' + @pNumNULLValue + ''' ELSE CONVERT(VARCHAR,[' + @columnname + ']) END AS [' + @ColumnName + '],'
    ELSE
    BEGIN
    -- Double embedded double quotes - example "abc"d"ed" to "abc""d""ed". Only applicible for character data types.
    IF @pDouble_EmbeddedDoubleQuotes = 1
    -- example - CASE when [aaa] IS NULL THEN '' ELSE CONVERT(VARCHAR,REPLACE([aaa],'"','""')) END AS [aaa],
    SET @ColumnSelect = @ColumnSelect + 'CASE WHEN [' + @columnname + '] IS NULL THEN '''' ELSE CONVERT(VARCHAR,REPLACE([' + @columnname + '],''"'',''""'')) END AS [' + @ColumnName + '],'
    ELSE
    -- example - CASE when [aaa] IS NULL THEN '' ELSE CONVERT(VARCHAR,[aaa]) END AS [aaa],
    SET @ColumnSelect = @ColumnSelect + 'CASE WHEN [' + @columnname + '] IS NULL THEN '''' ELSE CONVERT(VARCHAR,[' + @columnname + ']) END AS [' + @ColumnName + '],'
    END
    END
    FETCH NEXT FROM db_cursor INTO @ColumnName, @ColumnSize, @Data_Type
    END TRY
    BEGIN CATCH
    RETURN (1)
    END CATCH
    END
    CLOSE db_cursor
    DEALLOCATE db_cursor
    BEGIN TRY
    -- remove last comma
    IF @pColumnHeader = 1
    SET @HeaderRow = SUBSTRING(@HeaderRow , 1, LEN(@HeaderRow ) - 1)
    SET @ColumnSelect = SUBSTRING(@ColumnSelect, 1, LEN(@ColumnSelect) - 1)
    -- Put on the finishing touches on the SELECT
    IF @pColumnHeader = 1
    SET @SQLSelect = 'SELECT ' + @HeaderRow + ' UNION ALL ' +
    'SELECT ' + @ColumnSelect + ' FROM [' + @pTableName + ']'
    ELSE
    SET @SQLSelect = 'SELECT ' + @ColumnSelect + ' FROM [' + @pTableName + ']'
    ---- diagnostics
    ---- PRINT truncates at 4k or 8k, not sure, my tables have many colummns
    --PRINT @SQLSelect
    --DECLARE @END varchar(max) = RIGHT(@SQLSelect, 3000)
    --PRINT @end
    --EXECUTE sp_executesql @SQLSelect
    -- drop view if exists -- using view because some tables are very wide. one of my tables had a 33k select statement
    SET @SQLCommand = '
    IF EXISTS (SELECT * FROM SYS.views WHERE name = ''v_ExportTable'')
    BEGIN
    DROP VIEW v_ExportTable
    END'
    EXECUTE @ReturnCode = sp_executesql @SQLCommand
    IF @returncode = 1
    BEGIN
    RETURN (1)
    END
    -- create the view
    SET @SQLCommand = '
    CREATE VIEW v_ExportTable AS ' + @SQLSelect
    -- diagnostics
    --print @sqlcommand
    EXECUTE @ReturnCode = sp_executesql @SQLCommand
    IF @returncode = 1
    BEGIN
    RETURN (1)
    END
    END TRY
    BEGIN CATCH
    RETURN (1)
    END CATCH
    RETURN (0)
    END -- CREATE PROCEDURE [dbo].[ExportTablesCreateView]
    GO

  • Exporting data from text file to a table using utl_file

    Dear all,
    I have a text file as below and i have a table having 12 columns. Now i need to insert this text file into the table story_books.
    CREATE TABLE story_books
    book_id NUMBER,
    Category VARCHAR2(100 BYTE),
    Book_type VARCHAR2(100 BYTE),
    Name VARCHAR2(700 BYTE),
    Location VARCHAR2(700 BYTE),
    Ownership_code VARCHAR2(700 BYTE),
    Author VARCHAR2(700 BYTE),
    Less_Sel_fact VARCHAR2(700 BYTE),
    Reason VARCHAR2(700 BYTE),
    Buying VARCHAR2(700 BYTE),
    Suspected Book VARCHAR2(700 BYTE),
    Conditions VARCHAR2(700 BYTE)
    -------------------------text file---------------
    Books Out Table: Books
    Book. Type          Name          Location               Ownership Code
    Story               SL          hyd               SS-HYD
    Known Author:     Unknown               
    Less Selling Factors: Thunderstorms     
    Reason:     Unknown               
    Buying (if applicable):
    Not Applicable
    Suspected Book:
    Unknown
    Conditions to increace sales:
    Advertisement in all areas
    i was able to read the data and storing if it is in the same line.But i dont know how to read below data
    Book. Type          Name          Location               Ownership Code
    Story               SL          hyd               SS-HYD
    In this data i have to search for 'Book. type' and then i need to save the word 'Story' to the column 'Book_type'
    Then i need to search for 'Name' and i need to save 'SL' into the column into 'Name'
    Then i need to search for 'Location' and i need to save 'hyd' into the column into 'Location'
    I was able to extract the data if it is in below format using utl_file.get_line
    Known Author:     Unknown               
    Less Selling Factors: Thunderstorms     
    Reason:     Unknown     
    Any one can explain me how to solve the above criteria.
    Thanks in advance.

    Dear all,
    I have a text file as below and i have a table having 12 columns. Now i need to insert this text file into the table story_books.
    CREATE TABLE story_books
    book_id NUMBER,
    Category VARCHAR2(100 BYTE),
    Book_type VARCHAR2(100 BYTE),
    Name VARCHAR2(700 BYTE),
    Location VARCHAR2(700 BYTE),
    Ownership_code VARCHAR2(700 BYTE),
    Author VARCHAR2(700 BYTE),
    Less_Sel_fact VARCHAR2(700 BYTE),
    Reason VARCHAR2(700 BYTE),
    Buying VARCHAR2(700 BYTE),
    Suspected Book VARCHAR2(700 BYTE),
    Conditions VARCHAR2(700 BYTE)
    -------------------------text file---------------
    Books Out Table: Books
    Book. Type          Name          Location               Ownership Code
    Story               SL          hyd               SS-HYD
    Known Author:     Unknown               
    Less Selling Factors: Thunderstorms     
    Reason:     Unknown               
    Buying (if applicable):
    Not Applicable
    Suspected Book:
    Unknown
    Conditions to increace sales:
    Advertisement in all areas
    i was able to read the data and storing if it is in the same line.But i dont know how to read below data
    Book. Type          Name          Location               Ownership Code
    Story               SL          hyd               SS-HYD
    In this data i have to search for 'Book. type' and then i need to save the word 'Story' to the column 'Book_type'
    Then i need to search for 'Name' and i need to save 'SL' into the column into 'Name'
    Then i need to search for 'Location' and i need to save 'hyd' into the column into 'Location'
    I was able to extract the data if it is in below format using utl_file.get_line
    Known Author:     Unknown               
    Less Selling Factors: Thunderstorms     
    Reason:     Unknown     
    Any one can explain me how to solve the above criteria.
    Thanks in advance.

  • Extra space adding during spool data into text file

    I'm using sql developer to query oracle tables. I can export data using GUI of sql developer, but I wish to use spool query to export the data. Using below query, I was able to export the data to specified location, but my final text file consist of additional spaces after each line. These additional spaces between each line is causing an error to upload the text file in different location.
    Did any one face have this issue? Below is my query
    set head off
    SET FEEDBACK OFF
    SET ECHO    OFF
    SET TRIMSPOOL ON
    SET TRIMOUT ON
    spool c:\test.txt
    select cast(memberid||',12'as varchar2(20))
    from abc;
    spool off
    set head on
    set ECHO on
    i'm using trimspool, and trimout, but it is not removing any blank spaces.

    Sorry, I changed my export.sql to the query you provided.
    SET HEAD OFF FEED OFF ECHO OFF
    SET LIN 120 PAGES 0 TRIMS ON
    SPOOL c:\test.txt
    SELECT memberid || ',12' FROM abc;
    SPOOL OFF
    But,the spool query is still adding additional spaces making length of each line 43 characters in final text file output.

  • SSIS - Exporting Data into flat files from Oracle Table as batchwise process

    Hi All,
    Thanks in advance.
    I have a Large Table in Oracle Database with some 3 Lakhs record. I need to fetch the 10,000 records for every iteration and export it into the flat file. This process should occur recursively until the table becomes empty.
    Hence, For every iteration on flat file to be generated with 10,000 records.
    Please help how to proceed further in SSIS.
    Thanks
    Pyarajan.S

    Yes, it always helps if your question doesn't specify the actual requirements...
    Use the FOR loop container to control the iterations of the data flow. For each run you read 10,000 rows from the table and dump them in a flat file. Either move the flat file, or use an expression on the flat file connection manager to give them dynamic
    file names.
    30 million rows is also not a problem by the way, it just takes a bit longer.
    MCSE SQL Server 2012 - Please mark posts as answered where appropriate.

  • Issue when exporting data to text file in BI Publisher 10.1.3.4

    We are trying to export over 900,000 records to a text file from BI Publisher. The reports keep on running while scheduling. But if we reduce the record limit to 200,000 it works fine. Please help us to resolve this issue. Its really urgent.

    How are you doing it? With a template? Need more info to be able to help
    Tim

  • Problem with data saving into text file

    Hi,
    The problem I am facing wihile saving the data into text file is that everytime when I am slecting the path from front panel, the data which is being saved is appended with the previous data, i.e. not only in the new text file, the new set of data is saved but also, if there is any previuos run for the program, the corresponding data is also present in that text file.
    However, when I change the same 'control'(file path) to 'constant' in the block diagram, and add the file path, there is no such problem. Basically, changing the "File path" from constant in the block diagram to control (so that it is displayed in the front panel) is causing the problem.
    Please help!
    Thanks 
    Solved!
    Go to Solution.
    Attachments:
    front panel.JPG ‏222 KB
    Block Diagram.JPG ‏70 KB
    Block diagram with File Path as Constant.JPG ‏74 KB

    Your shift register on the For loop is not initialized. It will retain the value of the string from the last time it executed. Initialize that and it should solve your problem.
    Mark Yedinak
    "Does anyone know where the love of God goes when the waves turn the minutes to hours?"
    Wreck of the Edmund Fitzgerald - Gordon Lightfoot

  • Loading data from text file into ListBox

    I have data in a text file that I want to load into a
    listbox... I have fully mastered handling strings and arrays so I'm
    going to need some help...
    I was wondering how do I get flash to load a text file that
    contains the data below.. and display it line for line like I want
    it to list down the component
    "Launch;7.1.7.6"
    "Engine;7.1.7.6"
    "OSX;7.0.0.2" (or something close to that)
    and I was wondering how do i just get it to take it fromt he
    file.. line for line from where it says exeversion in the file and
    list it in the listbox...
    I'm really thankful to anybody that helps.
    Data in text file:
    quote:
    exeversion=Launch;7.1.7.6;
    exeversion=Engine;7.1.7.6;
    exeversion=LinuxX86;7.0.0.2;
    exeversion=LinuxPPC;7.0.0.2;
    exeversion=LinuxMIPS;7.0.0.2;
    exeversion=OSX;7.0.0.2;
    exeversion=Config;7.1.7.6;
    exeversion=UI;7.1.7.7;
    exeversion=JAVA;7.0.4.5;

    nobody cna help me? i really need to know or have a tutorial
    or something so i can learn from it... i really appreciate anyone
    who helps

  • Cant get data from text file to print into Jtable

    Instead of doing JDBC i am using text file as database. I cant get data from text file to print into JTable when i click find button. Goal is to find a record and print that record only, but for now i am trying to print all the records. Once i get that i will change my code to search desired record and print it. when i click the find button nothing happens. Can you please take a look at my code, dbTest() method. thanks.
    void dbTest() {
    DataInputStream dis = null;
    String dbRecord = null;
    String hold;
    try {
    File f = new File("customer.txt");
    FileInputStream fis = new FileInputStream(f);
    BufferedInputStream bis = new BufferedInputStream(fis);
    dis = new DataInputStream(bis);
    Vector dataVector = new Vector();
    Vector headVector = new Vector(2);
    Vector row = new Vector();
    // read the record of the text database
    while ( (dbRecord = dis.readLine()) != null) {
    StringTokenizer st = new StringTokenizer(dbRecord, ",");
    while (st.hasMoreTokens()) {
    row.addElement(st.nextToken());
    System.out.println("Inside nested loop: " + row);
    System.out.println("inside loop: " + row);
    dataVector.addElement(row);
    System.out.println("outside loop: " + row);
    headVector.addElement("Title");
    headVector.addElement("Type");
    dataTable = new JTable(dataVector, headVector);
    dataTableScrollPane.setViewportView(dataTable);
    } catch (IOException e) {
    // catch io errors from FileInputStream or readLine()
    System.out.println("Uh oh, got an IOException error!" + e.getMessage());
    } finally {
    // if the file opened okay, make sure we close it
    if (dis != null) {
    try {
    dis.close();
    } catch (IOException ioe) {
    } // end if
    } // end finally
    } // end dbTest

    Here's a thread that loads a text file into a JTable:
    http://forum.java.sun.com/thread.jsp?forum=57&thread=315172
    And my reply in this thread shows how you can use a text file as a simple database:
    http://forum.java.sun.com/thread.jsp?forum=31&thread=342380

  • Why we need to conver Context  Node data into XML file----Export to Excel

    Hi All,
    Let me clarify my dought........today i have gone through the concept of  "Exporting Context Data Using the Webdynpro Binary cache" in SAP Online Help.
    From the SAP Online Help pdf document, i have found that, the context node data has been converted first in to XML file,after that file had been stored in the web dynpor binary cache...bla....bla.........
    Here my qtn is why they had converted context node data into XML file. With out doing that can not we export context node data to excel file..?
    Regards
    Seshu
    Edited by: Sesshanna D on Dec 19, 2007 7:25 AM

    Hi Sesshanna,
    it is not neccessary to do that but xml has the advantage, that it can be easily transformed into every output format that might occur in later project stages.
    If it's simply about blowing out some Excel, I suggest using an OSS library such as jexcelAPI or Jakarta POI and building the Excel how you need it.
    regards,
    Christian

Maybe you are looking for

  • Assigning interface to interface

    Hi All, I have a question in interface. It may be a silly doubt, but I am not sure what I am missing out. I have 2 interfaces I1 and I2, totally unrelated. I create variables for these 2 interfaces i1 and i2 respectively. Can I do like this? i1 = (I1

  • Conditional display in Reports

    Hi, Does anyone know of a way to make a icon used to implement a link to another page appear for some rows of a report but not others? The condition for display could be based on the value of one of the columns in the report. Niall

  • Synching iPod with Adobe Photo Elements 4

    I've been syncing my 60GB iPod with my PC via Adobe Photoshop Album Starter Edition 3.0 since September and it has worked fine. I recently upgraded to Photoshop Elements 4.0, uninstalling Album in the process. iTunes no longer shows Album as a synchr

  • Jurassic Park app progress lost, how do I get it back?

    How do I get back progress done in a game app?  Jurassic Park and Dragonvale have defaulted back to brand new game.

  • Sql query o/p into text file using 11g

    i am using 11g. i want to write the result of the query into text file.how to do it