[code=oracle]
CREATE OR REPLACE procedure TEST_EMAIL(errb uf OUT VARCHAR2,
retcode OUT VARCHAR2,
p_from_date date,
p_to_date date,
P_CANDIDATE_NAM E VARCHAR2) as
x_manager_name1 assignment.mana ger_name%type;
x_EMAIL_ADDRESS candidate.EMAIL _ADDRESS%type;
x_candidate_nam e1 assignment.cand idate_name%TYPE ;
x_customer_name 1 assignment.cust omer_name%TYPE;
x_manager_name assignment.mana ger_name%TYPE;
x_time_sheet_id tps_time_sheet_ master.time_she et_id%TYPE;
x_assignment_id 1 assignment.assi gnment_id%TYPE;
x_fromdate DATE;
x_todate DATE;
x_cdate date;
x_bh NUMBER;
m1 date;
m2 date;
v_date date;
V1 VARCHAR2(20000) ;
V2 VARCHAR2(20000) ;
V3 VARCHAR2(20000) ;
v4 VARCHAR2(20000) ;
v5 VARCHAR2(20000) ;
v6 varchar2(20000) ;
v7 varchar2(20000) ;
v8 varchar2(20000) ;
v9 varchar2(20000) ;
v10 varchar2(20000) ;
x_mail varchar2(20000) ;
v11 varchar2(20000) ;
v12 varchar2(20000) ;
v13 varchar2(20000) ;
v14 varchar2(20000) ;
v15 varchar2(20000) ;
v16 varchar2(20000) ;
v17 varchar2(20000) ;
v18 varchar2(20000) ;
cursor c_top is
sELECT a.candidate_nam e, a.customer_name , a.manager_name,
b.time_sheet_id , a.assignment_id , b.from_date, b.TO_DATE,
SUM (c.billable_hou rs),e.EMAIL_ADD RESS
FROM assignment a, tps_time_sheet_ master b,
tps_time_sheet_ detail c,
candidate E
WHERE a.assignment_id = b.assignment_id
AND b.time_sheet_id = c.time_sheet_id
and a.candidate_id= E.candidate_id
--AND a.assignment_id = p_assignment_id
AND a.candidate_nam e = NVL (p_candidate_na me, a.candidate_nam e)
AND calendar_date BETWEEN p_from_date AND p_to_date
GROUP BY a.candidate_nam e,
a.customer_name ,
a.manager_name,
b.time_sheet_id ,
b.from_date,
b.TO_DATE,
a.assignment_id ,
e.EMAIL_ADDRESS
ORDER BY assignment_id;
CURSOR c_main(p_assign ment_id1 number)
IS
SELECT a.candidate_nam e, a.customer_name , a.manager_name,
b.time_sheet_id , a.assignment_id , b.from_date, b.TO_DATE,
SUM (c.billable_hou rs)
FROM assignment a, tps_time_sheet_ master b,
tps_time_sheet_ detail c
WHERE a.assignment_id = b.assignment_id
AND b.time_sheet_id = c.time_sheet_id
----and a.candidate_id= E.candidate_id
AND a.assignment_id = p_assignment_id 1
AND a.candidate_nam e = NVL (p_candidate_na me, a.candidate_nam e)
AND calendar_date BETWEEN p_from_date AND p_to_date
GROUP BY a.candidate_nam e,
a.customer_name ,
a.manager_name,
b.time_sheet_id ,
b.from_date,
b.TO_DATE,
a.assignment_id
ORDER BY assignment_id;
CURSOR c2 (p_assignment_i d NUMBER)
IS
SELECT MAX (b.mdate), MIN (b.mdate)
FROM (SELECT mdate
FROM xxmissing_time_ date
WHERE mdate BETWEEN p_from_date AND p_to_date
AND aid = p_assignment_id ) b;
x_rec c_main%rowtype;
BEGIN
select sysdate into v_date from dual;
OPEN c_top;
v1:='During last week your time sheet(s) has (have) been received and entered into the system ';
v2:='as follows:';
v8:='Please note that we not received time sheet(s) for periods mention below:';
v9:='Also note that payroll is processed every alternate Tuesday.Please ensure that your time';
v10:='Sheet reaches us at least 24 hours prior to payroll processing in order to processing in order';
v11:='to process an accurate and timely payroll.';
v12:='In case of any discrepancy/clarification.p lease send an email to';
v18:='Date:'||v _date;
v15:='';
v16:='';
v14:=v9||v10||v 11||chr(10)||v1 5||chr(10)||v16 ||chr(10)||v12| |chr(10)||''||c hr(10)||v13||ch r(10)||' '||chr(10)||v18 ;
v3:=v1||''||v2;
LOOP
FETCH c_top
INTO x_candidate_nam e1, x_customer_name 1, x_manager_name,
x_time_sheet_id , x_assignment_id 1, x_fromdate, x_todate, x_bh,x_EMAIL_AD DRESS;
x_mail:=x_EMAIL _ADDRESS;
EXIT WHEN c_top%NOTFOUND;
begin
open c_main( x_assignment_id 1);
loop
fetch c_main
INTO x_candidate_nam e1, x_customer_name 1, x_manager_name,
x_time_sheet_id , x_assignment_id 1, x_fromdate, x_todate, x_bh;
v4 := 'Candidate Name:'||x_candi date_name1;
v15:= 'Customer Name:'||x_custo mer_name1;
v16:= 'Manager Name:'||x_manag er_name;
v17:=x_fromdate ;
v5:=rpad('AID', 15)||rpad('from date',15)||rpad ('to date',15)||rpad ('billable hours',15);
v6:=rpad(x_assi gnment_id1,15)| |rpad(x_fromdat e,15)||rpad(x_t odate,15)||rpad (x_bh,15);
/*v7:=v3||chr(10 )||'||chr(10)|| v4||chr(10)||'' ||chr(10)||v15| |chr(10)||' '||chr(10)||v16 ||chr(10)||''|| chr(10)||v5||ch r(10)||v17;*/
exit when c_main%notfound ;
end loop;
CLOSE c_main;
end;
BEGIN
OPEN c2 (x_assignment_i d1);
LOOP
FETCH c2
INTO m1, m2;
v9:=rpad(' ',15)||rpad('fr om date',15)||rpad ('to date',15);
v10:=rpad(' ',15)||rpad(m2, 15)||rpad(m1,15 );
v7:=v3||chr(10) ||''||chr(10)|| v4||chr(10)||'' ||chr(10)||v15| |chr(10)||' '||chr(10)||v16 ||chr(10)||''|| chr(10)||''||v5 ||chr(10)||''|| chr(10)||''||ch r(10)||v6||chr( 10)||''||chr(10 )||v8||chr(10)| |v9||chr(10)||v 10||chr(10)||v1 4;
EXIT WHEN c2%NOTFOUND;
END LOOP;
CLOSE c2;
END;
END LOOP;
MAILOUT
('x.com',
'x.co.in',
'x@gmail.com',
'Test Mail',
V7);
CLOSE c_top;
COMMIT;
END;
/
[/code]
I am using this pl/sql code to send email.BY using this code mail goes to particular person.but c_main cursor not able to fetch more than one record.and
in databse there is more than one record.
the output like this
During last week your time sheet(s) has (have) been received and entered into the
system as follows:
Candidate Name:
Customer Name:Citigroup Global Markets Inc.
Manager Name:
AID from date to date billable hours
203 07-JAN-08 13-JAN-08 40
Please note that we not received time sheet(s) for periods mention below:
from date to date
Also note that payroll is processed every alternate Tuesday.Please ensure that your
timeSheet reaches us at least 24 hours prior to payroll processing in order to
processing in orderto process an accurate and timely payroll.
In case of any discrepancy/clarification.p lease send an email to x.com
Corporation
Date:23-MAR-08
i am not able to fetch more than one aid,fromdate,to date
so can u suggest me how to modified this query.
CREATE OR REPLACE procedure TEST_EMAIL(errb uf OUT VARCHAR2,
retcode OUT VARCHAR2,
p_from_date date,
p_to_date date,
P_CANDIDATE_NAM E VARCHAR2) as
x_manager_name1 assignment.mana ger_name%type;
x_EMAIL_ADDRESS candidate.EMAIL _ADDRESS%type;
x_candidate_nam e1 assignment.cand idate_name%TYPE ;
x_customer_name 1 assignment.cust omer_name%TYPE;
x_manager_name assignment.mana ger_name%TYPE;
x_time_sheet_id tps_time_sheet_ master.time_she et_id%TYPE;
x_assignment_id 1 assignment.assi gnment_id%TYPE;
x_fromdate DATE;
x_todate DATE;
x_cdate date;
x_bh NUMBER;
m1 date;
m2 date;
v_date date;
V1 VARCHAR2(20000) ;
V2 VARCHAR2(20000) ;
V3 VARCHAR2(20000) ;
v4 VARCHAR2(20000) ;
v5 VARCHAR2(20000) ;
v6 varchar2(20000) ;
v7 varchar2(20000) ;
v8 varchar2(20000) ;
v9 varchar2(20000) ;
v10 varchar2(20000) ;
x_mail varchar2(20000) ;
v11 varchar2(20000) ;
v12 varchar2(20000) ;
v13 varchar2(20000) ;
v14 varchar2(20000) ;
v15 varchar2(20000) ;
v16 varchar2(20000) ;
v17 varchar2(20000) ;
v18 varchar2(20000) ;
cursor c_top is
sELECT a.candidate_nam e, a.customer_name , a.manager_name,
b.time_sheet_id , a.assignment_id , b.from_date, b.TO_DATE,
SUM (c.billable_hou rs),e.EMAIL_ADD RESS
FROM assignment a, tps_time_sheet_ master b,
tps_time_sheet_ detail c,
candidate E
WHERE a.assignment_id = b.assignment_id
AND b.time_sheet_id = c.time_sheet_id
and a.candidate_id= E.candidate_id
--AND a.assignment_id = p_assignment_id
AND a.candidate_nam e = NVL (p_candidate_na me, a.candidate_nam e)
AND calendar_date BETWEEN p_from_date AND p_to_date
GROUP BY a.candidate_nam e,
a.customer_name ,
a.manager_name,
b.time_sheet_id ,
b.from_date,
b.TO_DATE,
a.assignment_id ,
e.EMAIL_ADDRESS
ORDER BY assignment_id;
CURSOR c_main(p_assign ment_id1 number)
IS
SELECT a.candidate_nam e, a.customer_name , a.manager_name,
b.time_sheet_id , a.assignment_id , b.from_date, b.TO_DATE,
SUM (c.billable_hou rs)
FROM assignment a, tps_time_sheet_ master b,
tps_time_sheet_ detail c
WHERE a.assignment_id = b.assignment_id
AND b.time_sheet_id = c.time_sheet_id
----and a.candidate_id= E.candidate_id
AND a.assignment_id = p_assignment_id 1
AND a.candidate_nam e = NVL (p_candidate_na me, a.candidate_nam e)
AND calendar_date BETWEEN p_from_date AND p_to_date
GROUP BY a.candidate_nam e,
a.customer_name ,
a.manager_name,
b.time_sheet_id ,
b.from_date,
b.TO_DATE,
a.assignment_id
ORDER BY assignment_id;
CURSOR c2 (p_assignment_i d NUMBER)
IS
SELECT MAX (b.mdate), MIN (b.mdate)
FROM (SELECT mdate
FROM xxmissing_time_ date
WHERE mdate BETWEEN p_from_date AND p_to_date
AND aid = p_assignment_id ) b;
x_rec c_main%rowtype;
BEGIN
select sysdate into v_date from dual;
OPEN c_top;
v1:='During last week your time sheet(s) has (have) been received and entered into the system ';
v2:='as follows:';
v8:='Please note that we not received time sheet(s) for periods mention below:';
v9:='Also note that payroll is processed every alternate Tuesday.Please ensure that your time';
v10:='Sheet reaches us at least 24 hours prior to payroll processing in order to processing in order';
v11:='to process an accurate and timely payroll.';
v12:='In case of any discrepancy/clarification.p lease send an email to';
v18:='Date:'||v _date;
v15:='';
v16:='';
v14:=v9||v10||v 11||chr(10)||v1 5||chr(10)||v16 ||chr(10)||v12| |chr(10)||''||c hr(10)||v13||ch r(10)||' '||chr(10)||v18 ;
v3:=v1||''||v2;
LOOP
FETCH c_top
INTO x_candidate_nam e1, x_customer_name 1, x_manager_name,
x_time_sheet_id , x_assignment_id 1, x_fromdate, x_todate, x_bh,x_EMAIL_AD DRESS;
x_mail:=x_EMAIL _ADDRESS;
EXIT WHEN c_top%NOTFOUND;
begin
open c_main( x_assignment_id 1);
loop
fetch c_main
INTO x_candidate_nam e1, x_customer_name 1, x_manager_name,
x_time_sheet_id , x_assignment_id 1, x_fromdate, x_todate, x_bh;
v4 := 'Candidate Name:'||x_candi date_name1;
v15:= 'Customer Name:'||x_custo mer_name1;
v16:= 'Manager Name:'||x_manag er_name;
v17:=x_fromdate ;
v5:=rpad('AID', 15)||rpad('from date',15)||rpad ('to date',15)||rpad ('billable hours',15);
v6:=rpad(x_assi gnment_id1,15)| |rpad(x_fromdat e,15)||rpad(x_t odate,15)||rpad (x_bh,15);
/*v7:=v3||chr(10 )||'||chr(10)|| v4||chr(10)||'' ||chr(10)||v15| |chr(10)||' '||chr(10)||v16 ||chr(10)||''|| chr(10)||v5||ch r(10)||v17;*/
exit when c_main%notfound ;
end loop;
CLOSE c_main;
end;
BEGIN
OPEN c2 (x_assignment_i d1);
LOOP
FETCH c2
INTO m1, m2;
v9:=rpad(' ',15)||rpad('fr om date',15)||rpad ('to date',15);
v10:=rpad(' ',15)||rpad(m2, 15)||rpad(m1,15 );
v7:=v3||chr(10) ||''||chr(10)|| v4||chr(10)||'' ||chr(10)||v15| |chr(10)||' '||chr(10)||v16 ||chr(10)||''|| chr(10)||''||v5 ||chr(10)||''|| chr(10)||''||ch r(10)||v6||chr( 10)||''||chr(10 )||v8||chr(10)| |v9||chr(10)||v 10||chr(10)||v1 4;
EXIT WHEN c2%NOTFOUND;
END LOOP;
CLOSE c2;
END;
END LOOP;
MAILOUT
('x.com',
'x.co.in',
'x@gmail.com',
'Test Mail',
V7);
CLOSE c_top;
COMMIT;
END;
/
[/code]
I am using this pl/sql code to send email.BY using this code mail goes to particular person.but c_main cursor not able to fetch more than one record.and
in databse there is more than one record.
the output like this
During last week your time sheet(s) has (have) been received and entered into the
system as follows:
Candidate Name:
Customer Name:Citigroup Global Markets Inc.
Manager Name:
AID from date to date billable hours
203 07-JAN-08 13-JAN-08 40
Please note that we not received time sheet(s) for periods mention below:
from date to date
Also note that payroll is processed every alternate Tuesday.Please ensure that your
timeSheet reaches us at least 24 hours prior to payroll processing in order to
processing in orderto process an accurate and timely payroll.
In case of any discrepancy/clarification.p lease send an email to x.com
Corporation
Date:23-MAR-08
i am not able to fetch more than one aid,fromdate,to date
so can u suggest me how to modified this query.
Comment