Write a query to a xl file
Hi everybody
I need to write a simple query result to a xl format file, how can I do that?
Using the FOR XML Clause to Return Query Results as XML
When you include the FOR
XML clause in your query, you must specify one of the four supported modes—RAW,AUTO, EXPLICIT,
or PATH. The options available to each mode vary according to that mode;
however, many of the options are shared among the modes.
Please refer the below links ,will be more useful
http://www.diaryofaninja.com/blog/2010/08/12/output-data-as-raw-xml-from-ms-sql-ndash-a-little-known-feature
https://www.simple-talk.com/sql/learn-sql-server/using-the-for-xml-clause-to-return-query-results-as-xml/
Similar Messages
-
Write big query results into a file ? ? ?
Hi all,
The problem is: I want to write a simple query results into a file. I have no idea how to do that. Only thing I know is utl_ functions. Please advise GURUS how can I use them for big queries. Any example will be really appreciable.
Thank you in advance.
Message was edited by:
v838hi,
i´ld do it like that:
filedir varchar2(30):= '/usr/frajo/';
filename varchar2(30):= 'file.txt';
fhandle utl_file.file_type;
cursor x is
select ... (what ever)
begin
fhandle := utl_file.fopen (filedir, filename,'a');
open x;
loop
fetch x into (what ever)
exit when x%notfound;
utl_file.put_line (fhandle,'text and you results');
end loop;
utl_file.fclose(fhandle);
end;
happy xmas. franz -
Procedure to write Oracle Query Result to Excel file?
Hi All,
I have a requirement to write a procedure which will write the result of a Query (select statement) to a Excel file.
I use a third party tool to do so but it fails when the query fetches more than 65000 records!
Can someone suggest me a procedure ( may be written in PL/SQL ) which can be used to achieve this task?
If there is a procedure available readily, can you please share it with me?
Thanks in advance
Himanshu DabirThere is a ready procedure (actually PL/SQL blocks by Tom Kyte) available at
http://www.quest-pipelines.com/newsletter-v5/0704_C.htm
but it also suffers from Microsofts limitation of 65536 rows per sheet. -
Write the output of a query in ODI to file
Hi Friends,
I am using ODI 11g.
In ODI I want to write the output of the below query to a unix file.
SELECT 'H'|| rpad('SB9KT.KTPRTO.EBSDATA.D0000000','30',' ')|| rpad(to_char(sysdate, 'YYYYMMDDHHMMSS'), 16, ' ')
FROM dual;
Please suggest any inputs.
Thanks,
Lonylony wrote:
Hi Friends,
I am using ODI 11g.
In ODI I want to write the output of the below query to a unix file.
SELECT 'H'|| rpad('SB9KT.KTPRTO.EBSDATA.D0000000','30',' ')|| rpad(to_char(sysdate, 'YYYYMMDDHHMMSS'), 16, ' ')
FROM dual;
Use OdiSqlUnload tool to write the output of the sql query to a file
Please suggest any inputs.
Thanks,
Lony -
How to write the output of an SQL query to a text file?
I am using Oracle 11g and SQL plus.
I have a large table called rating.
Whenever I do
SQL> select * from rating;
The output goes much beyond what the SQL Plus screen can show. I want to therefore store the output of this query into a text file.
How can this be done? Please help. Thanks.SQL> SPOOL results.txt
SQL> select * from rating;
SQL> SPOOL OFF -
How to write named query if we want to use IN syntax in our sql statement?
I cannot find a suitable category about named query, so please move to appropriate place if there is any.
When we write named query, below statement is fine.
Query q2 = em.createQuery("SELECT o FROM Table1 as o WHERE field1 = :input1"); q2.setParameter("input1", "value1");
Now, my question is, how can I write this type of query when we want to use the IN sql syntax? As below statement CANNOT return correct results. Even I tried to put a pair of single quote [ ':input2' ], it won't help also.
Query q2 = em.createQuery("SELECT o FROM Table1 as o WHERE field2 IN (:input2)"); q2.setParameter("input1", "3633, 3644");
Can anyone suggest? Thanks.roamer wrote:
Now, my question is, how can I write this type of query when we want to use the IN sql syntax? As below statement CANNOT return correct results. Even I tried to put a pair of single quote [ ':input2' ], it won't help also.
Query q2 = em.createQuery("SELECT o FROM Table1 as o WHERE field2 IN (:input2)");
q2.setParameter("input1", "3633, 3644");
Can anyone suggest?The above is in your code right? Not in some configuration file?
Then you do it the same way as with regular jdbc/sql.
1. You start with a collection of values - call it collection A.
1. Create a for loop that dynamically creates the string using 'bind' variables (whatever you want to call the 'colon' entity in the above).
2. Call the createQuery method using the string that was created
3. Create a second loop that iterates over A and populates with setParameter.
Pseudo code
Object[] A = ...
String sql = "SELECT o FROM Table1 as o WHERE field2 IN (";
for (int i=1; i <= A.length; i++)
if (i == 1)
sql += ":input" + i;
else
sql += ",:input" + i;
sql += ")";
Query q2 = em.createQuery(sql);
for (int i=1; i <= A.length; i++
q2.setParameter("input" + i, A[i-1]);
}By the way there is a jdbc forum. -
Extract data from Query to a Flat File - scheduling in the background
Hi All,
We need to extract data from a query to a flat file periodically, but each time 10 separate executions based on 10 profit centers, to get the separate files.
So, we have PC1, PC2, ... PC10 Profit centeres.
We have Query1, with profit center variable.
We have created 10 variants for Query1 so that we can execute for 10 profit centers.
Now, we have used RSCRM_BAPI to execute the Query1 and write to a flat file. Now we are having a problem in getting this feature used to execute the query automatically for 10 different varaints.
Thanks in advance,
_ ShashiShashi,
You can try using Information Broadcasting or Reporting Agent. You can schedule this in Information Broadcasting.
check this link for Information Broadcasting... <a href="http://help.sap.com/saphelp_nw04s/helpdata/en/a5/359840dfa5a160e10000000a1550b0/content.htm">http://help.sap.com/saphelp_nw04s/helpdata/en/a5/359840dfa5a160e10000000a1550b0/content.htm</a>
Nagesh Ganisetti. -
Hi friends,
My server Intelligence Agent (SIA) can not start because the database service "SQLAnywhereForBI" can't start also. I got the following error :
"I . 08/09 20:35:06. A read failed with error code: (1392), Le fichier ou le répertoire est endommagé et illisible.
E. 08/09 20:35:06. Fatal error: cannot write to transaction log "C:\Program Files (x86)\SAP BusinessObjects\sqlanywhere\database\BI4_Audit.log"
E. 08/09 20:35:06. unable to start database "C:\Program Files (x86)\SAP BusinessObjects\sqlanywhere\database\BI4_CMS.db"
E. 08/09 20:35:06. Error writing to transaction log file
I. 08/09 20:35:06. Database server shutdown due to startup error "
inside the database log file.
Please, can you help meI found the solution by following the advice given on the following forum:
http://evtechnologies.com/transaction-logs-on-sybase-sql-anywhere-and-sap-businessobjects-bi-4-1
In fact, I crushed the BI4_Audit.db and BI4_Audit.log files and I replaced with others that I got from another machine where I installed BO again and where the files are not corrupted . After I logged in to the CMS database by executing the command in the command line:
dbisql -c "UID = DBA; PWD = mypassword; BI4 Server =; DBF = C: \ Program Files (x86) \ SAP BusinessObjects \ sqlanywhere \ database \ BI4_CMS.db."
Once connected, I start the command:
alter database 'C: \ Program Files (x86) \ SAP BusinessObjects \ sqlanywhere \ database \ BI4_Audit.db' alter log off;
The query runs successfully.
And that's good, I can be connected to BO smoothly.
Thank you again Eric -
How to use property file - sql query define in property file
Hi All,
Anybody please tell me how to use property file.
I have placed sql query in propery file and I have to access this in my file.
well so far this is my code but don't know how to implement in the following ...
pstmt = con.prepareStatement("select * from registration where username=?");
instead of writting the query I want to use the property file.
so far I have developed the following code...
FileInputStream fis = new FileInputStream("querysql.property");
Properties dbProp = new Properties();
dbProp.load(fis);is the code correct... or is there another way to access property file
Please help.
please reply soon....
ThanksBefore answering, check if it's already been done here http://www.jguru.com/forums/view.jsp?EID=1304182
-
Export query result to txt file
Hello,
I'm trying to export a query result to txt file but I facing some problems.
I'm using the comand below:
set echo off newpage 0 space 0 pagesize 0 feed off head off trimspool on
set colsep ,
spool C:\estados.txt
select id_estado,cod_estado,nme_estado from tb_estado;
spool off
First problem: My select statement is being writen on my estados.txt
Second problem: The results are being writen with a lot of blank spaces in start of line, for example, instead of write "1,AC,Acre" the line is write as " 1,AC,Acre".
Third problem: The "spool off" statement is being written on my estados.txt
How could I solve it?
Thanks1. Works here - what version of SQL*PLUS are you using?
2. If you want to prevent spaces, you have to write your SELECT like this:
select id_estado || ',' || cod_estado || ',' || nme_estado from tb_estado;Note: not tested.
3. See 1.
C. -
I have a requirement to put the query result in a file(.csv),
Pls let me know is there a possibility to achieve this using dbms_output package
Thanks859486 wrote:
I have a requirement to put the query result in a file(.csv),
Pls let me know is there a possibility to achieve this using dbms_output packageNo. The DBMS_OUTPUT package is almost ALWAYS the wrong package to use. It is the most misunderstood and most frequently abused piece of PL/SQL software. So no - it is not suited in anyway to spool CSV output. In fact, trying it with a large SQLdataset can crash the Oracle server - as memory will be exhausted and the swap daemons will trash CPU utilisation.
To read or write a physical o/s file - the typical package used is UTL_FILE. It is fairly easy using UTL_FILE to create a CSV file.
However, there could be far better alternatives. The CSV file may be needed by a web client - in which case the file can be created as a CLOB and provided as a Mime text/csv data stream to a web browser (which usually will automatically open in Excel).
The CSV file may need to be delivered via e-mail. In which case, the CSV file contents can be delivered via UTL_SMTP to a mail server as an e-mail attachment.
The CSV file may be needed to be delivered to a remote server. In which case the CSV file can be created as a CLOB and this CLOB can be ftp'ed via PL/SQL to the remote server as a text file.
So there are many options in creating and delivering a CSV file. Using DBMS_OUTPUT though is not a sensible option - ever. -
How to write a Query for the mentioned scenario.
Hi All,
Table A
ID|| Start_Date||End_date||Rate
1||01-Jan-2011||31-Mar-2011||0.8
1||01-Apr-2011||31-Jun-2011||0.9
I have a table like above. I want to write a query to display the result as below.
ID|| Start_Date||Rate
1||01-Jan-2011||0.8
1||01-Feb-2011||0.8
1||01-Mar-2011||0.8
1||01-Apr-2011||0.9
1||01-May-2011||0.9
1||01-Jun-2011||0.9
Kindly help.
Thanks!
GJTry to read link mentioned by SB. It will make you more interactive to share your problems. And immediate reply too from experts.
Check your solution below.
SQL> ed
Wrote file afiedt.buf
1 WITH data1 AS
2 (
3 SELECT 1 id, TO_DATE('01-Jan-2011' , 'DD-Mon-YYYY') stdt,TO_DATE('31-Mar-2011' , 'DD-Mon-YYYY') endt, 0.8 rate FROM dual
4 UNION ALL
5 SELECT 1 id, TO_DATE('01-Apr-2011' , 'DD-Mon-YYYY') stdt,TO_DATE('30-Jun-2011' , 'DD-Mon-YYYY') endt, 0.9 rate FROM dual
6 )
7 SELECT id, ADD_MONTHS(stdt, level -1) st_dt, rate FROM data1
8 CONNECT BY level <= ROUND(MONTHS_BETWEEN(endt,stdt))
9 AND rate= prior rate /* stick to current line */
10* AND prior sys_guid() IS NOT NULL /* used to terminate the connect by loop */
SQL> /
ID ST_DT RATE
1 01-JAN-11 .8
1 01-FEB-11 .8
1 01-MAR-11 .8
1 01-APR-11 .9
1 01-MAY-11 .9
1 01-JUN-11 .9
6 rows selected.Thanks!
Ashutosh
Edited by: Ashu_Neo on Oct 8, 2012 11:57 AM -
Write a query to display HI using stars(for loop using)
Hi all
can u tell me please how to write this query
HI
write a query using for loop display the stars(*) in the place of H and I
thanks regards
Edited by: user9195968 on Apr 20, 2010 11:18 PM
Edited by: user9195968 on Apr 20, 2010 11:26 PMuser9195968 wrote:
Hi all
can u tell me please how to write this query
HI
write a query using for loop display the stars(*) in the place of H and I
thanks regardsHere's a starter for you...
SQL> ed
Wrote file afiedt.buf
1 with a as (select 'A' as ch, 2 as line1, 5 as line2, 7 as line3, 5 as line4, 5 as line5 from dual union all
2 select 'B', 4, 5, 5, 5, 5 from dual union all
3 select 'C', 3, 4, 4, 4, 3 from dual union all
4 select 'D', 6, 5, 5, 5, 6 from dual union all
5 select 'E', 7, 4, 6, 4, 7 from dual union all
6 select 'F', 7, 4, 6, 4, 4 from dual union all
7 select 'G', 3, 4, 5, 5, 2 from dual union all
8 select 'H', 5, 5, 7, 5, 5 from dual union all
9 select 'I', 7, 2, 2, 2, 7 from dual union all
10 select 'J', 7, 1, 1, 1, 6 from dual union all
11 select 'K', 5, 6, 4, 6, 5 from dual union all
12 select 'L', 4, 4, 4, 4, 7 from dual union all
13 select 'M', 5, 7, 5, 5, 5 from dual union all
14 select 'N', 5, 5, 7, 5, 5 from dual union all
15 select 'O', 2, 5, 5, 5, 2 from dual union all
16 select 'P', 6, 5, 6, 4, 4 from dual)
17 --
18 ,w as (select 'HI' as word from dual)
19 --
20 ,chrs as (select rownum as chnum, substr(word,rownum,1) as ch
21 from w
22 connect by rownum <= length(word))
23 --
24 select decode(rn,1,decode(bitand(line1,4),4,'*',' ')||decode(bitand(line1,2),2,'*',' ')||decode(bitand(line1,1),1,'*',' '))||
25 decode(rn,2,decode(bitand(line2,4),4,'*',' ')||decode(bitand(line2,2),2,'*',' ')||decode(bitand(line2,1),1,'*',' '))||
26 decode(rn,3,decode(bitand(line3,4),4,'*',' ')||decode(bitand(line3,2),2,'*',' ')||decode(bitand(line3,1),1,'*',' '))||
27 decode(rn,4,decode(bitand(line4,4),4,'*',' ')||decode(bitand(line4,2),2,'*',' ')||decode(bitand(line4,1),1,'*',' '))||
28 decode(rn,5,decode(bitand(line5,4),4,'*',' ')||decode(bitand(line5,2),2,'*',' ')||decode(bitand(line5,1),1,'*',' '))
29 from chrs join a on (a.ch = chrs.ch)
30 cross join (select rownum as rn from dual connect by rownum <= 5) x
31* order by chnum, rn
SQL> /
DECODE(RN,1,DEC
10 rows selected.
SQL>To display characters as stars (as per the unix banner command) you need some sort of bitmap representation of your character set. As I've done, you can define your own, or you could probably get at the internal fonts somehow (I used to do this sort of thing in machine code back on the BBC Master, but not sure how you'd access the font/character set information from within Oracle)
If you actually want the H and the I displaying next to each other then that's a little more work, but you can have a go at that yourself. -
Write a QUERY of Concurrent Program
hello everyone,
i hav one issue and its very urgent, i hav to write a QUERY(in TOAD) where in that QUERY
1)If i give (Concurrent Program Shortname) then it should show me the (Parameters) of that Concurrent Program
2)If i give (Concurrent Program Executable Name) then it should give me (Execution File name) and (Execution Method)
How can i do this?plzz can anyone explain me clearly !!--to fetch responsibility
select resp.responsibility_name
from fnd_responsibility_vl resp, fnd_request_group_units rgu, fnd_concurrent_programs_vl prog
where resp.request_group_id = rgu.request_group_id
AND rgu.request_unit_id = prog.concurrent_program_id
AND rgu.unit_application_id = prog.application_id
AND prog.user_concurrent_program_name = '.................'
--to fetch parameters
select cols.end_user_column_name, cols.form_left_prompt, fvs.flex_value_set_name, cols.default_value
from fnd_descr_flex_col_usage_vl cols, fnd_flex_value_sets fvs, fnd_concurrent_programs_vl prog
where cols.flex_value_set_id = fvs.flex_value_set_id
AND cols.descriptive_flexfield_name = '$SRS$.' || prog.concurrent_program_name
And prog.user_concurrent_program_name like '...........'
--to get details of executables n programs
select
prog.user_concurrent_program_name "program name",
prog.concurrent_program_name "program short name",
appl.application_name "program application name",
prog.description "program description",
exe.executable_name "executable name",
exe.execution_file_name "executable file name",
exe.description "executable description",
decode( exe.execution_method_code, 'I', 'PLSQL Stored Procedure', 'P', 'Report', 'L', 'SQL Loader', exe.execution_method_code) "execution method"
from
fnd_executables exe,
fnd_application_tl appl,
fnd_concurrent_programs_vl prog
where prog.application_id = appl.application_id
AND exe.executable_id = prog.executable_id
AND prog.user_concurrent_program_name = '…………’ -- program name
AND prog.concurrent_program_name = '…………’ -- program short name
AND exe.execution_file_name = '…………’ -- executable file name
--to check where the table is present or not
select * from user_objects where object_name like ' ...............';
---------------------------Form Responsibility---------------
SELECT
fff.function_name,
fff.function_id,
fm.menu_id,
fm.menu_name,
frt.responsibility_id ,
frt.responsibility_name
FROM
fnd_form_functions fff,
fnd_menu_entries fme,
fnd_menus fm,
fnd_responsibility fr,
fnd_responsibility_tl frt
WHERE
fff.function_name = '&FMB_name' and
fff.function_id = fme.function_id and
fme.menu_id = fm.menu_id and
fme.menu_id = fr.menu_id and
fr.responsibility_id = frt.responsibility_id
------------------------------------------------------- -
A better way to write last_day query
Hi folks,
I am looking for a better way to write a query to find last_day in month but if its sunday or holiday it should move to day before last day.
So for example if 31 is sunday it should go for 30, if 30 is holiday it should move down to 29.
I got this so far but the connect by level is hardcoded to 15. Want to see if there is a better way to get this working:
select max(datum)
from ( select last_day(trunc(sysdate)) - level + 1 as datum
from dual
connect by level < 15)
where to_char(datum, 'day') != 'sunday'
and to_char(datum, 'DDMM') not in
('3012')Best regards,
IgorLike this
select to_char(last_day_month, 'Day') day_is,
last_day_month,
last_day_month - case when to_char(last_day_month, 'fmday') = 'sunday' then 1
when to_char(last_day_month, 'ddmm' ) = '3012' then 1
else 0
end last_business_day_month
from (
select last_day(add_months(trunc(sysdate, 'year'), level-1)) last_day_month
from dual
connect by level <= 12
DAY_IS LAST_DAY_MONTH LAST_BUSINESS_DAY_MONTH
Tuesday 31-JAN-12 31-JAN-12
Wednesday 29-FEB-12 29-FEB-12
Saturday 31-MAR-12 31-MAR-12
Monday 30-APR-12 30-APR-12
Thursday 31-MAY-12 31-MAY-12
Saturday 30-JUN-12 30-JUN-12
Tuesday 31-JUL-12 31-JUL-12
Friday 31-AUG-12 31-AUG-12
Sunday 30-SEP-12 29-SEP-12
Wednesday 31-OCT-12 31-OCT-12
Friday 30-NOV-12 30-NOV-12
Monday 31-DEC-12 31-DEC-12
Maybe you are looking for
-
Simple Java Network Programming Question
import java.io.*; import java.net.*; public class ConsumerClient private static InetAddress host; private static final int PORT = 1234; private static Socket link; private static Resource item; private static BufferedReader i
-
My cord failed during sync to an update and now my phone is stuck on the apple symbol but there is a empty bar under it. I tried to turn off the phone but that didn't work and the iTunes onn my computer isn't picking up the device at all. Whats wrong
-
I bought a team license for two computers, the purchase was recorded on the credit card and the amount recorded in the making, but was unable to validate the association staff . I received an email stating that Adobe could not release the payment and
-
I have a MacBook Pro wirelessly connected to a Time Capsule. If during a file transfer, for example during a Time Machine backup, I make an Ethernet connection between them, will the transfer continue only over wireless or will it go over Ethernet? A
-
Multiple rollover areas on a slide, only one works
Hi all, Long time reader, first time poster. I have been looking through all the forums and can't find a solution for this issue. I have a slide with six rollover captions, arranged in two rows of three. Beneath each rollover caption is a regular cap