1

I am trying to output the results of a SQL select statement into an e-mail, preferably text. I am using PL/SQL. I already have an e-mail function where I can specify a message body. However, I am not sure the best way to get the SQL select statement results into the message body for an arbitrary number of rows.

As an example, I might want to do select name, data from my_table; and then be able to store this into a VARCHAR2 variable which I can include in an e-mail.

1
  • 1
    Assuming you're sending the email from a PL/SQL procedure already, why is the handing of the variable holding the result any different to the rest of the message body?
    – Alex Poole
    Commented Oct 1, 2015 at 13:37

1 Answer 1

3
declare
    body varchar2(32000) := '';
begin
    for row in (select name, data from my_table) loop
        body := body || ' ' || row.name || ' ' || to_char(row.data) || chr(13)||chr(10) ; /*chr(13)||chr(10) is line feed carriage return*/
    end loop;
    p_email(body);
    exception
        when NO_DATA_FOUND then
            p_email('no data found');
        when others then
            raise;
end;
2
  • Between to_char(row.data) and chr(13) I get the following error: Error(108,69): PLS-00103: Encountered the symbol "CHR" when expecting one of the following: . ( * % & = - + ; < / > at in is mod remainder not rem <an exponent (**)> <> or != or ~= >= <= <> and or like like2 like4 likec between || member submultiset The symbol "." was substituted for "CHR" to continue.
    – Jake
    Commented Oct 1, 2015 at 13:57
  • @JakeWasdin sorry missed one concat (||) operator, now it should work
    – Typo
    Commented Oct 1, 2015 at 14:52

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.