Export table data in text file
hi,
i am using oracle 8.0.7 , i want to export a table data in to text file, thanks in advance
Noman ul haq
2 options:
1) Spool the query results into a file using SQL*PLUS
2) If you can use the Oracle Server, look at the UTL_FILE package. This writes files, but ONLY to the Oracle server. It will NOT write out to your client machine. Your DBA will need to add an entry to allow for the UTL_FILE package to write out to the directory you choose.
Hope that helps - the documentation should have detailed usage of UTL_FILE package. Or search on this site b/c this is a common question - see it at least 3 times a week.
Similar Messages
-
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 -
How to export bulk data in text file
Dear,
We have an requirement to get data from GL CONTAINING below tables, but it's taking lot of time, could you share the best way to get data in text file as quick as possiable.
from gl_je_headers_v,gl_je_lines,GL_JE_CATEGORIES
,gl_code_combinations_v
where gl_je_headers_v.je_header_id = gl_je_lines.je_header_id
AND GL_JE_CATEGORIES.je_category_name = gl_je_headers_v.je_category
and gl_code_combinations_v.CODE_COMBINATION_ID =
gl_je_lines.code_combination_id
and gl_code_combinations_v.CHART_OF_ACCOUNTS_ID = 50349
AND gl_je_headers_v.PERIOD_NAME = 'SEP-2012'it's based on formatting data in text file
you can use utl_file but it's row by row process your data
you can try spool
as example
spool c:\tmp\myfile.txt
select *
from emp;
spool off;or try export for example in sql developer -
Hi,
I have to dump the BKPF table data(some selected columns) into a txt file. It has around 30 lakh records.
I am planning to select the data from se16 for different date ranges and export into different txt files.
Is there any way that i can dump the whole data into a txt file for some selected columns.
Thanks,Hi,
goto se16> select the records as per requirement> goto change layout> select the number of column you required> click on the export option> select radio button unconverted> save the file in txt format.
you will get only select columns in the text file. -
Exporting historical data to text file with MAX misses columns of data?
I am using Labview 7.1 with DSC module 7.1 and wants to export data to either excel format or .txt.
I have tried this with the historical data export in MAX, and also programmatically with the "write traces to spreadsheet file.vi" available in the DSC module. All my tags in my tag engine file (*.scf) are defined to log data and events. Both the update tag engine deadband and the update database are set to 0 %.
My exported excel or text file seems reasonalbe except that some columns of data are missing. I dont understand
why data from these tags are not in the exported files since they have the same setup in the (.scf) as other tags which are okay exported?
All defined tags can be seen using the NI hypertrend or MAX. Also the ones that are not correctly exported to file.
Appreciate comments on this.
Best regards,
Ingvald BardsenI am using LV and DSC 7.1 with PCI-6251 and max 4.2. In fact, just one column of values does not make sense. In attachment, follows the excel exported file. The last of column called ...V-002 that is the problem. I put probes for checking values but them shows correct. When the file is exported that to show values wrong.
The problem of missing values in column i solved putting 0% in field of deadband.
thank you for your help
Attachments:
qui, 2 de ago de 2007 - 132736.xls 21 KB -
Exporting table data to .csv file
How to export the table data (this table is having 18 million records) to .csv file. using SQL Developer and PL/SQL deveoloper it is taking too long time to complete. Please let me know is there any faster way to complete this task.
Thanks in advanceAlso bear in mind that SQL Developer and PL/SQL Developer are running on your local client, so it's transferring all 18 million rows to the client before formatting and putting them out to a file. If you had some PL/SQL code to export it on the database server it would run a lot faster as you wouldn't have the network traffic delay to deal with, although your file would then reside on the server rather than the client (which isn't necessarily a bad thing as a lot of companies would be concerned about the security of their data especially if it ends up being stored on local machines rather than on a secure server).
As already asked, why on earth do you need to store 18 million rows in a CSV file? The database is the best place to keep the data. -
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 -
Hi all,
I have a .jspx page wich contains a table and a button with an exportCollectionActionListener to export the table data to an excell file.
Now i want to do the same but to a pdf file.
Is that posible, and if so how can I do that?
If it isn't posible is there any way to do that.
Thanks all,
RowanHi!
Yes, the first step is to learn iReport. Then, investigate Jasper Forums where you will find lot of code and hints.
To produce a report you have to:
1. Create report definition and compile it in report files used by Jasper API later on (this you learn on Jasper forums)
2. Create java code in your project to generate report (based on datasource in your app) - this is just java code which doesnt have anything special to ADF/JDev - learn this also on Jasper forums
3. Decide which mechanism you will use to downstream report output (whichever render you select when generate report - PDF, HTML, Excle, RTF...) - there are two options:
a. Use standard JSP Servlet, where you just have to generate report and downstream it into servlet's output stream
b. more ADF 11g way - using af:fileDownloadActionListener with backingbean to downstream a generated report content
That's it. You have to design your own strategy for supplying report query parameters (through Http Request params or any other way dependent on mechanism you decide to use).
Try Googling for Jdeveloper Jasper and you will find several blogs/forums on this topic (try JDeveloper and Jasper.. HTML Report without information The servlet technique is same as in 10g and for ADF 11g way you have to manage yourself.
Regards,
PaKo -
How to give path in plsql while exporting table data into .csv file
hi,
i have a code like this
PROCEDURE dump_table_to_csv (
p_tname IN VARCHAR2,
p_dir IN VARCHAR2,
p_filename IN VARCHAR2
IS
l_output UTL_FILE.file_type;
l_thecursor INTEGER DEFAULT DBMS_SQL.open_cursor;
l_columnvalue VARCHAR2 (4000);
l_status INTEGER;
l_query VARCHAR2 (1000) DEFAULT 'select * from ' || p_tname;
l_colcnt NUMBER := 0;
l_separator VARCHAR2 (1);
l_desctbl DBMS_SQL.desc_tab;
BEGIN
l_output := UTL_FILE.fopen (p_dir, p_filename, 'w');
EXECUTE IMMEDIATE 'alter session set nls_date_format=''dd-mon-yyyy hh24:mi:ss''';
DBMS_SQL.parse (l_thecursor, l_query, DBMS_SQL.native);
DBMS_SQL.describe_columns (l_thecursor, l_colcnt, l_desctbl);
FOR i IN 1 .. l_colcnt
LOOP
UTL_FILE.put (l_output,
l_separator || '"' || l_desctbl (i).col_name || '"'
DBMS_SQL.define_column (l_thecursor, i, l_columnvalue, 4000);
l_separator := ',';
END LOOP;
UTL_FILE.new_line (l_output);
l_status := DBMS_SQL.EXECUTE (l_thecursor);
WHILE (DBMS_SQL.fetch_rows (l_thecursor) > 0)
LOOP
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 := ',';
END LOOP;
UTL_FILE.new_line (l_output);
END LOOP;
DBMS_SQL.close_cursor (l_thecursor);
UTL_FILE.fclose (l_output);
EXECUTE IMMEDIATE 'alter session set nls_date_format=''dd-MON-yy'' ';
EXCEPTION
WHEN OTHERS
THEN
EXECUTE IMMEDIATE 'alter session set nls_date_format=''dd-MON-yy'' ';
RAISE;
END;
I am getting error like :-------
SQL> exec dump_table_to_csv('deptair','c:/csv','aa.deptair');
BEGIN dump_table_to_csv('deptair','c:/csv','aa.deptair'); END;
ERROR at line 1:
ORA-00604: error occurred at recursive SQL level 1
ORA-06502: PL/SQL: numeric or value error: character string buffer too small
ORA-06512: at line 8
ORA-29280: invalid directory path
ORA-06512: at "SCOTT.DUMP_TABLE_TO_CSV", line 58
ORA-06512: at line 1
pplease help me out
thanks
vickylook at your other thread, answer is already there.
-
How can we export table data to a CSV file??
Hi,
I have the following requirement. Initially business agreed upon, exporting the table data to Excel file. But now, they would like to export the table data to a CSV file, which is not being supported by af:exportCollectionActionListener component.
Because, when i opened the exported CSV file, i can see the exported data sorrounded with HTML tags. Hence the issue.
Does someone has any solution for this ... Like, how can we export the table data to csv format. And it should work similar to exporting the data to excel sheet.
For youre reference here is the code which i have used to export the table data..
><f:facet name="menus">
><af:menu text="Menu" id="m1">
><af:commandMenuItem text="Print" id="cmi1">
><af:exportCollectionActionListener exportedId="t1"
>title="CommunicationDistributionList"
>filename="CommunicationDistributionList"
>type="excelHTML"/> ---- I tried with removing value for this attribute. With no value, it did not worked at all.
></af:commandMenuItem>
></af:menu>
></f:facet>
Thanks & Regards,
Kiran KonjetiHi Alex,
I have already visited that POST and it works only in 10g. Not in 11g.
I got the solution for this. The solution is :
Use the following code in jsff
==================
<af:commandButton text="Export Data" id="ctb1">><af:fileDownloadActionListener contentType="text/csv; charset=utf-8"
>filename="test.csv"
>method="#{pageFlowScope.pageFlowScopeDemoAppMB.test}"/>
></af:commandButton>
OR
<af:commandButton text="Export Data" id="ctb1">><af:fileDownloadActionListener contentType="application/vnd.ms-excel; charset=utf-8"
>filename="test.csv"
>method="#{pageFlowScope.pageFlowScopeDemoAppMB.test}"/>
></af:commandButton>
And place this code in ManagedBean
======================
> public void test(FacesContext facesContext, OutputStream outputStream) throws IOException {
> DCBindingContainer dcBindings = (DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
>DCIteratorBinding itrBinding = (DCIteratorBinding)dcBindings.get("fetchDataIterator");
>tableRows = itrBinding.getAllRowsInRange();
preparaing column headers
>PrintWriter out = new PrintWriter(outputStream);
>out.print(" ID");
>out.print(",");
>out.print("Name");
>out.print(",");
>out.print("Designation");
>out.print(",");
>out.print("Salary");
>out.println();
preparing column data
> for(Row row : tableRows){
>DCDataRow dataRow = (DCDataRow)row;
> DataLoaderDTO dto = (DataLoaderDTO)dataRow.getDataProvider();
>out.print(dto.getId());
>out.print(",");
>out.print(dto.getName());
>out.print(",");
>out.print(dto.getDesgntn());
>out.print(",");
>out.print(dto.getSalary());
>out.println();
>}
>out.flush();
>out.close();
> }
And do the following settings(*OPTIONAL*) for your browser - Only in case, if the file is being blocked by IE
==================================================================
http://ais-ss.usc.edu/helpdoc/main/browser/bris004b.html
This resolves implementation of exporting table data to CSV file in 11g.
Thanks & Regards,
Kiran Konjeti -
Table data in FLAT file - Please help me
Hi,
Please have look.
In my database 7 - users, Each user with nearly 1500 tables.
My client wants the data in each table to be availbale in a text file in a human
readable format like.
eg: DEPT table
Deptno,Dname,Location (This line is optional)
10,FIN,LA
20,ACCOUNTING,NW
Please help me to solve this.
Can you suggest any easy way?
regards
MathewCan you suggest any easy way?What about the answers given in your previous post:
Tables data into text file
Use Oracle's SQL Developer. Bring up the table in a
grid and export it to a .csv file. Then the human
can open it in Excel.If the OP's numbers are correct (7 users, each with 1500 tables) this does not sound like an easy way to export 10500 tables...
Message was edited by:
thomas.kellerer -
Sql/Plsql code to export data into a temporary table from a text file
Dear all,
I need to create a temporary table getting data from a text file. I am very new to data loading could you please help me how to read the text file in to a temporary table.
i have text file like as below:
order items : books Purchasing
start date:
8-11-09
Notes: Books are selling from aug10 to aug 25
Action performed
Time
Verified By
sold out from shop, sold out date:_________
1.
physics _______ book sold to ravi
2.
social _______ book this is a good book
sold to kiran
aug10th
ronald
3.
maths book to sal
4.
english book__________ this was a newbook
to raj
jak
return to shop, return date:____________
1.
maths book return by:_____________ Verify book
aug11th
john
2.
story book by:_________ checked
aug14th
Now i need to create a temporary table and insert the data into the table from this text file.
Now i need to create a temporary table named as books_order with 5columns(order,Status,Action_Performed,Time,Verified_By) like as below:
Order status Action_Performed Time Verified_By
books Purchasing sold physics _______ book sold to ravi _______ _________
books Purchasing sold social _______ book this is a good book sold to kiran aug10th ronald
books Purchasing sold maths book to sal _____ __________
books Purchasing sold english book__________ this was a newbook to raj __________ jak
books Purchasing return maths book return by:_____________ Verify book aug11th john
books Purchasing return story book by:_________ checked aug14th _________
Thanks in advance.Isn't school work marvelous?
Create an external table.
http://www.morganslibrary.org/reference/externaltab.html
Getting the data into a temporary table may make sense in SQL Server ... but not in Oracle. -
Exporting table data to a flat file
Hi, I am trying to export data from a table to a text file using this:
CREATE TABLE bufurl
url, sno
ORGANIZATION EXTERNAL
TYPE oracle_datadump
DEFAULT DIRECTORY dataload
LOCATION ('external.txt')
AS
SELECT url, sno from table1 where sno > 10
but i get this error:
ERROR at line 1:
ORA-29829: implementation type does not exist
any clues what might be going on here?user652125 wrote:
Hi, I am trying to export data from a table to a text file using this:
CREATE TABLE bufurl
url, sno
ORGANIZATION EXTERNAL
TYPE oracle_datadump
DEFAULT DIRECTORY dataload
LOCATION ('external.txt')
AS
SELECT url, sno from table1 where sno > 10
but i get this error:
ERROR at line 1:
ORA-29829: implementation type does not exist
any clues what might be going on here?Well it should work if you are using 10g or above...
SQL> ed
Wrote file afiedt.buf
1 CREATE TABLE ext_emps
2 ORGANIZATION EXTERNAL
3 (TYPE oracle_datapump
4 DEFAULT DIRECTORY TEST_DIR
5 LOCATION ('emps.txt'))
6 AS
7 SELECT empno, ename
8* from emp
SQL> /
Table created.
SQL>What version of SQL*Plus are you running? -
How to extract data from text file to database table
Hi ,
I am trying to upload data in text file to database table using GUI_UPLOAD function .what would be the program for that.
thanks in advance.Hi,
I don't think you have a standard sap program to upload data from file to database table...
Instead you can create a custom program like this..
DATA: T_FILEDATA(1000) OCCURS 0 WITH HEADER LINE.
DATA: T_ZTABLE LIKE ZTABLE OCCURS 0 WITH HEADER LINE.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = 'C:\TEST.TXT'
tables
data_tab = T_FILEDATA
EXCEPTIONS
FILE_OPEN_ERROR = 1
FILE_READ_ERROR = 2
NO_BATCH = 3
GUI_REFUSE_FILETRANSFER = 4
INVALID_TYPE = 5
NO_AUTHORITY = 6
UNKNOWN_ERROR = 7
BAD_DATA_FORMAT = 8
HEADER_NOT_ALLOWED = 9
SEPARATOR_NOT_ALLOWED = 10
HEADER_TOO_LONG = 11
UNKNOWN_DP_ERROR = 12
ACCESS_DENIED = 13
DP_OUT_OF_MEMORY = 14
DISK_FULL = 15
DP_TIMEOUT = 16
OTHERS = 17
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
LOOP AT T_FILEDATA.
T_ZTABLE = T_FILEDATA.
APPEND T_ZTABLE.
ENDLOOP.
MODIFY ZTABLE FROM TABLE T_ZTABLE.
COMMIT WORK..
Thanks,
Naren -
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:
ben512Well 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>
Maybe you are looking for
-
[Solved] Kernel 3.2 wont re-patch vmware for new kernel build
Hi, I looked for the same thing and didnt find it, I had vmplayer running great -> enter new kernel 3.2. When it went to build the new modules because the kernel changed it failed with log of: 2012-01-19T06:10:49.389-06:00| vthread-3| I120: Log for
-
Images with news items appearing as blanks
I am using BT Yahoo - Mozilla Firefox with Windows XP professional and Service Pack 2. There is a news section on the home page but any news item accompanied with still images (e.g Chinese New Year Celebrations on Jan 22)the images are blanked out. I
-
Since installing SL, I can't add a new entry to my ICal. It says "New Entry", but I can't change the name of the entry. This only happens on my MacBook Pro, but it works fine on my IMac. Anyone else have a MacBook Pro with the same issue?
-
Authorization Object=S_RFC values for Integarted Planing
Hello all, Does any one know specific values(Function Group Names) just to authorize and enable users to open IP-Workbooks on BEx. Authorization Object: S_RFC- Authorization Check for RFC access.. When I give full "*" authorization everyting is work
-
Since I got my iMac 3 years ago, I've had the issue of it constantly logging me out mid-email or post, of gmail, facebook, and everything else. Sometimes it lets me stay logged in for 30 minutes, others I will be logged out every 30 seconds, ten time