| convert the given sql to procedure [message #572429] |
Wed, 12 December 2012 01:20  |
 |
mvrkr44
Messages: 11 Registered: December 2012
|
Junior Member |
|
|
i have the below query
select to_char(report_date, 'YYYY MM Mon'), count(1) no_of_times
from (
select to_date('&&YYYYMMDD', 'YYYYMMDD')+rownum report_date
, mod(rownum,14) mod_result
from all_objects
where
rownum <= 365)
where mod_result=0
group by to_char(report_date, 'YYYY MM Mon')
order by to_char(report_date, 'YYYY MM Mon');
need to convert as procedure based on input date parameter.
I will pass the input date from java environment and need to see the sql query output in front end.
|
|
|
|
|
|
| Re: convert the given sql to procedure [message #572443 is a reply to message #572429] |
Wed, 12 December 2012 01:53   |
 |
rishwinger
Messages: 101 Registered: November 2011
|
Senior Member |
|
|
Hope this helps!
CREATE OR REPLACE
PROCEDURE p1(
l_date IN VARCHAR2)
IS
l_num NUMBER;
v_rpt_date CHAR(21);
type rc
IS
ref
CURSOR;
l_rc rc;
BEGIN
OPEN l_rc FOR 'select to_char(report_date, ''YYYY MM Mon''), count(1) as no_of_times
from (
select to_date(:1, ''YYYYMMDD'')+rownum report_date
, mod(rownum,14) mod_result
from all_objects
where
rownum <= 365)
where mod_result=0
group by to_char(report_date, ''YYYY MM Mon'')
order by to_char(report_date, ''YYYY MM Mon'')' USING l_date ;
LOOP
FETCH l_rc INTO v_rpt_date,l_num;
dbms_output.put_line('date='||v_rpt_date||' -- count='||l_num);
EXIT
WHEN l_rc%notfound;
END LOOP;
END;
/
[Updated on: Wed, 12 December 2012 01:55] Report message to a moderator
|
|
|
|
|
|
|
|
|
|
| Re: convert the given sql to procedure [message #572458 is a reply to message #572452] |
Wed, 12 December 2012 03:54   |
 |
Michel Cadot
Messages: 54126 Registered: March 2007 Location: Nanterre, France, http://...
|
Senior Member Account Moderator |
|
|
Do you think that:
OPEN l_rc FOR 'select to_char(report_date, ''YYYY MM Mon''), count(1) as no_of_times
from (
select to_date(:1, ''YYYYMMDD'')+rownum report_date
, mod(rownum,14) mod_result
from all_objects
where
rownum <= 365)
where mod_result=0
group by to_char(report_date, ''YYYY MM Mon'')
order by to_char(report_date, ''YYYY MM Mon'')' USING l_date ;
is something readable (OK you will say that this OP's query but you could format anyway).
Regards
Michel
|
|
|
|
|
|