Welcome to dbFreaks.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Trying to export to a text file using PL/SQL

 
   Database Help (Home) -> Oracle RSS
Next:  sp_replwritetovarbin memory overwrite Security th..  
Author Message
sajrizvi80

External


Since: Dec 11, 2008
Posts: 1



(Msg. 1) Posted: Thu Dec 11, 2008 6:20 am
Post subject: Trying to export to a text file using PL/SQL
Archived from groups: comp>databases>oracle>misc (more info?)

Hi I have the following query and I need the output to be in the form
of an attachment (text or csv) instead of being in the body of the
email. I am relatively new to PL/SQL and hitting a wall trying to get
this done. I really appreciate your help in looking into this. Thanks

CREATE OR REPLACE PROCEDURE SP_TEST as


--Declare all the variables
v_startdate DATE;
v_enddate DATE;
k NUMBER;


TYPE quest_type IS RECORD (
qcount NUMBER,
qtxt VARCHAR2(1000)
);

TYPE quest_tab IS TABLE OF quest_type
INDEX BY BINARY_INTEGER;

t_quest quest_tab;

-------------------------
CURSOR cur_1 IS

SELECT qtxt,
qcount
FROM
(
SELECT /*+ parallel(A,4)*/
SUM(A.QCNT) AS qcount,
LOWER(TRIM(A.QTEXT)) AS qtxt
FROM Xtable A
WHERE A.DT >= v_startdate
AND A.DT < v_enddate + 1
GROUP BY LOWER(TRIM(A.XX))
ORDER BY SUM(A.XXXX) DESC
)
WHERE ROWNUM < 50;




--------------------------------------------------------------------------------------------

BEGIN

FOR i in 1..7 LOOP
IF TRIM(UPPER(TO_CHAR(NEW_TIME(SYSDATE, 'PST','GMT')-
i ,'DAY'))) LIKE 'MONDAY%' THEN
v_enddate := TRUNC(NEW_TIME(SYSDATE, 'PST','GMT'))-i;
v_startdate:= v_enddate - 6;
END IF;
END LOOP;



ajutl.smtp_file.clear_buffer;
ajutl.smtp_file.add_to(' ');

ajutl.smtp_file.set_subject('TITLE ' || v_startdate || ' - ' ||
v_enddate);

k := 0;

ajutl.smtp_file.add_text('Num'||CHR(9)||'Query Text');

FOR i IN cur_1 LOOP

k := k + 1;

t_quest(k).qcount := i.qcount;
t_quest(k).qtxt := i.qtxt;

ajutl.smtp_file.add_text(t_quest(k).qcount||CHR(9)||t_quest
(k).qtxt);

END LOOP;

ajutl.smtp_file.send;

COMMIT;

END;

 >> Stay informed about: Trying to export to a text file using PL/SQL 
Back to top
Login to vote
DA Morgan

External


Since: Dec 14, 2007
Posts: 757



(Msg. 2) Posted: Thu Dec 11, 2008 9:23 am
Post subject: Re: Trying to export to a text file using PL/SQL [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

wrote:
> Hi I have the following query and I need the output to be in the form
> of an attachment (text or csv) instead of being in the body of the
> email. I am relatively new to PL/SQL and hitting a wall trying to get
> this done. I really appreciate your help in looking into this. Thanks
>
> CREATE OR REPLACE PROCEDURE SP_TEST as
>
>
> --Declare all the variables
> v_startdate DATE;
> v_enddate DATE;
> k NUMBER;
>
>
> TYPE quest_type IS RECORD (
> qcount NUMBER,
> qtxt VARCHAR2(1000)
> );
>
> TYPE quest_tab IS TABLE OF quest_type
> INDEX BY BINARY_INTEGER;
>
> t_quest quest_tab;
>
> -------------------------
> CURSOR cur_1 IS
>
> SELECT qtxt,
> qcount
> FROM
> (
> SELECT /*+ parallel(A,4)*/
> SUM(A.QCNT) AS qcount,
> LOWER(TRIM(A.QTEXT)) AS qtxt
> FROM Xtable A
> WHERE A.DT >= v_startdate
> AND A.DT < v_enddate + 1
> GROUP BY LOWER(TRIM(A.XX))
> ORDER BY SUM(A.XXXX) DESC
> )
> WHERE ROWNUM < 50;
>
>
>
>
> --------------------------------------------------------------------------------------------
>
> BEGIN
>
> FOR i in 1..7 LOOP
> IF TRIM(UPPER(TO_CHAR(NEW_TIME(SYSDATE, 'PST','GMT')-
> i ,'DAY'))) LIKE 'MONDAY%' THEN
> v_enddate := TRUNC(NEW_TIME(SYSDATE, 'PST','GMT'))-i;
> v_startdate:= v_enddate - 6;
> END IF;
> END LOOP;
>
>
>
> ajutl.smtp_file.clear_buffer;
> ajutl.smtp_file.add_to(' ');
>
> ajutl.smtp_file.set_subject('TITLE ' || v_startdate || ' - ' ||
> v_enddate);
>
> k := 0;
>
> ajutl.smtp_file.add_text('Num'||CHR(9)||'Query Text');
>
> FOR i IN cur_1 LOOP
>
> k := k + 1;
>
> t_quest(k).qcount := i.qcount;
> t_quest(k).qtxt := i.qtxt;
>
> ajutl.smtp_file.add_text(t_quest(k).qcount||CHR(9)||t_quest
> (k).qtxt);
>
> END LOOP;
>
> ajutl.smtp_file.send;
>
> COMMIT;
>
> END;

What is this?
ajutl.smtp_file.clear_buffer;
where did it come from?
In what version of Oracle?

Assuming a currently supported version of the product I would
suggest you look into UTL_FILE and UTL_MAIL.
http://www.psoug.org/reference/utl_file.html
http://www.psoug.org/reference/utl_mail.html
--
Daniel A. Morgan
Oracle Ace Director & Instructor
University of Washington
damorgan.RemoveThis@x.washington.edu (replace x with u to respond)
Puget Sound Oracle Users Group
www.psoug.org

 >> Stay informed about: Trying to export to a text file using PL/SQL 
Back to top
Login to vote
Josh

External


Since: Dec 15, 2008
Posts: 1



(Msg. 3) Posted: Mon Dec 15, 2008 4:22 am
Post subject: Re: Trying to export to a text file using PL/SQL [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Dec 11, 5:23 pm, DA Morgan wrote:
> wrote:
> > Hi I have the following query and I need the output to be in the form
> > of an attachment (text or csv) instead of being in the body of the
> > email. I am relatively new to PL/SQL and hitting a wall trying to get
> > this done. I really appreciate your help in looking into this. Thanks
>
> > CREATE OR REPLACE PROCEDURE  SP_TEST as
>
> > --Declare all the variables
> > v_startdate     DATE;
> > v_enddate       DATE;
> > k               NUMBER;
>
> > TYPE quest_type IS RECORD (
> >     qcount  NUMBER,
> >     qtxt    VARCHAR2(1000)
> > );
>
> > TYPE quest_tab IS TABLE OF quest_type
> > INDEX BY BINARY_INTEGER;
>
> > t_quest quest_tab;
>
> > -------------------------
> > CURSOR cur_1 IS
>
> > SELECT  qtxt,
> >         qcount
> > FROM
> > (
> > SELECT  /*+ parallel(A,4)*/
> >         SUM(A.QCNT) AS qcount,
> >         LOWER(TRIM(A.QTEXT)) AS qtxt
> > FROM    Xtable A
> > WHERE   A.DT >= v_startdate
> > AND     A.DT < v_enddate + 1
> > GROUP   BY LOWER(TRIM(A.XX))
> > ORDER   BY SUM(A.XXXX) DESC
> > )
> > WHERE ROWNUM < 50;
>
> > --------------------------------------------------------------------------------------------
>
> > BEGIN
>
> >     FOR i in 1..7 LOOP
> >         IF TRIM(UPPER(TO_CHAR(NEW_TIME(SYSDATE, 'PST','GMT')-
> > i ,'DAY')))  LIKE 'MONDAY%' THEN
> >             v_enddate := TRUNC(NEW_TIME(SYSDATE, 'PST','GMT'))-i;
> >             v_startdate:= v_enddate - 6;
> >         END IF;
> >     END LOOP;
>
> >     ajutl.smtp_file.clear_buffer;
> >     ajutl.smtp_file.add_to(' ');
>
> >     ajutl.smtp_file.set_subject('TITLE ' || v_startdate || ' - ' ||
> > v_enddate);
>
> >     k := 0;
>
> >     ajutl.smtp_file.add_text('Num'||CHR(9)||'Query Text');
>
> >     FOR i IN cur_1 LOOP
>
> >         k := k + 1;
>
> >         t_quest(k).qcount   := i.qcount;
> >         t_quest(k).qtxt     := i.qtxt;
>
> >         ajutl.smtp_file.add_text(t_quest(k).qcount||CHR(9)||t_quest
> > (k).qtxt);
>
> >     END LOOP;
>
> >     ajutl.smtp_file.send;
>
> >     COMMIT;
>
> > END;
>
> What is this?
> ajutl.smtp_file.clear_buffer;
> where did it come from?
> In what version of Oracle?
>
> Assuming a currently supported version of the product I would
> suggest you look into UTL_FILE and UTL_MAIL.http://www.psoug.org/reference/utl_file.htmlhttp://www.psoug.org/reference/utl_mail.html
> --
> Daniel A. Morgan
> Oracle Ace Director & Instructor
> University of Washington
> damor... DeleteThis @x.washington.edu (replace x with u to respond)
> Puget Sound Oracle Users Groupwww.psoug.org

Thanks Daniel. This is of great help.
 >> Stay informed about: Trying to export to a text file using PL/SQL 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
how to export public synonyms from one to another oracle d.. - I need to export public synonyms from one to another oracle database. Since public synonyms are logical objects and owner 'PUBLIC' is also logical a can't export those owner through exp/imp utility.. example exp system/manager@pro.proliant from use...

How to Export Database into csv files - What is the best way to export any of the following: 1. Whole Schema, or 2. All Tables with Row Header information, or 3 Individual tables with Header row information I opened up access and exported all of my tables into csv files, but it did not..

order by text - Hi, I have a variable field of type varchar2 called storeId. I need to sort the store Id's but they are of variable length and some of them contain characters and digits while others contain only digits. I tried using order by lpad(storeId, 10) asc bu...

Text search - Hi * following situation a table with a column ID varchar2(4000) I want to search with an ID-Range like select * from table where id between '12' and '1234AABBG' Does this work and what about NLS- dependent information ? Thanx for your help Ralph

Assigning text in an OCIString - I've tried the sample code of Oracle's documentation. I had to make small changes, since the initial code does not compile... Unfortunately, the final code compiles, but does not work. The OCIString pointer points to a NULL string. Coul you tell me what....
   Database Help (Home) -> Oracle All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]