0

我正在尝试使用带有 where 子句的游标。它与我假设的简单光标应该没有太大不同。我在我的情况下尝试了以下但似乎没有打印任何输出。

    Declare 
      BG_TOTAL number;
     SDO_GEOM varchar2 ;

      cursor c1 is 
        select 
        SDO_GEOM.SDO_AREA(GEOMETRY, 0.005,'unit = SQ_MILE') 
          from <tablename>
          where SITE_ID= 8;

      Type SITE_TAB_TYPE is table of  c1%ROWTYPE;

      SITE_LIST SITE_TAB_TYPE;

    Begin
      open c1;
      FETCH c1 BULK COLLECT INTO SITE_LIST;

      close c1;


         DBMS_OUTPUT.PUT_LINE(SITE_LIST(1).SDO_GEOM);

    Exception
        When others then 
        DBMS_OUTPUT.PUT_LINE(sqlerrm);
    End;



[Error] Execution (3: 11): ORA-06550: line 3, column 11:
PLS-00215: String length constraints must be in range (1 .. 32767)
ORA-06550: line 7, column 5:
PLS-00487: Invalid reference to variable 'SDO_GEOM'
ORA-06550: line 7, column 5:
PLS-00487: Invalid reference to variable 'SDO_GEOM'
ORA-06550: line 22, column 40:
PLS-00302: component 'SDO_GEOM' must be declared
ORA-06550: line 22, column 6:
PL/SQL: Statement ignored
4

1 回答 1

0

问题是您试图将整个表对象输出到标准输出,而您应该遍历它。代替:

DBMS_OUTPUT.PUT_LINE(SITE_LIST.SDO_GEOM);

使用这样的东西:

FOR v_i IN 1..SITE_LIST.LAST
LOOP
  dbms_output.put_line(SITE_LIST(v_i).SOME_COLUMN_NAME);
END LOOP;

将 替换为SOME_COLUMN_NAME光标中所选列的名称。

编辑

您必须提供要引用的集合元素的索引:

dbms_output.put_line(site_list(1).SDO_GEOM);

编辑#2

是的..您没有为查询中选择的值指定列别名。试试这个游标:

cursor c1 is 
        select 
        SDO_GEOM.SDO_AREA(GEOMETRY, 0.005,'unit = SQ_MILE') AS my_value
          from <tablename>
          where SITE_ID= 8;

接着:

dbms_output.put_line(site_list(1).my_value);
于 2013-11-11T17:27:53.067 回答