End the result of an sql query by Email as an excel file attachement
Hi,
I would like to create a PL/SQL function that send the result of an sql query by Email as an excel file attachement.
i'm newbie in pl/sql an d i dont know if it's possible to do such task.
regards,
i think a regular expression is he way to go in your case...
Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com
Similar Messages
-
Pass the result of a SQL Query as table_name for another SQL Query
Hi All,
How to pass the result of a SQL Query as parameter to another SQL Query
Eg: I am doing the steps below.
1) select distinct table_name as TAB1 from all_tab_cols where table_name like 'T_%' and column_name like '%XYZ'
2) I want to pass the table_name from step 1 above as parameter to another query "select * from TAB1"
ThanksNaveen B wrote:
Hi All,
How to pass the result of a SQL Query as parameter to another SQL Query
Eg: I am doing the steps below.
1) select distinct table_name as TAB1 from all_tab_cols where table_name like 'T_%' and column_name like '%XYZ'
2) I want to pass the table_name from step 1 above as parameter to another query "select * from TAB1"
ThanksYou should craete PL/SQL code with cursor which will accept a parameter and call that cursor inside the first one
But if the first sql returns only one row, you can do it with simple sql code
select * from (select distinct table_name as TAB1 from all_tab_cols where table_name like 'T_%' and column_name like '%XYZ')- - - - - - - - - - - - - - - - - - - - -
Kamran Agayev A. (10g OCP)
http://kamranagayev.wordpress.com
[Step by Step install Oracle on Linux and Automate the installation using Shell Script |http://kamranagayev.wordpress.com/2009/05/01/step-by-step-installing-oracle-database-10g-release-2-on-linux-centos-and-automate-the-installation-using-linux-shell-script/] -
Use the results of an SQL query to create another query
I am working on a bidding/allocation system using C# and MySQL, and I am currently having difficulty implementing the “post-allocation” mechanics of the system. Let me explain how it works, before introducing the code:
When the bids are made on the system, they all have the position 0, so the first thing the system does is order them according to priority.
(bid table)
In this case, 5 bidders are interested in what is in plot 15, but we have not assigned them a position yet.
(bid table)
The system then organises the bids according to the order in which they are going to processed.
The bids are then allocated, but unfortunately there are only 3 spaces in plot 15 that can be allocated. As a result, we use the priority listing to determine which bidder gets what.
(booking table)
At this stage, I can say that I am stuck, there are two things that I want to do, both of which involve reusing the results of the query at step 2.
(bid table)
The bidders that have their job allocated should see: their bid.status updated
from Queued to Allocated,
the bid.position should
be set to 0,
and their job_id should
be set to the booking they have been allocated (i.e. booking.id).
The bidders that have not had their jobs allocated should see: their bid.status remain
as Queued, and their bid.position should
be set to 0 in
preparation for the method to run again
The difficulty I am having is in stage 3, how do I determine which jobs have been allocated and which ones have not, and then run the necessary SQL queries in order to make the updates?
My code so far is as follows:
// STEP 1a - SELECT BIDS
string query =
"SELECT t1.operator_id, t1.datetime, t1.plot_id, t1.position, t2.market_access FROM bid t1 " +
"JOIN operator t2 ON t1.operator_id = t2.id WHERE t1.status='Queued' AND t1.postcode=@postcode " +
"ORDER BY t2.market_access ASC, t1.datetime ASC";
var bidList = new List<BidList>();
var cmd = new MySqlCommand(query, _connection);
cmd.Parameters.AddWithValue(("@postcode"), _plot);
MySqlDataReader dataReader = cmd.ExecuteReader();
while (dataReader.Read())
var item = new BidList
OperatorId = dataReader["operator_id"] + "",
PlotId = dataReader["plot_id"] + "",
Position = dataReader["position"] + "",
Datetime = dataReader["datetime"] + "",
MarketAccess = dataReader["market_access"] + "",
bidList.Add(item);
dataReader.Close();
// STEP 1b - SET PRIORITIES
for (var i = 0; i < bidList.Count; i++)
var position = i + 1;
bidList[i].Position = position.ToString();
query = "UPDATE bid SET position=@position WHERE status='Queued' AND postcode=@postcode AND operator_id=@operator_id;";
cmd = new MySqlCommand(query, _connection);
cmd.Parameters.AddWithValue(("@position"), position);
cmd.Parameters.AddWithValue(("@postcode"), _plot);
cmd.Parameters.AddWithValue(("@operator_id"), bidList[i].OperatorId);
cmd.ExecuteNonQuery();
dataReader.Close();
// STEP 2 - ALLOCATE JOBS ACCORDING TO PRIORITY
foreach (var t in bidList)
query = "SELECT operator_id, plot_id, status FROM booking " +
"WHERE status='open' AND postcode=@postcode AND operator_id='0'" +
"ORDER BY datetime ASC;" +
"UPDATE booking SET operator_id=@operator_id, status='Allocated' " +
"WHERE (plot_id=@plot_id AND operator_id='0' AND status='Open') LIMIT 1;";
cmd = new MySqlCommand(query, _connection);
cmd.Parameters.AddWithValue(("@operator_id"), t.OperatorId);
cmd.Parameters.AddWithValue(("@postcode"), _plot);
cmd.Parameters.AddWithValue(("@plot_id"), t.PlotId);
cmd.ExecuteNonQuery();
dataReader.Close();
// STEP 3
CloseConnection();I can't tell. When modifying row(s) you have to be able to uniquely be able to identify the row(s) in the database you want to modify. That is why I recommended the other day to use DataAdapter instead of the DataReader. You can with the
reader, but you need to unique identify the rows.
I can't tell from the limited amount of data you posted if in table 2 that there is only one row with the same operator id and plot id. It looks like in table 2 the 'id' number is unique. When working with a database with multiple tables you
need to be able to link tables together with primary keys (columns wit unique values). If the database isn't designed properly then it is impossible to do some operations. So you always have to make sure you design a database properly.
jdweng
When you say table 2 are you referring to the bid or booking table?
Here is the table structure for the bid table
Here is the table structure for the booking table
Hope it helps makes things clearer! -
How to use the result of a sql query for a max () function
Hi
I wrote a query on which i wrote
"select max(id) from users "
how can i use the returned value.
if i made the var name ="userid"
can it be userid.rows[0] or what.
thnx for any helpHi!
The result of this query will be the max ID of users' IDs.
Let say we have:
String sql="select max(users.id) from users";
Statement st = ctx.conn.createStatement();
ResultSet rs = st.executeQuery(sql);
rs.next();
So you can get the max Id in the following way:
int maxId=rs.getInt("id");
Regards,
Rossi -
Making Buttons appear depending on the results of a SQL Query
I need some help here I am still working on a time clock program
I need help with the clock in and out buttons i need to know how to make
the clock in button appear only if they are not clocked in. But I can not seem
to make the sql statement or maybe my code is wrong, it needs to just get a
count to see if they have any entries that have 0 in the hoursworked column
and if so then it needs to just display the clock out if not then just the clockin button needs to be displayed this was my orignal code that was not working
<%
String statement = "select count(*) as cnt from TimeSheet Where idnum = " + session.getAttribute("IDNUM");
stmt.execute(statement);
rs = stmt.getResultSet();
rs.next();
int num = rs.getInt("cnt");
if (num == 0 || num == null)
{%>
<tr>
<td><input type="submit" value="Clock In" name="button"></td>
</tr>
<%}
else
{%>
<tr>
<td><input type="submit" value="Clock Out" name="button"></td>
</tr>
<% } %>but it did not work it would only display the clock out button so i need to figure this out so that the user can not clock into the program twice to get double hours and so forth.Does it even compile ?Yes, it wouldnt, not even in 1.5
it needs to just get a
count to see if they have any entries that have 0 in the hoursworked column
and if so then it needs to just display the clock out if not then just the clockin button needs to be displayed in which case,
1. your sql is not correct.
2. session.getAttribute("attrName") returns an Object - is the IDNUM column of type number
(going by the fact that you have not enclosed the value in single quotes '')
Assuming that you have a column called 'hoursworked' in table 'timesheet' and
IDNUM is of type NUMBER
<%
Integer idNum = (Integer)session.getAttribute("IDNUM");
//from the OP :: get a count to see if they have any entries that have 0 in the hoursworked column
String statement = "select count(*) as CNT from TIMESHEET where IDNUM = " + idNum + " and HOURSWORKED = 0 ";
//remaining stuff :: Look out for the error pointed out by Pgeuens
cheers,
ram. -
Result of an SQL query as a Column name of another query
Hi Friends,
Can we use a result of a SQL Query as a column name of another table to retrieve data. If so please help me.
For eg :
I have a table where is store numbers;
select col1 from table1 where col1='5';
and i have another table where .. this value of col is a column name..
select ( select col1 from table1 where col1='5') from table2;
Thanks in advance.Hi,
ORAFLEX wrote:
Hi Friends,
Can we use a result of a SQL Query as a column name of another table to retrieve data. If so please help me.
For eg :
I have a table where is store numbers;
select col1 from table1 where col1='5';
and i have another table where .. this value of col is a column name..
select ( select col1 from table1 where col1='5') from table2;
Thanks in advance.Do you really mean that?
select col1 from table1 where col1='5';That query will always return either '5' or nothing. Whatever you're trying to accomplish with that, you can do with an EXISTS query.
Perhaps you meant to reference two different columns in that query:
select col1 from table1 where col2='5';In that case, sorry, no, you can't do that without resorting to dynamic SQL.
If the same column is used throughout the query (but could change every time you run the query), then the dynamic SQL might be pretty easy. In SQL*Plus, for example, you could use substitution variables, defined in another query at run-time.
If there are only a few possible values that the sub-query could possibly return, and you know what they all are, then you can fake a dynamic query like this:
SELECT CASE ( SELECT col1
FROM table1
WHERE col2 = '5'
WHEN 'BONUS' THEN bonus
WHEN 'COMM' THEN comm
WHEN 'SAL' THEN sal
END AS col1
FROM table2
;Sorry to give such a vague answer, but it's the best I can do with the information I have.
It would help if you posted a little sample data (CREATE TABLE and INSERT statments for both tables), and the results you want to get from that data. If you want to pass a parameter to the query, give the results you want for a couple of different parameters. -
Emailing results of a SQL Query....
I am new to Oracle and was wondering if there is a way to create an email task that could be used to email results of a sql query. My query returns emails addresses that meet a specified criteria. I want to use an email task that takes these addresses as variables and sends out an email to the specified email address.
Anyone provide any help with how I might do this?
Thanks.Hi,
The odiSqlUnload has a "select" command. Is possible, at your process, work with the "LPAD()" and/or "RPAD()" function to complete the necessary whitespace at each column?
To the column heading I suggest you use the "union" like: (I put the lpad and rpad fuctions as example...)
select col1, col2, col3
from(
select 1 as internal_order, 'header_col1' as col1, 'header_col2' as col2, 'header_col3' as col3
from dual
UNION
select 2 as internal_order, RPAD(col1, 10, ' ') as col1 , LPAD(col2, 50, ' ') as col2 , col3
from your_table)
order by internal_order
Do you think this will work for you? -
How to show the VALUE as the Column Header using SQL query?
Hi
I have a requirement to show the picked value as the column header using SQL query.
Example:
======
SELECT EMPNO FROM EMP
WHERE EMPNO=7934;
Result Should be:
7934
7934I have a requirement to show the picked value as the column header using SQL query.In sql*plus you can do
SQL> set verify on
SQL> def e = 7934
old: SELECT empno "&&e" FROM emp WHERE empno = &&e
new: SELECT empno "7934" FROM emp WHERE empno = 7934
SQL> SELECT empno "7934" FROM emp WHERE empno = 7934
7934
7934
1 row selected. -
How to export the result from executing sql statement to excel file ?
HI all,
Great with Oracle SQL Developer, but I have have a trouble as follwing :
I want to export the result from executing sql statement to excel file . I do easily like that in TOAD ,
anyone can help me to do that ? Thanks so much
SigmasvnHello Sue,
I just tried to export to excel with the esdev extension and got java.lang.NumberFormatException. I found the workaround at Re: Windows Multi-language env, - how do I set English for application lang?
open the file sqldeveloper\jdev\bin\sqldeveloper.conf and add the following two lines:
AddVMOption -Duser.language=en
AddVMOption -Duser.country=USyet now my date formats in excel are 'american-style' instead of german. For example 01-DEC-01 so excel does not recognize it as date and therefore I can not simply change the format.
When export to excel will be native to 1.1 perhaps someone can have a look at this 'feature'
Regards
Marcus -
Ability to send the results of a report query to a table in the database
Hi Guys
Is it possible to send the results of a report query to a table in the database ?
ThanksYes.
For this purpose, you can use :
* the delivers advanced option
http://gerardnico.com/wiki/dat/obiee/bi_scheduler/advanced_publication_delivers
* the SOA API
http://gerardnico.com/wiki/dat/obiee/obiee_soap_eclipse
This two solutions need some development skills. -
SQL query automation and output to text file
The bcp utility should handle this task pretty easily for you. The documentation is available here.
I know enough SQL to get me by with the few things I currently do in it (but would always like to know and do more). Anyway, I was just recently asked if I could come up with a way to automate the execution of a SQL query we currently manually run, and then have the results of that query output (instead of to the screen in SSMS) to a text file with the ".dat" extension. I've never automated a SQL query before nor have I had the results output to a file. Can anyone give me some pointers on how to tackle this?
The query currently calls to a stored procedure (which does all the work) and just executes it with some given dates from the query so I'm thinking the output will need to come from the stored procedure (and the code for output to a file added there?)
This topic first appeared in the Spiceworks Community -
SQL insert statement in java with Excel file
Dear all,
I wrote a program is as the follow:
import java.io.*;
import java.sql.*;
public class handleExcel
Connection con = null;
Statement stmnt = null;
public handleExcel()
String excel = "C:\\EGS\\app_files\\info_update_form_exported_data.xls";
try
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String str="jdbc:odbc:DRIVER=Microsoft Excel Driver (*.xls);DBQ=" + excel + ";";
String sql = "insert into [Sheet1$] (Name, Age, Test1, Test2, Test3) values ('mary','16','aa','bb','vv')";
con = DriverManager.getConnection(str, "", "");
stmnt = con.createStatement();
stmnt.executeUpdate(sql);
catch(Exception e)
System.out.println("con is error!!");
e.printStackTrace();
public static void main(String[] args)
handleExcel TestHpc = new handleExcel();
But when I run it, the error is as the follow:
java.sql.SQLException: [Microsoft][ODBC Excel Driver]
at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6958)
at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7115)
at sun.jdbc.odbc.JdbcOdbc.SQLExecDirect(JdbcOdbc.java:3111)
at sun.jdbc.odbc.JdbcOdbcStatement.execute(JdbcOdbcStatement.java:338)
at sun.jdbc.odbc.JdbcOdbcStatement.executeUpdate(JdbcOdbcStatement.java:288)
at hk.gov.edb.util.handleExcel.<init>(handleExcel.java:31)
at hk.gov.edb.util.handleExcel.main(handleExcel.java:97)
Please help me to solve this problem. Thank you so much for your help!
Regards,
kzyoHi
You can use the[b] jakarta POI api in order to read/write Excel file from java. Pure Java, no drivers nedeed.
I tested and ok.
Hope this helps -
After I Update to IOS 7.1 I can't open the excel file attached in my email
After I updated my Iphone 5s from IOS7.0.6 to IOS7.1 when i check my email i can't open excel file attached in my email i check with my frineds phone thy have same issoue
David_PDX wrote:
Hi Alex,
The trick to this whole thing is to scroll to the bottom of the message. There should be a dashed line at the bottom of the email message with text underneath it that says, "This message was downloaded as plain text." Underneath that it should say (in blue hyperlink text) "Download full message". Select that hyperlink, and the Excel file should download completely. You should then be able to select the document and have it open correctly.
I have had the same concern regardless of file format that is sent, so I do not believe your issue is with file format. Hope this helps.
I've seen the same thing happen with images, which it displays in a corrupted form. It's fixed by downloading the full message.
There's a more serious side effect of this, which I've now seen with several types of files. If one FORWARDS the email to someone else, the attached files it sends them are CORRUPTED and unopenable too. In the case of a Word files I looked at, it had dropped the last two bytes of the file.
The workaround for that is to download the full message before forwarding.
I'm seeing this happening with so many types of attachments that I'm assuming it affects them all. Please everyone report this to Apple feedback (http://www.apple.com/feedback/). It's one thing not being able to open a file on your device, it's another to have files corrupted permanently just by forwarding. -
when I send an email with a photoshop file attached, the recipient receives it "flattened". How do I change this?
I've sent psd files to various people without issues, however you might want to try something like www.filedropper.com to make sure it's not that they can't open your version of psd file.
You may also want to zip the file using the built in archiving software, simply right click (or control click) the file and choose Compress ...., then you can email it to the person as a compressed archive. That should preserve all the aspects of the file properly without any modifications. -
What is the best way to insert massive data into an existing excel file?
dear gurus,
i am wondering that what is the best way to insert massive data into an existing excel file, more performance perspective.
the file is read from BDS , and we want to insert data into it .
the way i can think of is
1. OLE AUTOMATION
i think performance will be a big problem
2. Office integration
i am not sure it's facing the same performance issue ?
3 . XXL_SIMPLE_API/FULL_API
I am not sure whether they can insert data into an existing excel file?
could you please give me some advices?
br.
junHi,
If you want to APPEND data( add data to an existing excel file) from SAP, then use GUI_DOWNLOAD fm with APPEND = 'X' paramter.
Best regards,
Prashant
Maybe you are looking for
-
Unable to play video onto my Samsung LCD TV when using a Memorex Mini Soundbar MA5004. Anyone can help?
-
How can I make a PDF with C and M separations only?
-
Export to CSV - order is now by alphabetical column
I was using 1.2, and exporting to CSV, and the file was in table-layout order, so another app is able to import. Now with 1.5 the export is in alphabetical column-name order - and the other app can't handle it. Is there some setting to change the exp
-
POST Connection HTTP ERROR 411 please read
Hi all, using the MIDlet 's code communicating with a SERVLET ( the code can be accessed in the links below) I get a 411 HTTP reply. Any idea why that is happening? The Midlet 's Code: http://www.babyyogurt-piace.it/mambo/content/view/28/2/ The Servl
-
My PM G5 refuses DVD+R DL
Every DVD DL introduiced is immediately ejected by the Superdrive. My PM G5 (bought late 2005) has a Pioneer 117-D. What can I do ? Thanks by advance.