我正在写explicit cursor的procedure比如
  cursor testCursor is
  select name,id,cost
  from table1,table2
  where table1.id=table2.id;
  
  testRow  testCursor%rowtype;  linecount:=0;
  open testCursor;
  loop
  fetch testCursor
  into testRow;
  exit when testCursor%notfound;
  linecount:=linecount+1;
  然后我要output的话,我就用dbms_output.put_line(testRow.name...);等等
  end loop;
  这个是普通情况
    但是我现在要写的procedure里面我要用一个sum
  
  cursor testCursor is
  select sum(cost)"total"
  from table1,table2
  where table1.id=table2.id;  testRow testCursor%rowtype;
这个时候我如何把这个sum的值output出来啊?
我胡乱试了dbms_output.put_line(testRow.sum(cost));
        dbms_output.put_line(testRow.total);
     
这些都不行,请假下该怎么output啊谢谢!

解决方案 »

  1.   

    直接 定义个number型的变量,into到这个变量不就得了
      

  2.   


    谢谢,我是这么弄的,网上查的。但是现在有个小问题。我的值是小数点后一位。比如15.6而我希望它显示为15.60
    谢谢
    我设了 test number(5,2);
    这个test如何把15.6显示为15.60呢。
      

  3.   

    SELECT to_char(1270.3,'9999.90') FROM dual;
      

  4.   

    dbms_output.put_line(testRow."total");正常的别名写法是不加双引号的,不加dbms_output.put_line(testRow.total);就对了。
      

  5.   


    我的total是alias,不加怎么可以