sql语句中不允许使用pls-00642本地集合类型

时间:2019-03-26 16:12:01

标签: sql oracle plsql

我知道有关此内容有很多资料,但是我仍然无法使其正常工作。上面的代码是我最后的尝试。问题是我在表中有重复记录,有时重复记录

我需要什么:

  • 获取重复记录
  • “保存”每个重复记录的次要序列(首先创建,应保留)
  • 删除其他记录

*我无法通过...按顺序进行分组...计数> 1,导致顺序不重复

DECLARE

TYPE SEQ_HISTORICO IS TABLE OF SIA.HISTORICO_ESCOLAR.NUM_SEQ_HISTORICO%TYPE;

V_MANTER SEQ_HISTORICO; -- least sequential, should be mantained

V_EXCLUIR SEQ_HISTORICO; -- others, to be deleted


BEGIN

   WITH 
   DUPLICADAS AS
   (
              select he.seq_historico,
                   he.cod_disciplina,
                   di.nom_disciplina,
                   pa.nom_fantasia,
                   he.cod_situacao_aluno_turma
              from ow.historico_escolar he
             inner join ow.periodo_academico pa on he.num_seq_periodo_academico =
                                                    pa.num_seq_periodo_academico
             inner join ow.disciplina di on he.cod_disciplina = di.cod_disciplina
             where he.seq_aluno_curso = '424242'
               and he.cod_situacao_aluno_turma = 'IS'

   )
   SELECT LEAST(nseq_historico) INTO V_MANTER FROM DUPLICADAS;

END;

错误:sql语句中不允许使用pls-00642本地集合类型

我应该使用pls_integer吗?

1 个答案:

答案 0 :(得分:1)

该错误试图告诉您不能SELECT...INTO...的PL / SQL中声明的类型的实例。在这种情况下,由于

SELECT LEAST(nseq_historico) INTO V_MANTER FROM DUPLICADAS

这里,V_MANTER的类型为SEQ_HISTORICO,在PL / SQL块中定义。

但是,您可以将BULK COLLECT放入PL / SQL集合中,但是为了使用MIN函数,您需要添加GROUP BY子句。从您的评论看来,您想按HISTORICO_ESCOLAR.COD_DISCIPLINA分组,因此将其汇总在一起,我们得到:

WITH DUPLICADAS AS (select he.seq_historico,
                           he.cod_disciplina,
                           di.nom_disciplina,
                           pa.nom_fantasia,
                           he.cod_situacao_aluno_turma
                      from ow.historico_escolar he
                      inner join ow.periodo_academico pa
                        on he.num_seq_periodo_academico = pa.num_seq_periodo_academico
                      inner join ow.disciplina di
                        on he.cod_disciplina = di.cod_disciplina
                      where he.seq_aluno_curso = '424242' and 
                            he.cod_situacao_aluno_turma = 'IS')
SELECT COD_DISCIPLINA, MIN(SEQ_HISTORICO) 
  BULK COLLECT INTO V_MANTER
  FROM DUPLICADAS
  GROUP BY COD_DISCIPLINA

好运。