plsql - Using a cursor in a stored procedure -


i want find min, max , average each quarter using stored procedure , cursors. can't figure out going wrong.

set serveroutput on  create or replace procedure seven2     cursor c1        select           qtrcode qtr,           cast(min(salaryoffered) decimal(4,2)) min,            cast(max(salaryoffered) decimal(4,2)) max,           cast(avg(salaryoffered) decimal(4,2)) avg                 interview       group           qtrcode       order           qtrcode  begin     qtrcode in c1    loop         dbms_output.put_line(min || ' ' ||max|| ' ' ||avg);    end loop; end; / 

can add padding functions above query , if how?

i have created interview table 2 columns example purpose , inserted dummy data, see changes in procedure, works fine now

sql> sql> desc interview  name                                                                     null?    type  ------------------------------------------------------------------------ -------- -------------------------------  salaryoffered                                                                     number(10,2)  qtrcode                                                                           varchar2(4)  sql>     sql> create or replace procedure seven2   2    3     cursor c1   4        select   5           qtrcode qtr,   6           cast(min(salaryoffered) decimal(10,4)) min,   7           cast(max(salaryoffered) decimal(10,4)) max,   8           cast(avg(salaryoffered) decimal(10,4)) avg   9         10           interview  11        group  12           qtrcode  13        order  14           qtrcode ;  15  16  begin  17     qtrcode in c1  18     loop  19             dbms_output.put_line('the qtr ' || qtrcode.qtr ||' min sal '|| qtrcode.min || ' max sal ' || qtrcode.max|| ' avg sal is' ||qtrcode.avg);  20     end loop;  21  end;  22  /  procedure created.    sql> exec seven2; qtr q1 min sal 137.07 max sal 964.66 avg sal 580.8748 qtr q2 min sal 127.79 max sal 938.49 avg sal 550.52 qtr q3 min sal 231.1 max sal 992.45 avg sal 672.59 qtr q4 min sal 103.19 max sal 960.13 avg sal 431.318  pl/sql procedure completed.  sql> 

Comments

Popular posts from this blog

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -