Exporting table data to a CSV file
hello everyone,
i need help on exporting table data to a CSV file.
I have a div element containing the table which displays some data.
there is a "Export" button just above the table, which if clicked, will export the current data in the table to a .csv file.
can this be done in jsp? or i need to use servlet?
also how can i submit the table data only? (as my webpage contiain other data also)
can anyone provide with some sort of sample code?
thanks in advance!!
oops!!
i just forgot..
when the user will click on the export button, i want to greet him with a "Save As"
popup, so that he can specify the filename and location to save the file.
thanks!!
Similar Messages
-
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 -
Export table data in a flat file without using FL
Hi,
I am looking for options where I can export table data into a flat file without using FL(File Layout) i.e., by using App Engine only.
Please share your experience if you did anything as this
ThanksA simple way to export any record (table/view) to an csv fiel, is to create a rowset and loop through all record fields, like below example code
Local Rowset &RS;
Local Record &Rec;
Local File &MYFILE;
Local string &FileName, &strRecName, &Line, &Seperator, &Value;
Local number &numRow, &numField;
&FileName = "c:\temp\test.csv";
&strRecName = "PSOPRDEFN";
&Seperator = ";";
&RS = CreateRowset(@("Record." | &strRecName));
&RS.Fill();
&MYFILE = GetFile(&FileName, "W", %FilePath_Absolute);
If &MYFILE.IsOpen Then
For &numRow = 1 To &RS.ActiveRowCount
&Rec = &RS(&numRow).GetRecord(@("RECORD." | &strRecName));
For &numField = 1 To &Rec.FieldCount
&Value = String(&Rec.GetField(&numField).Value);
If &numField = 1 Then
&Line = &Value;
Else
&Line = &Line | &Seperator | &Value;
End-If;
End-For;
&MYFILE.WriteLine(&Line);
End-For;
End-If;
&MYFILE.Close(); You can of course create an application class for generic calling this piece of code.
Hope it helps.
Note:
Do not come complaining to me on performance issues ;) -
Exporting Table data to delimited txt file
I am trying to import the table data into delimited text file, I am running the following code from Tom Kyte's website on the server. When I run the procedure after I run the function it is not creating any .dat file for me.
I have also checked for the parameter 'utl_file_dir' in the database and it is set to the correct path. Is there anything that I am missing??
any suggestions/inputs would help.
create or replace function 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;
create or replace procedure test_dump_csv
as
l_rows number;
begin
l_rows := dump_csv( 'select *
from doctype
where rownum < 25',
',', '/tmp', 'test.dat' );
end;
/Hi,
It works for me...
SQL> select dump_csv('select * from dba_users',',','/tmp','teste.txt') from dual;
DUMP_CSV('SELECT*FROMDBA_USERS',',','/TMP','TESTE.TXT')
149
SQL> show parameter utl_file_dir
NAME TYPE VALUE
utl_file_dir string /tmp
oracle@icaro:/tmp> ls -l teste.txt
-rw-r--r-- 1 rps users 394353 2006-07-31 17:40 teste.txtJust for information:
I'm using SUSE LINUX 10 and Oracle 10g 10.1.0.2
Cheers
Message was edited by:
Legatti -
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? -
The exported columns name are still ordered as the table definition and the data are ordered as the table is diplayed in the explorer. If you change the order of the columns in the explorer and export the data in a csv file by example, the data are putted in a wrong column due to the labeling mismatch.
Table
+column a
+column b
Table data in the explorer
+column b
+column a
Data exported in the csv file
+Title column a
+data column b
+Title column b
+data column aSure enough - just tested this with Export > Insert and the column headings are in the displayed order but the data is in the db order. I will log a bug now.
-- Sharon -
Data Migration from CSV file to Database Table.
Hi,
I have checked few answered threads on Data Migration Issues but didn't find the solution yet.
I am reading data from an CSV file to internal table but the complete row is coming under one field of the internal table.
How i can get values in different fields of the internal table from the CSV file ?
Thanks & Regards.
Raman Khurana.Hi,
If you are using GUI_UPLOAD, you might have missed to make has_field_separator as 'X'.
EXPORTING
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = 'C:\File.csv'
filetype = 'ASC'
has_field_separator = ' X' "<= Set this as 'X'.
TABLES
data_tab = itab.
Regards,
Manoj Kumar P -
Exporting table data to a Comma Separated file / .dat file?
Hi All,
I want to export the table data to a .CSV or .DAT file. This data is an input to other software to read and load like "Informatica".
I tried spooling the file by providing the extension as .CSV but that did'nt work!
Could you please let me know how can I get the data of a table into a .CSV or .DAT file?
I am trying to get it via SQL Prompt.
Thanks in advance.
HimanshuTake a look to the Laurent Schneider's solution.
Nicolas. -
HT2486 how can I export the contact book data to a csv file for editing?
how can I export the contact book data to a csv file for editing?
You can edit a card right in Contacts. No need to export and re-import.
Select a name and on the right side, click the Edit button: -
I need to import data from a CSV file to an Oracle table
I need to import data from a CSV file to an Oracle table. I'd prefer to use either SQL Developer or SQL Plus code.
As an example, my target database is HH910TS2, server is ADDb0001, my dB login is em/em, the Oracle table is AE1 and the CSV file is AECSV.
Any ideas / help ?And just for clarity, it's good to get your head around some basic concepts...
user635625 wrote:
I need to import data from a CSV file to an Oracle table. I'd prefer to use either SQL Developer or SQL Plus code.SQL Developer is a GUI front end that submits code to the database and displays the results. It does not have any code of it's own (although it may have some "commands" that are SQL Developer specific)
SQL*Plus is another front end (character based rather than GUI) that submits code to the database and displays the results. It also does not have code of it's own although there are SQL*Plus commands for use only in the SQL*Plus environment.
The "code" that you are referring to is either SQL or PL/SQL, so you shouldn't limit yourself to thinking it has to be for SQL Developer or SQL*Plus. There are many front end tools that can all deal with the same SQL and/or PL/SQL code. Focus on the SQL and/or PL/SQL side of your coding and don't concern yourself with limitations of what tool you are using. We often see people on here who don't recognise these differences and then ask why their code isn't working when they've put SQL*Plus commands inside their PL/SQL code. ;) -
Which version of the Forms Central subscription will allow me to export data to excel (CSV file)?
Hi Heather 349
I believe you can do it with both FormsCentral Basic and FormsCentral PLUS
Also Refer : Tutorial: Exporting Responses to Excel, CSV or PDF -
Need help in loading data from a csv file to a table in Oracle DB
Hi,
I am using sqlplus as a client to connect to the server.
I am trying to load data from a csv file from a client to a table in Oracle DB server.
I am trying to use the below command
" LOAD DATA INFILE 'test.csv' INTO TABLE testTable FIELDS TERMINATED BY ',' (test1,test2,testc3,testc4); "
But, I am encountered with the following error
"SP2-0042: unknown command "load data" - rest of line ignored."
Thanks in advance.
SBHey Frostmann,
That was a nice post....
I changed my mind to use an 'Insert into' statement from a shell script.
I created a DB table named test and I tried using the below shell script to insert a row in the table.
sqlplus test/test@test <<ENDOFSQL
INSERT INTO test VALUES('test1',123,'test2','test3');
exit
ENDOFSQL
A row is succesfully inserted into the table when I run the script manually, but it does not insert rows when a cron job is scheduled.
Could you please help me with this?
Thanks in advance.
SB -
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 haq2 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. -
Insert Data into Table from TXT or CSV file !!!!!
Dear All,
Recently I have started working on APEX. In Oracle Forms, we used to use TEXT_IO for inserting records into tables from txt files. Now I want to do the same thing in apex 3.2. How can I insert data into tables from txt of csv files.
Waiting of your valuable suggestions.
With kind regards,
Yousuf.Yousuf
wwv_flow_files is used by APEX to hold uploaded files.
If you incorporate a file browse item on you page, browse for the selected file, then submit the page (having the PL/SQL process described as an on suibmit process) then what I detailed should work.
If you don't need users to have access to this then just go to Home>Utilities>Data Load/Unload in APEX and there is a handy load utility there that does it all for you.
Cheers
Ben -
Writing data from a CSV file in to table
Hi All,
I have a CSV (Comma Separated Values) file and i want to write its data in to the table.
How can i get data from a CSV file.As Karthick suggested, you can use External Tables or Sql Loader functionality
You can check this link for example on Sql Loader http://surachartopun.com/2007/10/example-sql-loader-some-data-into.html
Maybe you are looking for
-
Error when splitting a Table into two columns - Please help!
Hi! I have created a table in which I have created a header which has been split into 3 parts conisting of 2 columns. These all work fine. However, when I try to split the row below the header row into 2 columns, it does so but, in a way, connects th
-
Safari 5 keeps crashing on launch
After updating to Safari 5, the application will no longer open. When I click on the icon it jumps up and down and then acts like its open and running. If I click 'open new tab' then it appears as a small grey window in the bottom of my screen. It sh
-
How to turn my calendars into delegates?
I've just started using Google Calendar. So I've recently tried to sync it with my iCal through CalDAV. I've noticed that the events from my iCal can't be synced with my Google Calendar, only the calendars displayed as "Delegates". Questions: 1) Is i
-
Dear Friends, I have q query in FA module. I want to capitalize the exchange gain or loss relating to an asset and add it to cost of the asset. In AP module, when payment is payment the difference between invoice rate & payment rate goes to exchange
-
This just started to happen recently,when I try to look at my email accounts (gmail and yahoo) on my itouch, they won't fetch the most recent emails. I'll press the refresh button, and it'll say latest update was in JUNE. I tried lookin up my emails