表变量和设置选项的Pl / SQL声明

时间:2013-10-23 15:58:13

标签: plsql oracle11g

我想创建一个匿名块,我在其中执行以下操作:

set session set current_schema = PTSI;
DECLARE
var_cur_proj structure.structure_code%TYPE;
var_cur_task structure.structure_code%TYPE;
TYPE tbl_result AS OBJECT
(
  projeto_id structure.structure_code%TYPE,
  projeto structure.description%TYPE,
  tarefa_id structure.structure_code%TYPE,
  tarefa structure.description%TYPE,
  recurso_id structure.structure_code%TYPE,
  recurso structure.description%TYPE,
  perfil_id structure.structure_code%TYPE,
  perfil structure.description%TYPE,
  rate_id structure.structure_code%TYPE,
  rate_value rate_change_point_res.rate_value%TYPE,
  dia date,
  horas_reportadas NUMBER(38,2),
  horas_integradas_realizadas NUMBER(38,2),
  horas_integradas_remanescentes NUMBER(38,2),
  horas_planeadas NUMBER(38,2)
);
TYPE table_resul IS TABLE OF tbl_resul;
resultado table_result;
BEGIN

END;
/

这给了我一个错误......我正在关注这个网站创建表变量(http://ss64.com/oraplsql/declaretbl.html)看到它没有用,我试着像我习惯的那样创建表变量创建要由函数返回的表(创建对象然后创建表)。

有人可以帮我吗?

1 个答案:

答案 0 :(得分:3)

不是创建对象,而是应该将其创建为记录,然后从记录中声明表格,并且如上面的Justin所述,您必须在Begin和End标记之间至少有null;。请参阅下面的修改代码。并http://docs.oracle.com/cd/E11882_01/appdev.112/e25519/record_definition.htm了解更多详情。

alter session set current_schema = PTSI;

DECLARE
  var_cur_proj structure.structure_code%TYPE;
  var_cur_task structure.structure_code%TYPE;
  TYPE rec_result IS RECORD
  (
    projeto_id structure.structure_code%TYPE,
    projeto structure.description%TYPE,
    tarefa_id structure.structure_code%TYPE,
    tarefa structure.description%TYPE,
    recurso_id structure.structure_code%TYPE,
    recurso structure.description%TYPE,
    perfil_id structure.structure_code%TYPE,
    perfil structure.description%TYPE,
    rate_id structure.structure_code%TYPE,
    rate_value rate_change_point_res.rate_value%TYPE,
    dia date,
    horas_reportadas NUMBER(38,2),
    horas_integradas_realizadas NUMBER(38,2),
    horas_integradas_remanescentes NUMBER(38,2),
    horas_planeadas NUMBER(38,2)
  );
  TYPE table_result IS TABLE OF rec_result;
  resultado table_result;
BEGIN
  null;
END;
/

希望这有帮助