Aggregated data from oracle to excel report
Hi all,
I have a requirement where i need to fill in an excel report using aggregated data in oracle tables.
example: i need to find total number of employees in each department and the total salaries of each department. My excel report looks like below
DEPT|total employees| total salaries
dept 10|15|75000
dept 20|0|0
dept 30|20|100000
dept 40|5|25000
TOTAL|40|200000
declare
begin
execute immediate 'insert into abc select count(empid),sum(sal), dept_id from emp group by dept_id';
end;
the above query gives me the aggreagted output and then i need to manually insert the data into the excel report. Instead i need an oracle procedure that will automatically insert the data from abc table into the excel report.
i know that the utl_file is used to export the data, but never used.
any help will be really appreciated.
Thanks
S
Hi,
Output Oracle report into HTML:
sqlplus user/pass@inst
SQL> set feed off markup html on spool on
SQL> spool C:\MyReport.html
<br>
SQL> select * from SomeTable;
SQL> spool off
<br>
SQL> set markup html off spool off;
<br>
SQL>
- Open obtained html report with browser; Output Oracle report into EXCEL:
sqlplus user/pass@inst
SQL> set feed off markup html on spool on
SQL> spool C:\MyReport.xls
<br>
SQL> select * from SomeTable;
SQL> spool off
<br>
SQL> set markup html off spool off;
<br>
SQL>
- Open obtained xls with Excel;
- In case of warning message "The file you're trying to open ... is in a different format ...
Do you want to open the file now? - press "Yes"
{code}
Good luck!
http://dba-star.blogspot.com/
Similar Messages
-
Query Data From Oracle to Excel
Dear all,
Please guide me to solve.
Regards
DharmaQuestion's Caption is : Data From Oracle to Excel
While you are asking :
data in execel (windows ) move to Oracle Database table (Linux *64)Anyway, if your question is export data from Excel to Oracle then below thread may be of your interest which are saying that you have to install Dg4ODBC on Windows and use the ODBC driver there.
When running DG4ODBC on Unix you need an ODBC driver on this Unix box which can connect to the MS Excel file. I'm not aware of any suitable driver so far that fulfills the ODBC level 3 standard required for DG4ODBC.
So instead of using DG4ODBC, get the Windows software of DG4ODBC and install it on a Windows machine. You can then connect from your Oracle database to the Dg4ODBC listener on Windows which then spawns the DG4ODBC process. This DG4ODBC process then uses the MS Excel ODBC driver to connect to the Excel sheet.
https://cn.forums.oracle.com/forums/thread.jspa?messageID=10466197
For this purpose there is separate forum too : [url https://forums.oracle.com/forums/forum.jspa?forumID=63] Heterogeneous Connectivity
Regards
Girish Sharma -
Extract data from Oracle in excel file
Hi,
I have a requirement where in I need to extract data from Oracle in excel file and the excel worksheet name should be "Data".
for eg. excel file name "AR Data_DDMMYY" and excel worksheet name "Data"
I have used the UTL_FILE API to extract the tab delimited data which can be opened in excel but it is not exactly an excel file as the worksheet name is same as the file name.
I tried using utl_file.fcopy and frename.
Is there any way to do this using PLSQL?
select * from v$version;
Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bi
PL/SQL Release 10.2.0.5.0 - Production
"CORE 10.2.0.5.0 Production"
TNS for HPUX: Version 10.2.0.5.0 - Production
NLSRTL Version 10.2.0.5.0 - ProductionSample Code:
declare
cursor c is
select * from scott.emp;
v varchar2(100);
f utl_file.file_type;
file_name varchar2(100) := 'AR Data.xls';
dir varchar2(50) := 'CESDIR191710';
--select * from dba_directories
begin
f := utl_file.fopen(dir, file_name, 'W');
v := 'EMPNO'||chr(9)||'ENAME'||chr(9)||'JOB'||chr(9)||'SAL'||chr(9)||'HIREDATE'||chr(9)||'DEPTNO';
utl_file.put_line(f, v);
for i in c
loop
v := i.empno||chr(9)||i.ename||chr(9)||i.job||chr(9)||i.sal||chr(9)||i.hiredate||chr(9)||i.deptno;
utl_file.put_line(f, v);
end loop;
utl_file.fclose(f);
--utl_file.frename(dir, file_name, dir, replace(file_name, '.xls', '_')||to_char(sysdate, 'MMDDYY')||'.xls', false);
utl_file.fcopy(dir, file_name, dir, replace(file_name, '.xls', '_')||to_char(sysdate, 'MMDDYY')||'.xls');
end;Thanks
ImranImran Soudagar wrote:
Hi,
I was able to generate the excel 2007 file with the data using the package from below link;
http://technology.amis.nl/2011/02/19/create-an-excel-file-with-plsql/
but the requirement is to generate excel 2003 file.
I tried changing the .xlsx to .xls and it gives a note while opening the file "The file you are trying to open, abc.xls, is in a different format than specified by the file extension. Verify that the file is not corrupted and is from a trusted source before opening the file. Do you want to open the file now?"Then you have three options:
1) stop using anton's package and find another one that supports the old and deprecated version of Excel 2003
2) write your own package to produce an Excel file.
3) Upgrade your version of Excel to a recent version
I tried the programs from other links on the forum but I am still getting this message. The client does not want this message to be displayed as the excel file works as an input to another system.
Can anyone help me with the issue?
Also, is it true that the programatically generated excel file is actually an xml file which is renamed to .xls and hence it shows the message while opening such files?Yes, Excel supports several different formats for it's files. By default, if you save an XLS files from Excel, it writes it out in a Microsoft proprietary binary format, which you would be hard pushed to replicate easily from PL/SQL. Excel also has the ability to save it's files as XML format, which is more readable and easier to produce programatically, whilst still allowing you to have multiple sheets, formulas and formatting included in it. That's the format that most people who need formatting and multiple sheets opt for when programatically generating their data as excel workbooks. (There's also an SLYK format that people used to use before that, but it's not as flexible)
If you want to write your own, the easiest thing to do is to start with a blank workbook in Excel, and put in your basic requirements e.g. a couple of named sheets, and some data in different formats (number, date, text etc.) and different formatting options etc. Save that file in XML format from Excel and then open up the file using notepad/wordpad to look at the structure. There'll be a whole load of redundant rubbish Microsoft put in there, but you should be able to figure out the basic structure of XML required to give you what you want. -
Data from oracle to excel very urgent
hi all,
im using servlets for fetching the data from oracle , i want to display the data which i get from orcle in excel sheet. A code snippet regarding this is highly appreciated...
Thanks in advanceJust visit Jakarta's POI API. It is simple. You can create workbooks, cells etc. You can apply styles, insert charts. And its very simple
-
Hi,
I want to know how can data be spooled from Oracle table to MS Excel.Is this done with MS Query if so how can that be done?Any other solutions are appreciated.
Thanks,
VenkataYou will be much better off writing an excel spreadsheet that queries the data directly.
First of all you need to create an ODBC connection to the database using ODBC admin.
Then
(1) fire up a new excel worksheet.
(2) Choose Data->Get External Data->New Query
(3) Connect using ODBC
(4) choose any table, columns, etc - it doesn't matter.
(5) at the end pane tick the MS query button. to edit the query press the SQL button.
Easy. Be aware that (i) your query resides in the cell you started with, usually A1, and (ii) if you want to format the columns in the spreadsheet you need to uncheck the formatting boxes in MS Query -
Transfer Data from Oracle to EXCEL
Hello,
I would like to transfer data from an oracle table into an EXCEL-Spreadsheet -
while doing it, I got the error message
"-1002 : 37000 : java.sql.SQLException:[Microsoft][ODBC Excel Driver]'C$_0Output is not a valid name..."
I think I have correctly defined a logical + physical schema for the excel-file (test works and counts rows), and as knowledg-modules I use:
LKM: SQL to SQL and
IKM: SQL Control Append
Does anybody have an idea how to avoid this error-message and to make the transfer working?
Edited by: user10874105 on Jan 30, 2009 7:19 AMHi Ramesh,
yes, this points to the right solution -
The only issue that remains is that by default ODBC-Setting for EXCEL is limitted to 255 Chars.
Otherwise it works perfect! -
Fetch tablespace data from Oracle database(HP UNIX server) to excel Sheet
Hi team,
I have 5 oracle databases and they all are on different machines. i want to fetch data(tablespace data) from db to excel.
here is my macro code
Sub tbs_STD()
Dim Conn As New ADODB.Connection
Dim RS As New ADODB.Recordset
Dim Cmd As New ADODB.Command
Dim sqlText As String
Dim Row As Long
Dim Findex As Long
Dim STD As Worksheet
Dim X As Long
Dim UID As String
Dim PWD As String
Dim Server As String
UID = "monitordb"
PWD = "monitor1"
Server = "STD"
Set STD = ActiveSheet
STD.Select
Conn.Open "PROVIDER=MSDAORA.Oracle;DATA SOURCE=" & Server & ";" & _
"USER ID=" & UID & ";PASSWORD=" & PWD
Cmd.ActiveConnection = Conn
Cmd.CommandType = adCmdText
sqlText = "select sum(a.tots/1048576) Tot_Size,sum(a.sumb/1048576) Tot_Free,round(sum(a.tots-a.sumb)*100/sum(a.tots),2) Pct_used,sum(a.largest/1024) Max_Free,sum(a.chunks) Chunks_Free from(select tablespace_name,0 tots,sum(bytes) sumb,max(bytes) largest,count(*) chunks from dba_free_space a group by tablespace_name union select tablespace_name,sum(bytes) tots,0,0,0 from dba_data_files group by tablespace_name) a group by a.tablespace_name order by a.tablespace_name"
Cmd.CommandText = sqlText
Set RS = Cmd.Execute
For X = 0 To 4 ' Number of columns returning minus 1
'Data.Cells(1, X + 1) = RS.Fields(X).Name
Next
Do While Not RS.EOF
Row = Row + 1
For Findex = 0 To RS.Fields.Count - 1
STD.Cells(Row + 2, Findex + 67) = RS.Fields(Findex).Value
Next Findex
RS.MoveNext
Loop
End Sub
I am able to connect through sqlplus on all machines but when i run the above code it gives me TNS error..
ORA-12154- TNS could not resolve the connect identifier specified..
Each database use same port 1527 and only one of them is able to fetch the data. and if i remove that database from client then the other one starts connecting. I think problem is due to same port number.
Entries in the listener.ora file was made throough oracle client only 32bit.
and i have installed both 10g and 11g client on my local machine.
Please help.You need to configure tnsnames.ora in your OracleClient\network\admin folder with the TNS entries for the servers you're connecting to.
-
How to I convert data from oracle database into excel sheet
how to I convert data from oracle database into excel sheet.
I need to import columns and there datas from oracle database to microsoft excel sheet.
Please let me know the different ways for doing this.
Thanks.asktom.oracle.com has an excellent article on writing a PL/SQL procedure that dumps data to an Excel spreadsheet-- search for 'Excel' and it'll come up.
You can also use your favorite connection protocol (ODBC, OLE DB, etc) to connect from Excel to Oracle and pull the data out that way.
Justin -
How can i extract data from oracle table to flat file or excel spread shee
Hello,
DB Version is 10.1.0.3.0
How can i extract data from oracle table to flat file or excel spread sheet by using sub programs?
Regards,
DHere what I did
SET NEWPAGE 0
SET SPACE 0
SET LINESIZE 80
SET PAGESIZE 0
SET ECHO OFF
SET FEEDBACK OFF
SET VERIFY OFF
SET HEADING OFF
SET MARKUP HTML OFF SPOOL OFF
Sql> SPOOL bing
select * from -------;
SPOOL OFF;
I do not see file.
I also tried
Sql> SPOOL /tmp/bing
select * from -------;
SPOOL OFF;
But still not seeing the fie, -
I need to download data from Oracle data base into a Excel spread sheet
I need to download data from Oracle data base into a Excel spread sheet.
Any input will be appreciated.Goes something like this:
1) create an ODBC connection (on NT/WIN: ODBC DATA SOURCES in the control panel, create a USER DSN.
2) in EXCEL-menu: DATA->GET EXTERNAL DATA->CREATE NEW QUERY. In the wizzard you will see the DSN created in the previous step. Select that source.
3) follow the wizzard.
Hope this does any good...
Regards, -
Using FDM to load data from oracle table (Integration Import Script)
Hi,
I am using Integration Import Script to load data from oracle table to worktables in FDM.
i am getting following error while running the script.
Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done
Attaching the full error report
ERROR:
Code............................................. -2147217887
Description...................................... Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done.
At line: 22
Procedure........................................ clsImpProcessMgr.fLoadAndProcessFile
Component........................................ upsWObjectsDM
Version.......................................... 1112
Thread........................................... 6260
IDENTIFICATION:
User............................................. ******
Computer Name.................................... *******
App Name......................................... FDMAPP
Client App....................................... WebClient
CONNECTION:
Provider......................................... ORAOLEDB.ORACLE
Data Server......................................
Database Name.................................... DBNAME
Trusted Connect.................................. False
Connect Status.. Connection Open
GLOBALS:
Location......................................... SCRTEST
Location ID...................................... 750
Location Seg..................................... 4
Category......................................... FDM ACTUAL
Category ID...................................... 13
Period........................................... Jun - 2011
Period ID........................................ 6/30/2011
POV Local........................................ True
Language......................................... 1033
User Level....................................... 1
All Partitions................................... True
Is Auditor....................................... False
I am using the following script
Function ImpScrTest(strLoc, lngCatKey, dblPerKey, strWorkTableName)
'Oracle Hyperion FDM Integration Import Script:
'Created By: Dhananjay
'Date Created: 1/17/2012 10:29:53 AM
'Purpose:A test script to import data from Oracle EBS tables
Dim cnSS 'ADODB.Connection
Dim strSQL 'SQL string
Dim rs 'Recordset
Dim rsAppend 'tTB table append rs object
'Initialize objects
Set cnSS = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADODB.Recordset")
Set rsAppend = DW.DataAccess.farsTable(strWorkTableName)
'Connect to SQL Server database
cnss.open "Provider=OraOLEDB.Oracle.1;Data Source= +server+;Initial Catalog= +catalog+;User ID= +uid+;Password= +pass+"
'Create query string
strSQL = "Select AMOUNT,DESCRIPTION,ACCOUNT,ENTITY FROM +catalog+.TEST_TMP"
'Get data
rs.Open strSQL, cnSS
'Check for data
If rs.bof And rs.eof Then
RES.PlngActionType = 2
RES.PstrActionValue = "No Records to load!"
Exit Function
End If
'Loop through records and append to tTB table in location’s DB
If Not rs.bof And Not rs.eof Then
Do While Not rs.eof
rsAppend.AddNew
rsAppend.Fields("PartitionKey") = RES.PlngLocKey
rsAppend.Fields("CatKey") = RES.PlngCatKey
rsAppend.Fields("PeriodKey") = RES.PdtePerKey
rsAppend.Fields("DataView") = "YTD"
rsAppend.Fields("CalcAcctType") = 9
rsAppend.Fields("Amount") = rs.fields("Amount").Value
rsAppend.Fields("Desc1") = rs.fields("Description").Value
rsAppend.Fields("Account") = rs.fields("Account").Value
rsAppend.Fields("Entity") = rs.fields("Entity").Value
rsAppend.Update
rs.movenext
Loop
End If
'Records loaded
RES.PlngActionType = 6
RES.PstrActionValue = "Import successful!"
'Assign Return value
SQLIntegration = True
End Function
Please help me on this
Thanks,
Dhananjay
Edited by: DBS on Feb 9, 2012 10:21 PMHi,
I found the problem.It was because of the connection string.The format was different for oracle tables.
PFB the format
*cnss.open"Provider=OraOLEDB.Oracle.1;Data Source= servername:port/SID;Database= DB;User Id=aaaa;Password=aaaa;"*
And thanks *SH* for quick response.
So closing the thread......
Thanks,
Dhananjay -
How to download data from itab to Excel sheet..
Hi sap Experts,
I develop one report to download data from itab to excel sheet.I done it perfectly.
My doubt is in the excel sheet i need to put headings. and also at last i need to display total no.of Records.
Please help me how to do this.
Thanks in Advance....
Thanks and Regards
Siri.......................u can either use GUI_DOWNLOAD or the method below...just give a try
DATA:WK_string TYPE STRING.
DATA:Wk_EXT(4) TYPE C value '.xls'.
DATA:WK_path TYPE STRING.
DATA:wk_file_name type string.
data:wk_records type sy-tfill.
wk_file_name = 'Downloaded'.
describe table itab lines wk_records.
LOOP AT ITAB.
at first.
**Provide path
concatenate 'C:\' wk_file_name Wk_EXT into wk_path.
open dataset WK_path for output in text mode encoding default.
if sy-subrc 0.
write:'ERROR while opening dataset !!!!!!'.
EXIT.
endif.
CONDENSE wk_path.
**Heading Part
concatenate 'Part No' 'Description'
into wk_string separated by cl_abap_char_utilities=>horizontal_tab.
endat.
**Data ITAB
CONCATENATE ITAB-MATNR itab-maktx into wk_string
separated by cl_abap_char_utilities=>horizontal_tab.
transfer wk_string to WK_path.
at last.
clear wk_string.
Concatenate 'Records Passed:' wk_string into wk_string.
transfer wk_string to WK_path.
close dataset WK_path.
endat.
endloop. -
Calling stored procedure From Oracle BAM 11g Reports ???
Is it possible to pass user prompt value from oracle bam11g report to the stored procedure as parameter and get data from database and display report on that?
Reagrds,
Ravi yadavHi Gopal,
Thank you for your reply.
>Is there any way other than Stored Procedure?
Can you try configuring sender adapter to poll the data in intervals. You can configure Automatic TIme planning (ATP) in the sender jdbc channel.
I need to select the data from different tables based on some conditions. Let me simplify that.
Suppose Table1 contains 'n' no of rows. For each row, I need to test two conditions where only one condition will be satisfied. If 1st condition is satisfied, then data needs to be taken from Table2 else data needs to be taken from Table3.
How can we meet this by configuring sender adapter with ATP?
================================================================================================
>How to handle Data Types as data is coming from two different tables?
If you use join query in the select statement field of the channel then whatever you need select fields will be returned. This might be fields of two tables. your datatype fields are combination of two diff table.
we need to take data only from one table at a time. It is not join of two tables.
================================================================================================
Thanks,
Jyothirmayi. -
Export data from block to excel.
Hi
Does anybody know how I can export data from oracle forms to an excel worksheet. I need to provide a direct interface for a user where he fetches the data into the block and by just click a button the data from the block should go to an excel sheet.
Thanks in advance
-SamsamSomething along the following lines should help you in you are Client/Server. If you're on the Web then make sure you have WebUtil set up and add "CLIENT_" to all the OLE2 calls.
PROCEDURE P_EXCEL IS
application ole2.Obj_Type;
workbooks ole2.Obj_Type;
workbook ole2.Obj_Type;
worksheets ole2.Obj_Type;
worksheet ole2.Obj_Type;
args ole2.List_Type;
cell ole2.Obj_Type;
j INTEGER;
k INTEGER;
file_name_cl VARCHAR2(32767);
item_prompt VARCHAR2(32767);
user_cancel EXCEPTION;
BEGIN
-- open the java save file dialogue box
file_name_cl := GET_FILE_NAME('H:\', 'file_name.xls', 'XLS Files (*.xls)|*.xls|', NULL, SAVE_FILE, TRUE);
file_name_cl := SUBSTR(file_name_cl,1,LENGTH(file_name_cl));
IF file_name_cl IS NULL THEN
RAISE user_cancel;
END IF;
application := ole2.create_obj('Excel.Application');
workbooks := ole2.Get_Obj_Property(application, 'Workbooks');
workbook := ole2.Invoke_Obj(workbooks, 'Add');
worksheets := ole2.Get_Obj_Property(workbook, 'Worksheets');
worksheet := ole2.Invoke_Obj(worksheets, 'Add');
go_block('EXPORT_BLOCK');
first_record;
j:=1; /* Represents row number */
k:=1; /* Represemts column number */
/* Add the column headings using item prompts */
FOR k IN 1..10 /* Block has 10 visible columns */
LOOP
item_prompt := get_item_property(:SYSTEM.CURRENT_BLOCK||'.'||:SYSTEM.CURRENT_ITEM, prompt_text);
args:=ole2.create_arglist;
ole2.add_arg(args, j);
ole2.add_arg(args, k);
cell:=ole2.get_obj_property(worksheet, 'Cells', args);
ole2.destroy_arglist(args);
ole2.set_property(cell, 'Value', item_prompt);
ole2.release_obj(cell);
next_item;
END LOOP;
j:=j+1; /* Add to rowcount so that data won't overwrite column headings! */
LOOP
/* Add in all the data */
FOR k IN 1..10 /* Block has 10 visible columns */
LOOP
IF NOT name_in(:system.cursor_item) IS NULL THEN
args:=ole2.create_arglist;
ole2.add_arg(args, j);
ole2.add_arg(args, k);
cell:=ole2.get_obj_property(worksheet, 'Cells', args);
ole2.destroy_arglist(args);
ole2.set_property(cell, 'Value', name_in(:system.cursor_item));
ole2.release_obj(cell);
END IF;
next_item;
END LOOP;
j:=j+1;
IF :system.last_record = 'TRUE' THEN
exit;
ELSE
next_record;
END IF;
END LOOP;
ole2.Release_Obj(worksheet);
ole2.Release_Obj(worksheets);
/* Save the Excel file created */
args := ole2.Create_Arglist;
ole2.Add_Arg(args, file_name_cl);
ole2.Invoke(workbook, 'SaveAs', args);
ole2.Destroy_Arglist(args);
/* release workbook */
ole2.Release_Obj(workbook);
ole2.Release_Obj(workbooks);
/* Release application */
ole2.Invoke(application, 'Quit');
ole2.Release_Obj(application);
EXCEPTION
WHEN user_cancel THEN
RAISE;
END; -
I have written a query in Toad. It retrieves very huge data around 5000000 records. Now I want to export this data from Toad to Excel with faster rate. I tried to export using Save as and then gave the filename as "file.xls and enabled add include column headers. It got executed for 200000 records. But after that got a error message exceeds the limit.
can any one please suggest me how to export the while data with faster rate from Toad to excel.
Thanks,
Vas.905508 wrote:
hi all ,
it's bit urgent issue. So please help me in this. it would be very helpful to me. so please share your suggestions for this.It might be urgent for you, but what makes you think everyone should drop what they're doing (their own work) as if your issue is more important than anyone elses?
And to top that you've come onto the Oracle SQL and PL/SQL forum to ask a question about TOAD (a non-oracle product) and Excel (a non-Oracle product).
In answer to your question however, when you go to export your data from TOAD do you have the "Display all results in grid" option checked (which is the default). If so, then as it queries all the data and tries to write it out to a CSV file, it will also try to load all that data into the grid within TOAD, which can cause it to run out of memory. Uncheck that option and TOAD will just read the data and write it to the file.
Maybe you are looking for
-
Duplicates from PSA to DSO Load
Hi, I have 2 key fields in the DSO and there is a status field in data fields. In delta loads, I am getting the records with the same keys (already existing) but the different statuses. Due to this I am getting duplicate issue. But, I need to load th
-
I live in Mountain View and use Google WiFi which is provided by Google for the City of Mountain View. For the past few months, they have been having a BIG problem with the corruption of downloads. Even teensy tiny ones. Perhaps you've heard about it
-
I tried to update my old iPhone 3GS and is giving me a message that it can be activated. This is my old phone and it shouldn't have a line but I Still like to use it as an iPod. What can I do.
-
Printer Paused - "/usr/lib/cups/backend/hp failed" [SOLVED]
Nothing that I try to print with CUPS goes to the printer, it just sits in the job list saying "Pending". CUPS says the status of my printer is: Paused - "/usr/lib/cups/backend/hp failed" Restarting CUPS or DBus does nothing. I didn't notice any upda
-
Core Audio : Disk too slow (prepare)
Can anyone help me. I have created a track that will not bounce because it always comes up with this error message: Core Audio: disk too slow (prepare). I cannot bounce tracks individually for the same reason. I have tried deleting some tracks that i