--------------------------------------------------------
--  DDL for View VIEW_AUX_COL_SUBGRUPO
--------------------------------------------------------

  CREATE OR REPLACE VIEW VIEW_AUX_COL_SUBGRUPO AS 
  SELECT
  --------------------------------------- PK
  SSM.CDFILIAL,
  SSM.CDCIA,
  SSM.CDMANCIA,
  SSM.NRSERVICOCIAFILI,
  SSM.CDCLASSE,
  SSM.CDSUBGRU,
  SSM.NRSEQSUBGRUSEMAM,
  SSM.NRORG,
  ---------------------------------------- IDENTIFICADOR CROSSTAB
  SSM.CDSUBGRU||'_'||SSM.NRSEQSUBGRUSEMAM AS SUBGRUPO,
  'SUBGRUPO' AS COLUNA,
  ---------------------------------------- ORDENACAO DA COLUNA
  TO_CHAR(SSM.NRORDSUBGRUSEMAM) AS NRORDEM,
  ---------------------------------------- ITENS DA COLUNA
  SBG.DSSUBGRU,
  TO_CHAR(SSM.DTINIVGSUMA, 'DD/MM/YYYY')   AS DTVIGINI,
  TO_CHAR(SSM.DTFIMVGSUMA, 'DD/MM/YYYY')   AS DTVIGFIM,
  ---------------------------------------- ITENS DE OUTRAS COLUNAS
  NULL AS PROPORCAO,
  NULL AS NMPRODUTOCIA,
  NULL AS SGUNIDADECIA,
  NULL AS QTPRODUTOCIA,
  NULL AS CDCICLO,
  NULL AS IDCICLO,
  NULL AS FGFOTOSUBSEMAM,
  NULL AS IDPRODREC,
  NULL AS NMPRODRECCICLO,
  NULL AS SGUNPRODRECCICLO,
  NULL AS QTPRODRECCICLO,
  NULL AS VRPESOGRAMATURA,
  NULL AS QTGRAMATURA,
  CUSTO_SUBGRU_TOTAL_COC(
    SSM.CDFILIAL,
    SSM.CDCIA,
    SSM.CDMANCIA,
    SSM.NRSERVICOCIAFILI,
    SSM.CDCLASSE,
    SSM.CDSUBGRU,
    SSM.NRSEQSUBGRUSEMAM,
    SSM.NRORG,
    NVL((SELECT MAX(DTCUSTO) FROM CICLOSUBGRUSEMAM WHERE CDFILIAL = SSM.CDFILIAL AND CDCIA = SSM.CDFILIAL AND CDMANCIA = SSM.CDMANCIA AND NRORG = SSM.NRORG AND CDSUBGRU = SSM.CDSUBGRU ), MAN.DTCUSTOMAN),
    NVL((SELECT MAX(IDTIPOCUSTO) FROM CICLOSUBGRUSEMAM WHERE CDFILIAL = SSM.CDFILIAL AND CDCIA = SSM.CDFILIAL AND CDMANCIA = SSM.CDMANCIA AND NRORG = SSM.NRORG AND CDSUBGRU = SSM.CDSUBGRU ), MAN.IDTIPOCUSTOMAN)) AS VRCUSTO,
  NULL AS SITUACAOREC
FROM SUBGRUSEMAM SSM
JOIN MANUALCIAM MAN
ON SSM.CDFILIAL = MAN.CDFILIAL
AND SSM.CDCIA = MAN.CDCIA
AND SSM.CDMANCIA = MAN.CDMANCIA
AND SSM.NRORG = MAN.NRORG
JOIN SUBGRUPOM SBG
ON SSM.CDSUBGRU          = SBG.CDSUBGRU
AND SSM.NRORG            = SBG.NRORG
/

--------------------------------------------------------
--  DDL for View VIEW_AUX_COL_PROPORCAO
--------------------------------------------------------

  CREATE OR REPLACE VIEW VIEW_AUX_COL_PROPORCAO AS
  SELECT
  --------------------------------------- PK
  SSM.CDFILIAL,
  SSM.CDCIA,
  SSM.CDMANCIA,
  SSM.NRSERVICOCIAFILI,
  SSM.CDCLASSE,
  SSM.CDSUBGRU,
  SSM.NRSEQSUBGRUSEMAM,
  SSM.NRORG,
  ---------------------------------------- IDENTIFICADOR CROSSTAB
  SSM.CDSUBGRU||'_'||SSM.NRSEQSUBGRUSEMAM AS SUBGRUPO,
  'PROPORCAO' AS COLUNA,
  ---------------------------------------- ORDENACAO DA COLUNA
  TO_CHAR(SSM.NRORDSUBGRUSEMAM) AS NRORDEM,
  ---------------------------------------- ITENS DE OUTRAS COLUNAS
  NULL AS DSSUBGRU,
  NULL AS DTVIGINI,
  NULL AS DTVIGFIM,
  ---------------------------------------- ITENS DA COLUNA
  CASE IDPROPSUBSEMAM
    WHEN '1' THEN '100%'
    WHEN '2' THEN 'V'||QTPROPSUBSEMAM
    WHEN '3' THEN 'T'
    WHEN '4' THEN QTPROPSUBSEMAM||'%'
    WHEN '5' THEN 'S'||QTPROPSUBSEMAM
  END AS PROPORCAO,
  ---------------------------------------- ITENS DE OUTRAS COLUNAS
  NULL AS NMPRODUTOCIA,
  NULL AS SGUNIDADECIA,
  NULL AS QTPRODUTOCIA,
  NULL AS CDCICLO,
  NULL AS IDCICLO,
  NULL AS FGFOTOSUBSEMAM,
  NULL AS IDPRODREC,
  NULL AS NMPRODRECCICLO,
  NULL AS SGUNPRODRECCICLO,
  NULL AS QTPRODRECCICLO,
  NULL AS VRPESOGRAMATURA,
  NULL AS QTGRAMATURA,
  NULL AS VRCUSTO,
  NULL AS SITUACAOREC
FROM SUBGRUSEMAM SSM
/

--------------------------------------------------------
--  DDL for View VIEW_AUX_COL_PRODUTOCIA
--------------------------------------------------------

  CREATE OR REPLACE VIEW VIEW_AUX_COL_PRODUTOCIA  AS
  SELECT
  --------------------------------------- PK
  SSM.CDFILIAL,
  SSM.CDCIA,
  SSM.CDMANCIA,
  SSM.NRSERVICOCIAFILI,
  SSM.CDCLASSE,
  SSM.CDSUBGRU,
  SSM.NRSEQSUBGRUSEMAM,
  SSM.NRORG,
  ---------------------------------------- IDENTIFICADOR CROSSTAB
  SSM.CDSUBGRU||'_'||SSM.NRSEQSUBGRUSEMAM AS SUBGRUPO,
  'PRODUTOCIA' AS COLUNA,
  ---------------------------------------- ORDENACAO DA COLUNA
  TO_CHAR(PCS.NRORDEM) AS NRORDEM,
  ---------------------------------------- ITENS DE OUTRAS COLUNAS
  NULL AS DSSUBGRU,
  NULL AS DTVIGINI,
  NULL AS DTVIGFIM,
  NULL AS PROPORCAO,
  ---------------------------------------- ITENS DA COLUNA
  PRO.NMPRODUTO AS NMPRODUTOCIA,
  PRO.SGUNIDADE AS SGUNIDADECIA,
  PCS.QTPRODUTOCIA,
  ---------------------------------------- ITENS DE OUTRAS COLUNAS
  NULL AS CDCICLO,
  NULL AS IDCICLO,
  NULL AS FGFOTOSUBSEMAM,
  NULL AS IDPRODREC,
  NULL AS NMPRODRECCICLO,
  NULL AS SGUNPRODRECCICLO,
  NULL AS QTPRODRECCICLO,
  NULL AS VRPESOGRAMATURA,
  NULL AS QTGRAMATURA,
  NULL AS VRCUSTO,
  NULL AS SITUACAOREC
FROM SUBGRUSEMAM SSM
INNER JOIN PROCIASUBSEMAM PCS ON
  SSM.CDFILIAL = PCS.CDFILIAL AND
  SSM.CDCIA = PCS.CDCIA AND
  SSM.CDMANCIA = PCS.CDMANCIA AND
  SSM.NRSERVICOCIAFILI = PCS.NRSERVICOCIAFILI AND
  SSM.CDCLASSE = PCS.CDCLASSE AND
  SSM.CDSUBGRU = PCS.CDSUBGRU AND
  SSM.NRSEQSUBGRUSEMAM = PCS.NRSEQSUBGRUSEMAM AND
  SSM.NRORG = PCS.NRORG
JOIN PRODUTO PRO ON
  PCS.CDPRODUTO = PRO.CDPRODUTO AND
  PCS.NRORG = PRO.NRORG
/

--------------------------------------------------------
--  DDL for View VIEW_AUX_COL_CICLO
--------------------------------------------------------

  CREATE OR REPLACE VIEW VIEW_AUX_COL_CICLO AS
  SELECT
  --------------------------------------- PK
  SSM.CDFILIAL,
  SSM.CDCIA,
  SSM.CDMANCIA,
  SSM.NRSERVICOCIAFILI,
  SSM.CDCLASSE,
  SSM.CDSUBGRU,
  SSM.NRSEQSUBGRUSEMAM,
  SSM.NRORG,
  ---------------------------------------- IDENTIFICADOR CROSSTAB
  SSM.CDSUBGRU||'_'||SSM.NRSEQSUBGRUSEMAM AS SUBGRUPO,
  'CICLO' AS COLUNA,
  ---------------------------------------- ORDENACAO DA COLUNA
  CCL.IDCICLO AS NRORDEM,
  ---------------------------------------- ITENS DE OUTRAS COLUNAS
  NULL AS DSSUBGRU,
  NULL AS DTVIGINI,
  NULL AS DTVIGFIM,
  NULL AS PROPORCAO,
  NULL AS NMPRODUTOCIA,
  NULL AS SGUNIDADECIA,
  NULL AS QTPRODUTOCIA,
  ---------------------------------------- ITENS DA COLUNA
  CSM.CDCICLO,
  CCL.IDCICLO,
  CSM.FGFOTOSUBSEMAM,
  ---------------------------------------- ITENS DE OUTRAS COLUNAS
  NULL AS IDPRODREC,
  NULL AS NMPRODRECCICLO,
  NULL AS SGUNPRODRECCICLO,
  NULL AS QTPRODRECCICLO,
  NULL AS VRPESOGRAMATURA,
  NULL AS QTGRAMATURA,
  NULL AS VRCUSTO,
  NULL AS SITUACAOREC
FROM SUBGRUSEMAM SSM
INNER JOIN CICLOSUBGRUSEMAM CSM ON
  SSM.CDFILIAL = CSM.CDFILIAL AND
  SSM.CDCIA = CSM.CDCIA AND
  SSM.CDMANCIA = CSM.CDMANCIA AND
  SSM.NRSERVICOCIAFILI = CSM.NRSERVICOCIAFILI AND
  SSM.CDCLASSE = CSM.CDCLASSE AND
  SSM.CDSUBGRU = CSM.CDSUBGRU AND
  SSM.NRSEQSUBGRUSEMAM = CSM.NRSEQSUBGRUSEMAM AND
  SSM.NRORG = CSM.NRORG
JOIN CICLO CCL ON
  CSM.CDCICLO = CCL.CDCICLO AND
  CSM.NRORG = CCL.NRORG
/

--------------------------------------------------------
--  DDL for View VIEW_AUX_COL_CICLOPROD
--------------------------------------------------------

  CREATE OR REPLACE VIEW VIEW_AUX_COL_CICLOPROD AS
  SELECT
    --------------------------------------- PK
    SSM.CDFILIAL,
    SSM.CDCIA,
    SSM.CDMANCIA,
    SSM.NRSERVICOCIAFILI,
    SSM.CDCLASSE,
    SSM.CDSUBGRU,
    SSM.NRSEQSUBGRUSEMAM,
    SSM.NRORG,
    ---------------------------------------- IDENTIFICADOR CROSSTAB
    SSM.CDSUBGRU||'_'||SSM.NRSEQSUBGRUSEMAM AS SUBGRUPO,
    'CICLOCOMP' AS COLUNA,
    ---------------------------------------- ORDENACAO DA COLUNA
    TO_CHAR(PSM.NRORDEM) AS NRORDEM,
    ---------------------------------------- ITENS DE OUTRAS COLUNAS
    NULL AS DSSUBGRU,
    NULL AS DTVIGINI,
    NULL AS DTVIGFIM,
    NULL AS PROPORCAO,
    NULL AS NMPRODUTOCIA,
    NULL AS SGUNIDADECIA,
    NULL AS QTPRODUTOCIA,
    CSM.CDCICLO,
    NULL AS IDCICLO,
    NULL AS FGFOTOSUBSEMAM,
    ---------------------------------------- ITENS DA COLUNA
    'PROD' AS IDPRODREC,
    PRO.NMPRODUTO AS NMPRODRECCICLO,
    PRO.SGUNIDADE AS SGUNPRODRECCICLO,
    PSM.QTPRODSUMA AS QTPRODRECCICLO,
    PSM.VRPESOGRAMATURA,
    PSM.QTGRAMATURA,
    CUSTO_PRODUTO_COC(PSM.CDFILIAL, PSM.CDPRODUTO, NVL(CSM.DTCUSTO, MAN.DTCUSTOMAN), NVL(CSM.IDTIPOCUSTO, MAN.IDTIPOCUSTOMAN), PSM.CDCIA) AS VRCUSTO,
    NULL AS SITUACAOREC
  FROM SUBGRUSEMAM SSM
  JOIN MANUALCIAM MAN
  ON SSM.CDFILIAL = MAN.CDFILIAL
  AND SSM.CDCIA = MAN.CDCIA
  AND SSM.CDMANCIA = MAN.CDMANCIA
  AND SSM.NRORG = MAN.NRORG
  INNER JOIN CICLOSUBGRUSEMAM CSM ON
    SSM.CDFILIAL = CSM.CDFILIAL AND
    SSM.CDCIA = CSM.CDCIA AND
    SSM.CDMANCIA = CSM.CDMANCIA AND
    SSM.NRSERVICOCIAFILI = CSM.NRSERVICOCIAFILI AND
    SSM.CDCLASSE = CSM.CDCLASSE AND
    SSM.CDSUBGRU = CSM.CDSUBGRU AND
    SSM.NRSEQSUBGRUSEMAM = CSM.NRSEQSUBGRUSEMAM AND
    SSM.NRORG = CSM.NRORG
  JOIN CICLO CCL ON
    CSM.CDCICLO = CCL.CDCICLO AND
    CSM.NRORG = CCL.NRORG
  RIGHT JOIN PRODSUBSEMAM PSM ON
    CSM.CDFILIAL = PSM.CDFILIAL AND
    CSM.CDCIA = PSM.CDCIA AND
    CSM.CDMANCIA = PSM.CDMANCIA AND
    CSM.NRSERVICOCIAFILI = PSM.NRSERVICOCIAFILI AND
    CSM.CDCLASSE = PSM.CDCLASSE AND
    CSM.CDSUBGRU = PSM.CDSUBGRU AND
    CSM.NRSEQSUBGRUSEMAM = PSM.NRSEQSUBGRUSEMAM AND
    CSM.CDCICLO = PSM.CDCICLO AND
    CSM.NRORG = PSM.NRORG
  JOIN PRODUTO PRO ON
    PSM.CDPRODUTO = PRO.CDPRODUTO AND
    PSM.NRORG = PRO.NRORG
/

--------------------------------------------------------
--  DDL for View VIEW_AUX_COL_CICLOREC
--------------------------------------------------------

  CREATE OR REPLACE VIEW VIEW_AUX_COL_CICLOREC AS
  SELECT
  --------------------------------------- PK
  SSM.CDFILIAL,
  SSM.CDCIA,
  SSM.CDMANCIA,
  SSM.NRSERVICOCIAFILI,
  SSM.CDCLASSE,
  SSM.CDSUBGRU,
  SSM.NRSEQSUBGRUSEMAM,
  SSM.NRORG,
  ---------------------------------------- IDENTIFICADOR CROSSTAB
  SSM.CDSUBGRU||'_'||SSM.NRSEQSUBGRUSEMAM AS SUBGRUPO,
  'CICLOCOMP' AS COLUNA,
  ---------------------------------------- ORDENACAO DA COLUNA
  TO_CHAR(RSM.NRORDEM) AS NRORDEM,
  ---------------------------------------- ITENS DE OUTRAS COLUNAS
  NULL AS DSSUBGRU,
  NULL AS DTVIGINI,
  NULL AS DTVIGFIM,
  NULL AS PROPORCAO,
  NULL AS NMPRODUTOCIA,
  NULL AS SGUNIDADECIA,
  NULL AS QTPRODUTOCIA,
  CSM.CDCICLO,
  NULL AS IDCICLO,
  NULL AS FGFOTOSUBSEMAM,
  ---------------------------------------- ITENS DA COLUNA
  'REC' AS IDPRODREC,
  REC.DSRECEITA AS NMPRODRECCICLO,
  REC.SGUNIDADE AS SGUNPRODRECCICLO,
  RSM.QTRECSUMA AS QTPRODRECCICLO,
  RSM.VRPESOGRAMATURA,
  RSM.QTGRAMATURA,
  CUSTO_RECEITAM_COC(RSM.CDFILIAL, RSM.CDRECEITA, FLR.NRVARIACAOREC, NVL(CSM.DTCUSTO, MAN.DTCUSTOMAN), NVL(CSM.IDTIPOCUSTO, MAN.IDTIPOCUSTOMAN), RSM.CDCIA) AS VRCUSTO,
  EXISTE_CUSTO_ZERO_REC(RSM.CDRECEITA, RSM.CDFILIAL, RSM.CDCIA, NVL(CSM.DTCUSTO, MAN.DTCUSTOMAN), NVL(CSM.IDTIPOCUSTO, MAN.IDTIPOCUSTOMAN), RSM.NRORG) AS SITUACAOREC
FROM SUBGRUSEMAM SSM
JOIN MANUALCIAM MAN
ON SSM.CDFILIAL = MAN.CDFILIAL
AND SSM.CDCIA = MAN.CDCIA
AND SSM.CDMANCIA = MAN.CDMANCIA
AND SSM.NRORG = MAN.NRORG
INNER JOIN CICLOSUBGRUSEMAM CSM ON
  SSM.CDFILIAL = CSM.CDFILIAL AND
  SSM.CDCIA = CSM.CDCIA AND
  SSM.CDMANCIA = CSM.CDMANCIA AND
  SSM.NRSERVICOCIAFILI = CSM.NRSERVICOCIAFILI AND
  SSM.CDCLASSE = CSM.CDCLASSE AND
  SSM.CDSUBGRU = CSM.CDSUBGRU AND
  SSM.NRSEQSUBGRUSEMAM = CSM.NRSEQSUBGRUSEMAM AND
  SSM.NRORG = CSM.NRORG
JOIN CICLO CCL ON
  CSM.CDCICLO = CCL.CDCICLO AND
  CSM.NRORG = CCL.NRORG
RIGHT JOIN RECSUBSEMAM RSM ON
  CSM.CDFILIAL = RSM.CDFILIAL AND
  CSM.CDCIA = RSM.CDCIA AND
  CSM.CDMANCIA = RSM.CDMANCIA AND
  CSM.NRSERVICOCIAFILI = RSM.NRSERVICOCIAFILI AND
  CSM.CDCLASSE = RSM.CDCLASSE AND
  CSM.CDSUBGRU = RSM.CDSUBGRU AND
  CSM.NRSEQSUBGRUSEMAM = RSM.NRSEQSUBGRUSEMAM AND
  CSM.CDCICLO = RSM.CDCICLO AND
  CSM.NRORG = RSM.NRORG
JOIN RECEITAM REC ON
  RSM.CDRECEITA = REC.CDRECEITA AND
  RSM.NRORG = REC.NRORG
JOIN FILIRECEITA FLR ON
  RSM.CDFILIAL = FLR.CDFILIAL AND
  RSM.CDRECEITA = FLR.CDRECEITA AND
  RSM.NRORG = FLR.NRORG
/


-------------------------------------------------------- 
-- DDL for View VIEW_AUX_COL_SUBGRUPOSEC 
-------------------------------------------------------- 


CREATE OR REPLACE VIEW VIEW_AUX_COL_SUBGRUPOSEC AS 
SELECT 
  --------------------------------------- PK 
  SSM.CDFILIAL, 
  SSM.CDCIA, 
  SSM.CDMANCIA, 
  SSM.NRSERVICOCIAFILI, 
  SSM.CDCLASSE, 
  SSM.CDSUBGRU, 
  SSM.NRSEQSUBGRUSEMAM, 
  SSM.NRORG, 
  ---------------------------------------- IDENTIFICADOR CROSSTAB 
  SSM.CDSUBGRU||'_'||SSM.NRSEQSUBGRUSEMAM AS SUBGRUPO, 
  'CICLOCOMP' AS COLUNA, 
  ---------------------------------------- ORDENACAO DA COLUNA 
  TO_CHAR(SSM.NRORDSUBGRUSEMAM) AS NRORDEM, 
  ---------------------------------------- ITENS DE OUTRAS COLUNAS 
  NULL AS DSSUBGRU, 
  NULL AS DTVIGINI, 
  NULL AS DTVIGFIM, 
  NULL AS PROPORCAO, 
  NULL AS NMPRODUTOCIA, 
  NULL AS SGUNIDADECIA, 
  NULL AS QTPRODUTOCIA, 
  CSM.CDCICLO, 
  NULL AS IDCICLO, 
  NULL AS FGFOTOSUBSEMAM, 
  ---------------------------------------- ITENS DA COLUNA 
  'SEC' AS IDPRODREC, 
  SGP.DSSUBGRU AS NMPRODRECCICLO, 
  NULL AS SGUNPRODRECCICLO, 
  NULL AS QTPRODRECCICLO, 
  NULL AS VRPESOGRAMATURA, 
  NULL AS QTGRAMATURA, 
  NULL AS VRCUSTO,
  NULL AS SITUACAOREC
  FROM SUBGRUSEMAM SSM 
  INNER JOIN CICLOSUBGRUSEMAM CSM ON 
  SSM.CDFILIAL = CSM.CDFILIAL AND 
  SSM.CDCIA = CSM.CDCIA AND 
  SSM.CDMANCIA = CSM.CDMANCIA AND 
  SSM.NRSERVICOCIAFILI = CSM.NRSERVICOCIAFILI AND 
  SSM.CDCLASSE = CSM.CDCLASSE AND 
  SSM.CDSUBGRU = CSM.CDSUBGRU AND 
  SSM.NRSEQSUBGRUSEMAM = CSM.NRSEQSUBGRUSEMAM AND 
  SSM.NRORG = CSM.NRORG 
JOIN CICLO CCL ON 
CSM.CDCICLO = CCL.CDCICLO AND 
CSM.NRORG = CCL.NRORG 
INNER JOIN SUBGRUPRINCIPALMENU SPM ON 
CSM.CDFILIAL = SPM.CDFILIAL AND 
CSM.CDCIA = SPM.CDCIA AND 
CSM.CDMANCIA = SPM.CDMANCIA AND 
CSM.NRSERVICOCIAFILI = SPM.NRSERVICOCIAFILI AND 
CSM.CDCLASSE = SPM.CDCLASSE AND 
CSM.CDSUBGRU = SPM.CDSUBGRUPRIN AND 
CSM.NRSEQSUBGRUSEMAM = SPM.NRSEQSUBGRUSEMAMPRIN AND 
CSM.CDCICLO = SPM.CDCICLO AND 
CSM.NRORG = SPM.NRORG 
INNER JOIN SUBGRUPOM SGP ON 
SGP.CDSUBGRU = SPM.CDSUBGRU AND 
SGP.NRORG = SPM.NRORG
/

--------------------------------------------------------
--  DDL for View VIEW_AUX_SUBGRUPO
--------------------------------------------------------

CREATE OR REPLACE VIEW VIEW_AUX_SUBGRUPO AS 
  SELECT CROSSTAB.*, LPAD(CROSSTAB.NRORDEM, 40, '0') AS NRORDEMGERAL FROM
(
        (SELECT 1 AS ORD, SUB.* FROM VIEW_AUX_COL_SUBGRUPO SUB)
  UNION (SELECT 2 AS ORD, PRP.* FROM VIEW_AUX_COL_PROPORCAO PRP)
  UNION (SELECT 3 AS ORD, PDC.* FROM VIEW_AUX_COL_PRODUTOCIA PDC)
  UNION (SELECT 4 AS ORD, CIC.* FROM VIEW_AUX_COL_CICLO CIC)
  UNION (SELECT 5 AS ORD, CLP.* FROM VIEW_AUX_COL_CICLOPROD CLP)
  UNION (SELECT 6 AS ORD, CLR.* FROM VIEW_AUX_COL_CICLOREC CLR)
  UNION (SELECT 7 AS ORD, SEC.* FROM VIEW_AUX_COL_SUBGRUPOSEC SEC)
) CROSSTAB ORDER BY ORD, NRORDEMGERAL ASC
/