Send lines returned by a query

Hi,
I have this script :
SET SERVEROUT ON
DECLARE
c utl_smtp.connection;
vInHandle utl_file.file_type;
vNewLine VARCHAR2(250);
vMessage VARCHAR2(250);
I pls_integer := 0;
PROCEDURE send_header(name VARCHAR2, header VARCHAR2) AS
BEGIN
utl_smtp.write_data(c,name ||':'|| header || UTL_TCP.CRLF);
END;
BEGIN
select status into vMessage from v$instance;
DBMS_OUTPUT.ENABLE(10000);
DBMS_OUTPUT.PUT_LINE(vMessage);
utl_file.fclose(vInHandle);
-----------------------SEND A MAIL---------------------------
c := utl_smtp.open_connection('ms01xyt3.x-t-y.com',25);
utl_smtp.helo(c, 'ms01xyt3.x-t-y.com');
utl_smtp.mail(c, '[email protected]');
utl_smtp.rcpt(c, '[email protected]');
utl_smtp.open_data(c);
send_header('From', '" xyt" <[email protected]>');
send_header('To', '"Recipient" <[email protected]>');
send_header('Subject', 'DB STATUS ');
utl_smtp.write_data(c, UTL_TCP.CRLF ||vMessage);
utl_smtp.close_data(c);
utl_smtp.quit(c);
EXCEPTION
WHEN utl_smtp.transient_error OR utl_smtp.permanent_error THEN
BEGIN
utl_smtp.quit(c);
EXCEPTION
WHEN utl_smtp.transient_error
OR utl_smtp.permanent_error THEN
NULL;
END;
raise_application_error(-20000, SQLERRM);
END fopen;
It works well and sends vMessage in a mail.
I have another query :
Cursor C_TBS is
Select A.tablespace_name ,
     A.total_size "Taille totale Ko",
     B.Free_space "Espace disponible Ko",
((A.total_size-B.Free_space)*100/A.total_size) "% Occupied Espace "
From
          (select tablespace_name, sum(BYTES)/1024 total_size
          from dba_data_files
          group by tablespace_name) A ,
          (select tablespace_name, sum(BYTES)/1024 Free_space
          from dba_free_space
          group by tablespace_name) B
where a.tablespace_name = b.tablespace_name
AND
((A.total_size-B.Free_space)*100/A.total_size) > 80;
v_line C_TBS%rowtype;
BEGIN
DBMS_OUTPUT.ENABLE(10000);
Open C_TBS;
Loop
Fetch C_TBS into v_line;
EXIT WHEN c_TBS%NOTFOUND;
How can I send v_line in amail ?
Many thanks.

thank you.
SET SERVEROUT ON
DECLARE
c utl_smtp.connection;
  CURSOR C_TBS IS
    SELECT A.tablespace_name ,
           A.total_size "Taille totale Ko",
           B.Free_space "Espace disponible Ko",
           ((A.total_size-B.Free_space)*100/A.total_size) "% Occupied Espace "
    FROM (SELECT tablespace_name, sum(BYTES)/1024 total_size
          FROM   dba_data_files
          GROUP BY tablespace_name) A,
         (SELECT tablespace_name, sum(BYTES)/1024 Free_space
          FROM dba_free_space
          GROUP BY tablespace_name) B
    WHERE a.tablespace_name = b.tablespace_name
    AND   ((A.total_size-B.Free_space)*100/A.total_size) > 80;
BEGIN
  DBMS_OUTPUT.ENABLE(10000);
-----------------------SEND A MAIL---------------------------
c := utl_smtp.open_connection('ms01xyt3.xyt.com',25);
  utl_smtp.helo(c, 'ms01xyt3.xyt.com');
  utl_smtp.mail(c, '[email protected]');
  utl_smtp.rcpt(c, '[email protected]');
  utl_smtp.open_data(c);
  send_header('From', '"AK xyt" <[email protected]>');
  send_header('To', '"Recipient" <[email protected]>');
  send_header('Subject', 'STATUT DE LA BASE ORCL');
FOR v_line IN C_TBS
  Loop
    DBMS_OUTPUT.PUT_LINE('TABLESPACE_NAME is : '||v_line.tablespace_name||' '||v_line."Taille totale Ko"||' '||v_line."Espace disponible Ko");
    utl_smtp.write_data(c, UTL_TCP.CRLF ||v_line);
  End Loop;
  utl_smtp.close_data(c);
  utl_smtp.quit(c);
EXCEPTION
  WHEN utl_smtp.transient_error OR utl_smtp.permanent_error THEN
    BEGIN
      utl_smtp.quit(c);
    EXCEPTION
      WHEN utl_smtp.transient_error OR utl_smtp.permanent_error THEN
        NULL;
    END;
  WHEN OTHERS THEN
    raise_application_error(-20000, SQLERRM);
END;
/ But :
send_header('From', '"AK xyt" <[email protected]>');
RREUR Ó la ligne 25 :
RA-06550: Ligne 25, colonne 3 :
LS-00201: l'identificateur 'SEND_HEADER' must be declared RA-06550: Ligne 25, colonne 3 :
L/SQL: Statement ignored
RA-06550: Ligne 26, colonne 3 :
LS-00201: l'identificateur 'SEND_HEADER' must be declared
RA-06550: Ligne 26, colonne 3 :
L/SQL: Statement ignored
RA-06550: Ligne 27, colonne 3 :
LS-00201: l'identificateur 'SEND_HEADER' must be declared
RA-06550: Ligne 27, colonne 3 :
L/SQL: Statement ignored
RA-06550: Ligne 31, colonne 28 :
LS-00306: numÚro ou types d'arguments erronÚs dans appel Ó '||'
RA-06550: Ligne 31, colonne 5 :
L/SQL: Statement ignoredThank you.

Similar Messages

  • Problem with return a ColdFusion query object from a Java class

    Hi!
    I need to return a ColdFusion query object from a Java class
    using a JDBC result set ( java.sql.ResultSet);
    I have tried to pass my JDBC result set in to the constructor
    of the coldfusion.sql.QueryTable class with this code:
    ColdFusion code
    <cfset pra = createObject("java","QueryUtil").init()>
    <cfset newQuery = CreateObject("java",
    "coldfusion.sql.QueryTable")>
    <cfset newQuery.init( pra.getColdFusionQuery () ) >
    My java class execute a query to db and return QueryTable
    Java code (QueryUtil.java)
    import coldfusion.sql.QueryTable; // (CFusion.jar for class
    QueryTable)
    import com.allaire.cfx //(cfx.jar for class Query used from
    QueryTable)
    public class QueryUtil
    public static coldfusion.sql.QueryTable
    getColdFusionQuery(java.sql.ResultSet rs)
    return new coldfusion.sql.QueryTable(rs);
    but when i run cfm page and coldfusion server tries to
    execute : "<cfset pra =
    createObject("java","QueryUtil").init()>" this error appears:
    Object Instantiation Exception.
    An exception occurred when instantiating a java object. The
    cause of this exception was that: coldfusion/sql/QueryTable.
    If i try to execute QueryUtil.java with Eclipse all it works.
    Also I have tried to return java.sql.ResultSet directly to
    coldfusion.sql.QueryTable.init () with failure.
    Do you know some other solution?

    ok
    i print all my code
    pratica.java execute a query to db and return a querytable
    java class
    import java.util.*;
    import java.sql.*;
    import coldfusion.sql.*;
    public class Pratica {
    private HashMap my;
    private String URI,LOGIN,PWD,DRIVER;
    private Connection conn=null;
    //funzione init
    //riceve due strutture converite in hashmap
    // globals
    // dbprop
    public Pratica(HashMap globals,HashMap dbprop) {
    my = new HashMap();
    my.put("GLOBALS",globals);
    my.put("DBPROP",dbprop);
    URI = "jdbc:sqlserver://it-bra-s0016;databaseName=nmobl";
    LOGIN = "usr_dev";
    PWD = "developer";
    DRIVER = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
    try{
    // Carico il driver JDBC per la connessione con il database
    MySQL
    Class.forName(DRIVER);
    /* Connessione alla base di dati */
    conn=DriverManager.getConnection(URI,LOGIN,PWD);
    if(conn!=null) System.out.println("Connection Successful!");
    } catch (ClassNotFoundException e) {
    // Could not find the database driver
    System.out.print("\ndriver non trovato "+e.getMessage());
    System.out.flush();
    catch (SQLException e) {
    // Could not connect to the database
    System.out.print("\nConnessione fallita "+e.getMessage());
    System.out.flush();
    //funzione search
    //riceve un hash map con i filtri di ricerca
    public QueryTable search(/*HashMap arg*/) {
    ResultSet rs=null;
    Statement stmt=null;
    QueryTable ret=null;
    String query="SELECT * FROM TAN100pratiche";
    try{
    stmt = conn.createStatement();// Creo lo Statement per
    l'esecuzione della query
    rs=stmt.executeQuery(query);
    // while (rs.next()) {
    // System.out.println(rs.getString("descrizione"));
    catch (Exception e) {
    e.printStackTrace();
    try {
    ret = Pratica.RsToQueryTable(rs);
    } catch (SQLException e) {
    e.printStackTrace();
    this.close();
    return(ret);
    // ret=this.RsToQuery(rs);
    // this.close(); //chiude le connessioni,recordset e
    statament
    //retstruct CF vede HashMap come struct
    //METODO DI TEST
    public HashMap retstruct(){
    return(my);
    //conversione resultset to querytable
    private static QueryTable RsToQueryTable(ResultSet rs)
    throws SQLException{
    return new QueryTable(rs);
    //chiura resultset statament e connessione
    private void close(){
    try{
    conn.close();
    conn=null;
    catch (Exception e) {
    e.printStackTrace();
    coldfusion code
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01
    Transitional//EN">
    <html>
    <head>
    <title>Test JDBC CFML Using CFScript</title>
    </head>
    <body>
    <cftry>
    <cfset glb_map =
    createObject("java","java.util.HashMap")>
    <cfset dbprop_map =
    createObject("java","java.util.HashMap")>
    <cfset glb_map.init(glb)> <!---are passed from
    another page--->
    <cfset dbprop_map.init(glb["DBPROP"])>
    <cfset pra =
    createObject("java","Pratica").init(glb_map,dbprop_map)>
    <cfset ourQuery
    =createObject("java","coldfusion.sql.QueryTable").init(pra.search())>
    <cfcatch>
    <h2>Error - info below</h2>
    <cfdump var="#cfcatch#"><cfabort>
    </cfcatch>
    </cftry>
    <h2>Success - statement dumped below</h2>
    <cfdump var="#ourQuery#">
    </body>
    </html>
    error at line <cfset pra =
    createObject("java","Pratica").init(glb_map,dbprop_map)>
    An exception occurred when instantiating a java object. The
    cause of this exception was that: coldfusion/sql/QueryTable.
    -----------------------------------------------------------------------

  • Modify amount of space after line return

    hi
    I'm creating a html email (using a table and a new inline style each time i insert text, as advised)
    However, this query may apply to any form of html produced in dreamweaver:
    Can I set and modify the amount of space inserted after a line return?
    I know shift+return gives standard space but I'd like to ideally insert a slightly bigger space than this (although not as big a full "return" gives)
    Surely this must be possible?
    All help appreciated
    Tom

    Hi Tom,
    Hitting the enter key gives you a paragraph tag <p>  </p>
    Paragraphs have a default margin so you need to change that margin.To change/adjust the margin on all paragraphs on your page use css.
    Add it to the head of the page between style tags or to an external stylesheet:
    p {margin: 5px 0 0;}
    The above sets margin 5 pixels top 0 pixels right/left 0 pixels bottom. Adjust as per your need.
    Thanks
    Bhawna

  • Number of lines of a select query

    I want only the number of lines from a result of a select query.
    How can i get this?
    Greetings Volker

    Hi Volkar,
    When you extract the data from Database into an internal table, use the DESCRIBE TABLE syntax for fetching the number of lines returned.
    Syntax :
    DESCRIBE TABLE ITAB lines l_lines.
    where l_lines is the no. of lines returned.
    Hope this will resolve your query.
    Reward all the helpful answers.
    Regards
    Nagaraj T

  • Filtering users based on return of past query

    Greetings!
    We have a Users table with over 3 million user records in it (like a data warehouse). The requirement is to execute 2 queries on the Users table, where the return of the second query should not have any users that were returned in the first query.
    For e.g. Consider a sweepstake user-list, where you want to send flyers to people, notifying them about prizes, but do not want to send two flyers to the same person, even if he fulfills the selection criteria for both the sweepstakes.
    So -
    Query.1. has conditions, which state: All Users from New York, with age=25 (independently run, returns 500,000 users)
    Query.2. has conditions, which state: All Users of age=25 (independently run, returns 700,000 users)
    Expected Output:
    Query 1 should return 500,000
    Query 2 should return 700,000 MINUS those users that were already returned in Query 1. i.e. Only return all users of age 25, but who are not from New York
    Any inputs will be much appreciated!
    Thanks,

    Given that you know that the first query uses state = NY and age = 25, why can't you do the second query as:
    SELECT * FROM table
    WHERE age = 25 and
          state <> 'NY'John

  • Text lines in the BW query variables screen

    Hi gurus.
    The bw users ask me to display some text lines in the BW query variables prompt.
    The text lines are saved in a custom table.
    The only idea that I've got is to use customer exit text variables and fill them in CMOD when I_step = 1.
    I don't like this solution (I should have more the 10 text lines and so I have to mantain more than 10 Text variables) but I can't find any other solution.
    Any new idea or solution?
    Is there in Bex enviroment a functionality (that I don't know) for doing somenthing like this ?
    Thanks fo any help.
    S.

    Hi,
    to resolve it you should create all the prompts in the BW query. You are using a query with 2 parameters and then a dynamic list of values. the dynamic list of values can only work after you entered the other values.
    Ingo

  • How to get number of rows return in SELECT query

    i'm very new in java, i have a question:
    - How to get number of rows return in SELECT query?
    (i use SQL Server 2000 Driver for JDBC and everything are done, i only want to know problems above)
    Thanks.

    make the result set scroll insensitve, do rs.last(), get the row num, and call rs.beforeFirst(), then you can process the result set like you currently do.
             String sql = "select * from testing";
             PreparedStatement ps =
              con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
             ResultSet rs = ps.executeQuery();
             rs.last();
             System.out.println("Row count = " + rs.getRow());
             rs.beforeFirst();~Tim
    NOTE: Ugly, but does the trick.

  • How to restrict number of rows returned in a query

    Hi frnds,
    I'd like to restrict number of rows returned by my query to some 10 rows. how to do that.When I try doing with the rownum<10 its giving results for a particular dept and that too some 6 rows only...btw I'm grouping my table and includes joins from many a table and am ordering the table results by a column.. How to do this..

    776317 wrote:
    Hi frnds,
    I'd like to restrict number of rows returned by my query to some 10 rows. how to do that.When I try doing with the rownum<10 its giving results for a particular dept and that too some 6 rows only...btw I'm grouping my table and includes joins from many a table and am ordering the table results by a column.. How to do this..
    TELL ME HOW MANY ROWS YOU HAVE IN TABLE?
    Because you have only *6 rows* in you column, if you less than 10 rows then it displays only containied/exist rows. nothing much
    select ename,empno from emp where rownum < 10;Thanks

  • Sender jdbc adapter - no update query

    hi ,
    i am using pi 731 single stack.
    the scenario is - PI has to pick data from view of a hana database. i am using jdbc sender for it.
    pi will not have access to update the table,only pi can read the view of database.So,PI can't use UPDATE query.
    If in jdbc sender channel ,I use SELECT query only and no UPDATE query - will it work ? what will happen if there are 100 records in the view and PI failed after fetching 43 records..will it pick from 44th record next time OR it will start from 0 again ?
    rgds

    Hi SAP PI,
    It has no sense to use the sender JDBC without update query because then always will be taken the same records.
    If you cant update the source DB you only have the choice to talk with the DB administrators that they develop for you a stored procedure that it has to do the work to get different records in every PI access.
    If the PI record process fail with impossible source database update update, the only way (afaik) is to do a PI alert and to communicate it to db sender administrators. There are another option like to store the data in a intermediate table, and so on but all possibilities that i can think now are not to enough good.
    Regards.

  • Sending line No. 370 or 1280 Failed!

    This printer is a Brother HL-5140 Series laser printer attached to a Windows server. I have had no problems with this setup but yesterday whilst sending a print job to the printer I encountered the following error 'Sending line No. 370 Failed!' also 'Sending line No. 1280 Failed!'
    Windows machines can print and so can my Mac mini running OS X 10.4 Tiger.
    Any advise?

    Problem seemed to vanish. Perhaps an apple up-date solved this problem.

  • JTextPane and RTF line returns

    I'm wondering is there anyway to use a line return with JTextPane's? I'm not sure if thats what they're called but what i'm talking about is the RTF equivelent of <BR>. I tried importing a file with line returns and none of they were treated as a space. I also tried typing shift-enter like in word, but that didn't do anything. Is it possible to use line returns with a jtextpane? or is that just something you have to do without?

    Okay here's my code:
         coursetext = new JTextPane();
         coursetext.setContentType("text/RTF");
         RTFEditorKit edkit = new RTFEditorKit();
         coursetext.setEditorKit(edkit);
    and later on:
         RTFEditorKit edkit = new RTFEditorKit();
         File file = new File("gn.rtf");
         try {
              FileInputStream fr = new FileInputStream(file);     
              DefaultStyledDocument doc = new DefaultStyledDocument();
              edkit.read(fr,doc, 0);
              coursetext.setStyledDocument(doc);
    The file i'm loading is saved as an RTF file from Wordpad. If i try to load a rtf file saved from MS Word (2003) it gives me a null pointer exception.

  • When I send an email, a photo appears after my name in the sender line. How do I get rid of it?

    When I send an email, a photo appears after my name in the sender line. How do I get rid of it?

    I don't have a signature set up, but did a little research.  Someone posted that these will show up when I send an email to myself, but will not show up when sent to another person.  I sent a test email to a friend to check for sure.

  • "No results were returned by the query" exception

    Hi,
    im using postgreSql (7.2) as a backend and JDBC3 (from http://jdbc.postgresql.org/).
    im getting the exception, "No results were returned by the query" whenever i try to do an insert. the weird thing is that insert works and i can see a record in the database, but i still get this exception and i can't do anything.
    Java: 1.4.0
    thanks a lot

    you should use executeUpdate for queries that do not return result sets. that would include insert, update and delete.
    i didn't know that, that would cause a problem with postgreSql jdbc. im use to of Oracle and i never got these problems with Oracle
    this is not a problem with postgres it is a problem with your lack of understanding the API and the Oracle driver if it let's you do this is wrong.
    the API clearly states that is you try and execute a SQL statement that does not produce a ResultSet with executeQuery then a SQLException should be thrown.
    so again the postgres driver is correct you and the oracle driver are wrong.

  • Is it possible to count the rows returned from a query?

    Hello,
    When using JDBC is there anyway of finding out the number of
    rows returned from a query before actually getting each row?
    In Forms 4.5 you can use the count_query function, does anyone
    know of an equivalent function or work around in JDBC and/or
    SQLJ?
    Thanks.
    null

    Pasi Hmlinen (guest) wrote:
    : Try
    : SELECT COUNT(*) FROM the_table WHERE <conditions>;
    : Hope this helps,
    : Pasi
    Thanks for the advice, I'm currently using SELECT COUNT(*) but
    I'm looking for a more efficient way of doing it. If I SELECT
    COUNT each time then I have to prepare and execute a SQL
    statement each time. What I want to do it execute a single SQL
    statement to return my results and somehow find out the number
    of rows in the resultset without having to go back to the
    database.
    Gethin.
    null

  • How to count no of records returned from a query?

    Hello,
    I need to find out how many records displayed from a query without writing any other queries.
    i mean that.
    I have a query such as:
    query = "select * from users";
    and the resultset for it is rs.
    and i need to display how many records fetched from this query without using any other query such as "select count(user_id) from users" etc.
    Is there any function ?

    No, unfortunately there is no method or property that will tell you how many rows have been returned by a query.
    People use many different techniques.
    1.The simplest would be, keep incrementing a counter in while ( rs.next() ) and at the end you'll have the count. But only at the end, after the loop.
    2. Run another query with count(*) just to fetch the count.
    3. Run the same query twice, once for counting and then again for printing out. Very dumb idea though, might as well do 2. suggested above.
    4. If you have a scrollable resultset, you could go to the lastRecord and then getRow number and hence know how many there are and then rewind the resultset. I don't know how advisable using scrollable resultsets is.
    5. Create a slightly clumsy query like : select count(*) as "totalcount", emp_id, emp_name, emp_email, emp_phone from employees group by emp_id, emp_name, emp_email, emp_phone. You'll need to use the group by clause since count() is an aggregate function and you can't mix aggregate functions and columns unless you add the group by to all the columns you're fetching.

Maybe you are looking for

  • Can't see my objects, what grants do I need?

    Hi, I created a user and granted resource but also needed create session... I created a bunch of tables, seq, etc... Verified all objects existed and the owner was my new user: select OWNER, OBJECT_NAME from all_objects Tried to connect from Visio an

  • Best Practice for UPK implementation

    We will start using UPK tool in our Oracle E-Business Suite (11.5.10) environment soon. We are in a process of configuring the tool and making a standard template for training documents. For example, which screen resolution? which font size and color

  • Purchase order Creation Problem

    Dear All               For Local purchase NB order creation SAP Asking the Account assignement category. for only particular plant ,It should ask only Service orders. but why its asking the NB orders.      Even Valuation grouping code already assigne

  • MIR7 after used activety

    Hi, MIR7 posting use for Document parking after pass the mir7 when it post finally in purchase reg reflect two entry for same GRN with tax but vendors account it post one time. how to process atual document after mir7 posting? pls help and guildline.

  • Palletizing Material & Scanning Box Label Or Pallet Label Using HU OR SU

    Hello dear WM and MM experts, I'm looking at two scenarios here: A) If a company is trying to track box-level information (unique box number and LB per box), and pallet-level information as well (unique pallet number and total LB of all boxes in a pa