sql - How can I display all results? -


my table bellow consist of different colour teams of have played colour , received points.

   create table colours    (c_id varchar2 (4) not null,     hc varchar2 (4),     ac varchar2 (4),     total number (2),     scores number (2));    insert colours values   ('c1', 'red', 'blue',8,'');    insert colours values   ('c2', 'red', 'blue', 9,'');    insert colours values   ('c3','blue', 'red', 10,'');    insert colours values   ('c4','blue', 'red', 11,''); 

next have created function calculates total points teams:

 create or replace function total  (i_hc   colours.hc%type)  return number                 v_colours_total     colours.total%type;       begin     select sum (total)     v_colours_total                  colours                  hc = i_hc;     if v_colours_total  null                v_colours_total:=0;                      end if;   return v_colours_total;               end; 

lastly procedure call function , display result of each team 1 one:

   create or replace procedure colours_scores (dnum varchar2)                                                            w_hc   colours.hc%type;           w_c_id colours.c_id%type;    w_total  colours.total%type;                 w_scores     number(2);                  totalscores  number(5,2);           cursor colours_cursor             select hc,c_id,total,scores   colours     hc = dnum;     begin      dbms_output.put_line(' '||'colours points '||'  ');      open colours_cursor;      totalscores :=total(dnum);          loop  fetch colours_cursor w_hc,w_c_id,w_total, w_scores; exit when colours_cursor%notfound;     dbms_output.put_line(w_c_id || '----'|| w_total ||'  ');       end loop;     dbms_output.put_line('---------------------------------------');     dbms_output.put_line(w_hc||' '||'final score = '||to_char(totalscores));     dbms_output.put_line('---------------------------------------');     close colours_cursor;        end; 

now, after execution of procedure, example execute colours_scores ('red'); result of colours:

  • if argument red (17).

  • if argument blue (21).

my question is:

  • is possible display results of both teams , order highest total?

  • or perhaps, need function this?

help appreciated, in advance.

why don't use open cursor on query give information? like:

select hc, sum (total) total colours             group hc order sum(total) desc 

with query there no need function.

update

as want use function try like:

select hc, c_id, total, scores, total(hc) totalscores  colours order total(hc); 

i haven't tested i'm not near pc should work.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -