任何人都可以帮助我使用流水线功能吗?
Posted
技术标签:
【中文标题】任何人都可以帮助我使用流水线功能吗?【英文标题】:Can anyone help me with a PIPELINED function? 【发布时间】:2021-01-04 22:31:49 【问题描述】:我正在Oracle 12c 中开发一个函数,它从几个表中获取数据并返回一个标题行,每个标题后都有一个与其相关的值列表。 更好地解释一下,我有几个地方或城市,其中有电力消费者,根据他们用电的用途和消耗的千瓦时来确定它们。 该函数必须返回标题行中的每个城镇(加上标题),然后对该城镇的每个类别进行分组;等等每个城市。 我想我会用两 (2) 个光标来解决这个问题,一个按位置分组,另一个在第一个内部按类别分组。 当我编译时没有出现错误,但在执行时,Oracle 会警告我这个错误:
ORA-06502:PL / SQL:错误:数字或值字符串缓冲区太小
ORA-06512:在“CEMDO_DB.XXLOCALIDADPORCATEGORIA1”第 87 行
ORA-06512:在“CEMDO_DB.XXLOCALIDADPORCATEGORIA1”第 87 行
00000 - “PL/SQL:数值或数值错误%s”
原因:算术、数字、字符串、转换或约束错误 发生了。例如,如果尝试 将值 NULL 分配给声明为 NOT NULL 的变量,或者如果 尝试将大于 99 的整数分配给变量 声明为 NUMBER (2) 个。 操作:更改数据、操作方式或声明方式 值不违反约束。*
它并没有说明原因,因为我对值类型或变量容量没有任何问题。我在错误线上唯一的东西是一个管道行。 在函数的Debug中,报错信息如下:
ORA-06550:第 10 行,第 3 列:
PL / SQL:ORA-00904:“XXLXC1_ROW”:标识符无效
ORA-06550:第 9 行,第 5 列:
PL / SQL:忽略 SQL 语句
这里的错误是明确的,但我找不到解决方法,因为 PIPE ROW xxLxC1 类型已声明并且存在于架构对象中。
很抱歉给您带来不便,但这是我为 Oracle 编写的第三个特性,因为我已经使用 Informix 20 年了。
从现在开始,感谢您的关注。
我复制函数的代码:
CREATE OR REPLACE FUNCTION xxLocalidadPorCategoria1( pAnio NUMBER, pNroPer NUMBER ) RETURN xxLxC1_tab PIPELINED IS
CURSOR curLoc IS
SELECT cc.IdCategoria, cat.Descripcion, f.IdLocalidad, l.Descripcion Localidad
FROM Cbtes_Coop cc, Cbtes_Cptos ccp, Suministros s, SubFincas sf, Fincas f, Categorias cat,
Localidades l -----, OUTER( Sim_Cbtes sc, OUTER( Categorias cat, Suministros s, Localidades l ))
WHERE cc.Anio = pAnio
AND cc.NroPer = pNroPer
AND cc.Estado != 'X'
AND cc.IdTipo_Srv = 1
----AND cc.IdSuministro = 1078 ----Agregada para control
AND cc.IdEmpresa = ccp.IdEmpresa
AND cc.IdSucursal = ccp.IdSucursal
AND cc.Tipo_Cbte = ccp.Tipo_Cbte
AND cc.Grupo_Cbte = ccp.Grupo_Cbte
AND cc.Letra_Cbte = ccp.Letra_Cbte
AND cc.NroCbte = ccp.NroCbte
AND ccp.IdConcepto IN ( SELECT IdConcepto FROM Conceptos WHERE IdTipo_Srv = 1 )
AND NOT EXISTS ( SELECT IdEmpresa
FROM Cbtes_Coop
WHERE IdCbte_Padre = cc.IdCbte
AND IdSucursal IN ( 4, 47, 48 )
AND Tipo_Cbte = 'NC'
AND IdTipo_ModoFac > 0
AND Estado != 'X'
AND ABS( Totalimp ) = ABS( cc.Totalimp ))
AND cc.IdSuministro = s.IdSuministro
AND s.IdSubFinca = sf.IdSubFinca
AND sf.IdFinca = f.IdFinca
AND f.IdLocalidad = l.IdLocalidad
AND cc.IdTipo_Srv = cat.IdTipo_Srv
AND cc.IdCategoria = cat.IdCategoria
GROUP BY cc.IdCategoria, cat.Descripcion, f.IdLocalidad, l.Descripcion
ORDER BY 1;
CURSOR curTemp (pIdLocalidad NUMBER) IS
SELECT cc.IdCategoria, cat.Descripcion, f.IdLocalidad, l.Descripcion Localidad, SUM( CASE WHEN
ccp.IdConcepto = 5 THEN 1 END ) Cargo_Fijo, SUM( CASE WHEN ccp.IdConcepto = 5 THEN ccp.Importe
END ) Importe_C_Fijo, SUM( CASE WHEN ccp.IdConcepto = 10 THEN ROUND( ccp.Unidades, 2 ) END ) kWh,
SUM( CASE WHEN ccp.IdConcepto = 10 THEN ccp.Importe END ) Importe_Consumo, SUM( CASE WHEN
ccp.IdConcepto IN( 35, 38 ) THEN 1 END) Cargo_Fijo_GC, SUM( CASE WHEN ccp.IdConcepto IN( 35, 38 )
THEN ccp.Importe END ) Imp_C_Fijo_GC, SUM( CASE WHEN ccp.IdConcepto IN( 30, 31, 32 ) THEN ROUND(
ccp.Unidades, 2 ) END ) Energia_GC, SUM( CASE WHEN ccp.IdConcepto IN( 30, 31, 32 ) THEN
ccp.Importe END ) Importe_GC, SUM( CASE WHEN ccp.IdConcepto IN( 40, 41 ) THEN ROUND(
ccp.Unidades, 2 ) END ) Unidades_Demanda, SUM( CASE WHEN ccp.IdConcepto IN( 40, 41 ) THEN
ccp.Importe END ) Importe_Demanda, SUM( CASE WHEN ccp.IdConcepto IN( 101, 109 ) THEN 1 END )
Cant_BEN, SUM( CASE WHEN ccp.IdConcepto IN( 101, 109 ) THEN ccp.Importe END ) BEN, SUM( CASE WHEN
ccp.IdConcepto = 62 AND ccp.Importe != 0 THEN 1 END ) Ajuste_Coseno, SUM(CASE WHEN ccp.IdConcepto
= 62 AND ccp.Importe != 0 THEN ccp.Importe END ) Imp_Ajuste_Coseno, SUM(CASE WHEN ccp.IdConcepto
IN ( 25, 26, 27, 29, 291,292, 293, 294, 295 ) THEN 1 END )
Cant_Cargos_Ersep, SUM( CASE WHEN ccp.IdConcepto IN ( 25, 26, 27, 29, 291,292, 293, 294, 295 )
THEN ccp.Importe END ) Imp_Cargos_Ersep, SUM( CASE WHEN ccp.IdConcepto IN ( 20, 21, 23, 24, 64,
100, 432, 433, 434 ) THEN 1 END ) Cant_Ajustes_Ersep, SUM( CASE WHEN ccp.IdConcepto IN ( 20, 21,
23, 24, 64, 100, 432, 433, 434 ) THEN ccp.Importe END ) Imp_Ajustes_Ersep, SUM( CASE WHEN
ccp.IdConcepto IN( 28, 97, 98 ) AND ccp.IdSubConcepto IN( 0,1,2,3 ) THEN 1 END ) Unid_Bonif_Exc,
SUM( CASE WHEN ccp.IdConcepto IN( 28, 97, 98 ) AND ccp.IdSubConcepto IN( 0,1,2,3 ) THEN
ccp.Importe END ) Imp_Bonif_Exc, SUM( CASE WHEN ccp.IdConcepto IN( 438, 439 ) AND
ccp.IdSubConcepto = 0 THEN 1 END ) Unid_Reajustes, SUM( CASE WHEN
ccp.IdConcepto IN( 438, 439 ) AND ccp.IdSubConcepto = 0 THEN ccp.Importe END ) Imp_Reajustes, SUM(
CASE WHEN ccp.IdConcepto = 58 AND ccp.IdSubConcepto = 0 THEN 1 END ) Unid_Coie, SUM( CASE WHEN
ccp.IdConcepto = 58 AND ccp.IdSubConcepto = 0 THEN ccp.Importe END ) Imp_Coie, SUM( CASE WHEN
ccp.IdConcepto = 296 AND ccp.IdSubConcepto = 0 THEN 1 END ) Unid_Coie_Dem, SUM( CASE WHEN
ccp.IdConcepto = 296 AND ccp.IdSubConcepto = 0 THEN ccp.Importe END ) Imp_Coie_Dem, SUM( CASE WHEN
ccp.IdConcepto = 103 AND ccp.Importe < 0 THEN 1 END ) Unid_TRA1, SUM( CASE WHEN ccp.IdConcepto =
103 AND ccp.Importe < 0 THEN ccp.Importe END ) Imp_TRA1, SUM( CASE WHEN ccp.IdConcepto = 104 AND
ccp.Importe < 0 THEN 1 END ) Unid_TRA2, SUM( CASE WHEN ccp.IdConcepto = 104 AND ccp.Importe < 0
THEN ccp.Importe END ) Imp_TRA2, SUM( CASE WHEN ccp.IdConcepto = 102 AND ccp.Importe < 0 THEN 1
END ) Unid_TSCA, SUM( CASE WHEN ccp.IdConcepto = 102 AND ccp.Importe < 0 THEN ccp.Importe END )
Imp_TSCA, SUM( CASE WHEN ccp.IdConcepto = 105 AND ccp.Importe < 0 THEN 1 END ) Unid_TSSA, SUM(
CASE WHEN ccp.IdConcepto = 105 AND ccp.Importe < 0 THEN ccp.Importe END ) Imp_TSSA, SUM( CASE WHEN
ccp.IdConcepto = 443 AND ccp.Importe < 0 THEN 1 END ) UnidBonifCemdo, SUM( CASE WHEN
ccp.IdConcepto = 443 AND ccp.Importe < 0 THEN ccp.Importe END ) ImpBonifCemdo, SUM( CASE WHEN
ccp.IdConcepto = 121 AND ccp.Importe < 0 THEN 1 END ) UnidTSPC, SUM( CASE WHEN ccp.IdConcepto =
121 AND ccp.Importe < 0 THEN ccp.Importe END ) ImpTSPC, SUM( CASE WHEN ccp.IdConcepto = 122 AND
ccp.Importe < 0 THEN 1 END ) UnidTSPI, SUM( CASE WHEN ccp.IdConcepto = 122 AND ccp.Importe < 0
THEN ccp.Importe END ) ImpTSPI
FROM Cbtes_Coop cc, Cbtes_Cptos ccp, Suministros s, SubFincas sf, Fincas f, Categorias cat,
Localidades l
WHERE cc.Anio = pAnio
AND cc.NroPer = pNroPer
AND cc.Estado != 'X'
AND cc.IdTipo_Srv = 1
----AND cc.IdSuministro = 1078 ----Agregada para control
AND cc.IdEmpresa = ccp.IdEmpresa
AND cc.IdSucursal = ccp.IdSucursal
AND cc.Tipo_Cbte = ccp.Tipo_Cbte
AND cc.Grupo_Cbte = ccp.Grupo_Cbte
AND cc.Letra_Cbte = ccp.Letra_Cbte
AND cc.NroCbte = ccp.NroCbte
AND ccp.IdConcepto IN ( SELECT IdConcepto FROM Conceptos WHERE IdTipo_Srv = 1 )
AND NOT EXISTS ( SELECT IdEmpresa
FROM Cbtes_Coop
WHERE IdCbte_Padre = cc.IdCbte
AND IdSucursal IN ( 4, 47, 48 )
AND Tipo_Cbte = 'NC'
AND IdTipo_ModoFac > 0
AND Estado != 'X'
AND ABS( Totalimp ) = ABS( cc.Totalimp ))
AND cc.IdSuministro = s.IdSuministro
AND s.IdSubFinca = sf.IdSubFinca
AND sf.IdFinca = f.IdFinca
AND f.IdLocalidad = l.IdLocalidad
AND cc.IdTipo_Srv = cat.IdTipo_Srv
AND cc.IdCategoria = cat.IdCategoria
AND f.IdLocalidad = pIdLocalidad
GROUP BY f.IdLocalidad, l.Descripcion, cc.IdCategoria, cat.Descripcion
/*GROUPING SETS((f.IdLocalidad, l.Descripcion, cc.IdCategoria, cat.Descripcion))*/
ORDER BY f.IdLocalidad, cc.IdCategoria;
BEGIN
FOR regLoc IN curLoc LOOP
PIPE ROW (xxLxC1_row( TO_CHAR(regLoc.IdLocalidad) || '-' || regLoc.Localidad, 'Cargo Fijo',
'Imp. Cargo Fijo', 'Consumo', 'Imp. Consumo', 'C. Fijo GC', 'Imp. C. Fijo GC', 'Consumo GC', 'Imp.
Consumo GC', 'Unid. Demanda', 'Imp. Demanda', 'Bonificaciones', 'Imp. Bonificaciones', 'Coseno PHI',
'Imp. Coseno PHI', 'Cargos ERSeP', 'Imp. Cargos ERSeP',
'Ajustes ERSeP', 'Imp. Ajustes ERSeP', 'Unid. Bonif. Exc', 'Imp. Bonif. Exc.', 'Unid. Reajustes',
'Imp. Reajustes', 'Unid. COIE', 'Imp. COIE', 'Unid. COIE Dem.', 'Imp. COIE Dem', 'Unid. TRA1', 'Imp.
TRA1', 'Unid. TRA2', 'Imp. TRA2', 'Unid. TSCA', 'Imp. TSCA', 'Unid. TSSA', 'Imp. TSSA', 'Unid. Bonif.
Cemdo', 'Imp. Bonif. Cemdo', 'Unid. TSPC', 'Imp. TSPC', 'Unid. TSPI', 'Imp. TSPI'));
FOR regTemp IN curTemp(regLoc.IdLocalidad) LOOP
DBMS_OUTPUT.PUT_LINE(regLoc.IdLocalidad);
PIPE ROW (xxLxC1_row(regTemp.IdCategoria || '-' || regTemp.Descripcion, regTemp.Cargo_Fijo,
regTemp.Importe_C_Fijo, regTemp.kWh, regTemp.Importe_Consumo, regTemp.Cargo_Fijo_GC,
regTemp.Imp_C_Fijo_GC, regTemp.Energia_GC, regTemp.Importe_GC, regTemp.Unidades_Demanda,
regTemp.Importe_Demanda, regTemp.Cant_BEN, regTemp.BEN, regTemp.Ajuste_Coseno,
regTemp.Imp_Ajuste_Coseno, regTemp.Cant_Cargos_Ersep, regTemp.Imp_Cargos_Ersep,
regTemp.Cant_Ajustes_Ersep, regTemp.Imp_Ajustes_Ersep, regTemp.Unid_Bonif_Exc,
regTemp.Imp_Bonif_Exc, regTemp.Unid_Reajustes, regTemp.Imp_Reajustes, regTemp.Unid_Coie,
regTemp.Imp_Coie, regTemp.Unid_Coie_Dem, regTemp.Imp_Coie_Dem, regTemp.Unid_TRA1,
regTemp.Imp_TRA1, regTemp.Unid_TRA2, regTemp.Imp_TRA2, regTemp.Unid_TSCA, regTemp.Imp_TSCA,
regTemp.Unid_TSSA, regTemp.Imp_TSSA, regTemp.UnidBonifCemdo, regTemp.ImpBonifCemdo,
regTemp.UnidTSPC, regTemp.ImpTSPC, regTemp.UnidTSPI, regTemp.ImpTSPI));
END LOOP;
END LOOP;
END;
/
还有PIPE ROW和VIRTUAL TABLE的代码:
CREATE OR REPLACE TYPE xxLxC1_row AS OBJECT (c1 Varchar2(50), c2 Varchar2(20), c3 Varchar2(20), c4 Varchar2(20), c5 Varchar2(20), c6 Varchar2(20), c7 Varchar2(20), c8 Varchar2(20), c9 Varchar2(20), c10 Varchar2(20), c11 Varchar2(20), c12 Varchar2(20), c13 Varchar2(20), c14 Varchar2(20), c15 Varchar2(20), c16 Varchar2(20), c17 Varchar2(20), c18 Varchar2(20), c19 Varchar2(20), c20 Varchar2(20), c21 Varchar2(20), c22 Varchar2(20), c23 Varchar2(20), c24 Varchar2(20), c25 Varchar2(20), c26 Varchar2(20), c27 Varchar2(20), c28 Varchar2(20), c29 Varchar2(20), c30 Varchar2(20), c31 Varchar2(20), c32 Varchar2(20), c33 Varchar2(20), c34 Varchar2(20), c35 Varchar2(20), c36 Varchar2(20), c37 Varchar2(20), c38 Varchar2(20), c39 Varchar2(20), c40 Varchar2(20), c41 Varchar2(20));
/
CREATE OR REPLACE TYPE xxLxC1_tab AS TABLE OF xxLxC1_row;
/
【问题讨论】:
请edit 您的问题包含minimal reproducible example,其中包括表和数据类型的 DDL(CREATE TABLE
和 CREATE TYPE
)语句,以便我们可以运行您的函数并复制错误。如果我们不必尝试对您的代码进行逆向工程以使其能够运行,您更有可能获得帮助(尤其是对于大量代码)。
@MT0 我已经添加了代码,但是我不能添加每个中间表的代码,因为有好几个而且非常非常大。
然后添加一个minimal reproducible example,其中包含足够的信息来编译函数(我们不想要表格的完整定义,我们只想要足够的信息让它工作)。类似于您不需要将表中的所有列都提供给我们,您可以从函数和类型中编辑掉所有不必要的列;如果您对 4 列和 41 列有同样的问题,那么为什么要给我们 41 列……让它最小化。
@GustavoEchenique 由于错误发生在 PIPE ROW 行,可能 TYPE 中的变量之一不够大。在函数中,逐列遍历每一列,将变量替换为空字符串,并找出导致错误的原因。
将标题写为第一条记录对我来说有点奇怪。通常您将它们设置为对象中的属性(而不是 c1、c2、c3...)。注意,如果 DBMS_OUTPUT 缓冲区溢出,DBMS_OUTPUT.PUT_LINE
可能会在生产代码中引发异常。
【参考方案1】:
您的对象类型的每个元素都是 VARCHAR2(20),因此您输出的值之一很可能大于 20 个字节。
对于第一个管道行,假设您输出的所有值都是常量并且这些常量少于 20 个字符,那么唯一可能出现错误的是
TO_CHAR(regLoc.IdLocalidad) || '-' || regLoc.Localidad
超过 20 个字符。但是,对于第二个管道行,这些值中的每一个都来自游标提取,因此这些值中的任何一个都可能是罪魁祸首。
一个简单的循环数据的方法就是稍微改变你的函数暂时成为一个非流水线的函数,然后循环遍历数据并执行一个对象分配来检查,即
CREATE OR REPLACE FUNCTION xxLocalidadPorCategoria1( pAnio NUMBER, pNroPer NUMBER ) RETURN number IS
my_row xxLxC1_row;
CURSOR curLoc IS
SELECT cc.IdCategoria, cat.Descripcion, f.IdLocalidad, l.Descripcion Localidad
FROM Cbtes_Coop cc, Cbtes_Cptos ccp, Suministros s, SubFincas sf, Fincas f, Categorias cat,
Localidades l -----, OUTER( Sim_Cbtes sc, OUTER( Categorias cat, Suministros s, Localidades l ))
WHERE cc.Anio = pAnio
AND cc.NroPer = pNroPer
AND cc.Estado != 'X'
AND cc.IdTipo_Srv = 1
----AND cc.IdSuministro = 1078 ----Agregada para control
AND cc.IdEmpresa = ccp.IdEmpresa
AND cc.IdSucursal = ccp.IdSucursal
AND cc.Tipo_Cbte = ccp.Tipo_Cbte
AND cc.Grupo_Cbte = ccp.Grupo_Cbte
AND cc.Letra_Cbte = ccp.Letra_Cbte
AND cc.NroCbte = ccp.NroCbte
AND ccp.IdConcepto IN ( SELECT IdConcepto FROM Conceptos WHERE IdTipo_Srv = 1 )
AND NOT EXISTS ( SELECT IdEmpresa
FROM Cbtes_Coop
WHERE IdCbte_Padre = cc.IdCbte
AND IdSucursal IN ( 4, 47, 48 )
AND Tipo_Cbte = 'NC'
AND IdTipo_ModoFac > 0
AND Estado != 'X'
AND ABS( Totalimp ) = ABS( cc.Totalimp ))
AND cc.IdSuministro = s.IdSuministro
AND s.IdSubFinca = sf.IdSubFinca
AND sf.IdFinca = f.IdFinca
AND f.IdLocalidad = l.IdLocalidad
AND cc.IdTipo_Srv = cat.IdTipo_Srv
AND cc.IdCategoria = cat.IdCategoria
GROUP BY cc.IdCategoria, cat.Descripcion, f.IdLocalidad, l.Descripcion
ORDER BY 1;
CURSOR curTemp (pIdLocalidad NUMBER) IS
SELECT cc.IdCategoria, cat.Descripcion, f.IdLocalidad, l.Descripcion Localidad, SUM( CASE WHEN
ccp.IdConcepto = 5 THEN 1 END ) Cargo_Fijo, SUM( CASE WHEN ccp.IdConcepto = 5 THEN ccp.Importe
END ) Importe_C_Fijo, SUM( CASE WHEN ccp.IdConcepto = 10 THEN ROUND( ccp.Unidades, 2 ) END ) kWh,
SUM( CASE WHEN ccp.IdConcepto = 10 THEN ccp.Importe END ) Importe_Consumo, SUM( CASE WHEN
ccp.IdConcepto IN( 35, 38 ) THEN 1 END) Cargo_Fijo_GC, SUM( CASE WHEN ccp.IdConcepto IN( 35, 38 )
THEN ccp.Importe END ) Imp_C_Fijo_GC, SUM( CASE WHEN ccp.IdConcepto IN( 30, 31, 32 ) THEN ROUND(
ccp.Unidades, 2 ) END ) Energia_GC, SUM( CASE WHEN ccp.IdConcepto IN( 30, 31, 32 ) THEN
ccp.Importe END ) Importe_GC, SUM( CASE WHEN ccp.IdConcepto IN( 40, 41 ) THEN ROUND(
ccp.Unidades, 2 ) END ) Unidades_Demanda, SUM( CASE WHEN ccp.IdConcepto IN( 40, 41 ) THEN
ccp.Importe END ) Importe_Demanda, SUM( CASE WHEN ccp.IdConcepto IN( 101, 109 ) THEN 1 END )
Cant_BEN, SUM( CASE WHEN ccp.IdConcepto IN( 101, 109 ) THEN ccp.Importe END ) BEN, SUM( CASE WHEN
ccp.IdConcepto = 62 AND ccp.Importe != 0 THEN 1 END ) Ajuste_Coseno, SUM(CASE WHEN ccp.IdConcepto
= 62 AND ccp.Importe != 0 THEN ccp.Importe END ) Imp_Ajuste_Coseno, SUM(CASE WHEN ccp.IdConcepto
IN ( 25, 26, 27, 29, 291,292, 293, 294, 295 ) THEN 1 END )
Cant_Cargos_Ersep, SUM( CASE WHEN ccp.IdConcepto IN ( 25, 26, 27, 29, 291,292, 293, 294, 295 )
THEN ccp.Importe END ) Imp_Cargos_Ersep, SUM( CASE WHEN ccp.IdConcepto IN ( 20, 21, 23, 24, 64,
100, 432, 433, 434 ) THEN 1 END ) Cant_Ajustes_Ersep, SUM( CASE WHEN ccp.IdConcepto IN ( 20, 21,
23, 24, 64, 100, 432, 433, 434 ) THEN ccp.Importe END ) Imp_Ajustes_Ersep, SUM( CASE WHEN
ccp.IdConcepto IN( 28, 97, 98 ) AND ccp.IdSubConcepto IN( 0,1,2,3 ) THEN 1 END ) Unid_Bonif_Exc,
SUM( CASE WHEN ccp.IdConcepto IN( 28, 97, 98 ) AND ccp.IdSubConcepto IN( 0,1,2,3 ) THEN
ccp.Importe END ) Imp_Bonif_Exc, SUM( CASE WHEN ccp.IdConcepto IN( 438, 439 ) AND
ccp.IdSubConcepto = 0 THEN 1 END ) Unid_Reajustes, SUM( CASE WHEN
ccp.IdConcepto IN( 438, 439 ) AND ccp.IdSubConcepto = 0 THEN ccp.Importe END ) Imp_Reajustes, SUM(
CASE WHEN ccp.IdConcepto = 58 AND ccp.IdSubConcepto = 0 THEN 1 END ) Unid_Coie, SUM( CASE WHEN
ccp.IdConcepto = 58 AND ccp.IdSubConcepto = 0 THEN ccp.Importe END ) Imp_Coie, SUM( CASE WHEN
ccp.IdConcepto = 296 AND ccp.IdSubConcepto = 0 THEN 1 END ) Unid_Coie_Dem, SUM( CASE WHEN
ccp.IdConcepto = 296 AND ccp.IdSubConcepto = 0 THEN ccp.Importe END ) Imp_Coie_Dem, SUM( CASE WHEN
ccp.IdConcepto = 103 AND ccp.Importe < 0 THEN 1 END ) Unid_TRA1, SUM( CASE WHEN ccp.IdConcepto =
103 AND ccp.Importe < 0 THEN ccp.Importe END ) Imp_TRA1, SUM( CASE WHEN ccp.IdConcepto = 104 AND
ccp.Importe < 0 THEN 1 END ) Unid_TRA2, SUM( CASE WHEN ccp.IdConcepto = 104 AND ccp.Importe < 0
THEN ccp.Importe END ) Imp_TRA2, SUM( CASE WHEN ccp.IdConcepto = 102 AND ccp.Importe < 0 THEN 1
END ) Unid_TSCA, SUM( CASE WHEN ccp.IdConcepto = 102 AND ccp.Importe < 0 THEN ccp.Importe END )
Imp_TSCA, SUM( CASE WHEN ccp.IdConcepto = 105 AND ccp.Importe < 0 THEN 1 END ) Unid_TSSA, SUM(
CASE WHEN ccp.IdConcepto = 105 AND ccp.Importe < 0 THEN ccp.Importe END ) Imp_TSSA, SUM( CASE WHEN
ccp.IdConcepto = 443 AND ccp.Importe < 0 THEN 1 END ) UnidBonifCemdo, SUM( CASE WHEN
ccp.IdConcepto = 443 AND ccp.Importe < 0 THEN ccp.Importe END ) ImpBonifCemdo, SUM( CASE WHEN
ccp.IdConcepto = 121 AND ccp.Importe < 0 THEN 1 END ) UnidTSPC, SUM( CASE WHEN ccp.IdConcepto =
121 AND ccp.Importe < 0 THEN ccp.Importe END ) ImpTSPC, SUM( CASE WHEN ccp.IdConcepto = 122 AND
ccp.Importe < 0 THEN 1 END ) UnidTSPI, SUM( CASE WHEN ccp.IdConcepto = 122 AND ccp.Importe < 0
THEN ccp.Importe END ) ImpTSPI
FROM Cbtes_Coop cc, Cbtes_Cptos ccp, Suministros s, SubFincas sf, Fincas f, Categorias cat,
Localidades l
WHERE cc.Anio = pAnio
AND cc.NroPer = pNroPer
AND cc.Estado != 'X'
AND cc.IdTipo_Srv = 1
----AND cc.IdSuministro = 1078 ----Agregada para control
AND cc.IdEmpresa = ccp.IdEmpresa
AND cc.IdSucursal = ccp.IdSucursal
AND cc.Tipo_Cbte = ccp.Tipo_Cbte
AND cc.Grupo_Cbte = ccp.Grupo_Cbte
AND cc.Letra_Cbte = ccp.Letra_Cbte
AND cc.NroCbte = ccp.NroCbte
AND ccp.IdConcepto IN ( SELECT IdConcepto FROM Conceptos WHERE IdTipo_Srv = 1 )
AND NOT EXISTS ( SELECT IdEmpresa
FROM Cbtes_Coop
WHERE IdCbte_Padre = cc.IdCbte
AND IdSucursal IN ( 4, 47, 48 )
AND Tipo_Cbte = 'NC'
AND IdTipo_ModoFac > 0
AND Estado != 'X'
AND ABS( Totalimp ) = ABS( cc.Totalimp ))
AND cc.IdSuministro = s.IdSuministro
AND s.IdSubFinca = sf.IdSubFinca
AND sf.IdFinca = f.IdFinca
AND f.IdLocalidad = l.IdLocalidad
AND cc.IdTipo_Srv = cat.IdTipo_Srv
AND cc.IdCategoria = cat.IdCategoria
AND f.IdLocalidad = pIdLocalidad
GROUP BY f.IdLocalidad, l.Descripcion, cc.IdCategoria, cat.Descripcion
/*GROUPING SETS((f.IdLocalidad, l.Descripcion, cc.IdCategoria, cat.Descripcion))*/
ORDER BY f.IdLocalidad, cc.IdCategoria;
BEGIN
FOR regLoc IN curLoc LOOP
--
-- now we make sure this assignment works ok
--
DBMS_OUTPUT.PUT_LINE(TO_CHAR(regLoc.IdLocalidad));
my_row := xxLxC1_row( TO_CHAR(regLoc.IdLocalidad) || '-' || regLoc.Localidad, 'Cargo Fijo',
'Imp. Cargo Fijo', 'Consumo', 'Imp. Consumo', 'C. Fijo GC', 'Imp. C. Fijo GC', 'Consumo GC', 'Imp.
Consumo GC', 'Unid. Demanda', 'Imp. Demanda', 'Bonificaciones', 'Imp. Bonificaciones', 'Coseno PHI',
'Imp. Coseno PHI', 'Cargos ERSeP', 'Imp. Cargos ERSeP',
'Ajustes ERSeP', 'Imp. Ajustes ERSeP', 'Unid. Bonif. Exc', 'Imp. Bonif. Exc.', 'Unid. Reajustes',
'Imp. Reajustes', 'Unid. COIE', 'Imp. COIE', 'Unid. COIE Dem.', 'Imp. COIE Dem', 'Unid. TRA1', 'Imp.
TRA1', 'Unid. TRA2', 'Imp. TRA2', 'Unid. TSCA', 'Imp. TSCA', 'Unid. TSSA', 'Imp. TSSA', 'Unid. Bonif.
Cemdo', 'Imp. Bonif. Cemdo', 'Unid. TSPC', 'Imp. TSPC', 'Unid. TSPI', 'Imp. TSPI');
FOR regTemp IN curTemp(regLoc.IdLocalidad) LOOP
--
-- now we make sure this assignment works ok
--
DBMS_OUTPUT.PUT_LINE(regTemp.IdCategoria);
my_row :=xxLxC1_row(regTemp.IdCategoria || '-' || regTemp.Descripcion, regTemp.Cargo_Fijo,
regTemp.Importe_C_Fijo, regTemp.kWh, regTemp.Importe_Consumo, regTemp.Cargo_Fijo_GC,
regTemp.Imp_C_Fijo_GC, regTemp.Energia_GC, regTemp.Importe_GC, regTemp.Unidades_Demanda,
regTemp.Importe_Demanda, regTemp.Cant_BEN, regTemp.BEN, regTemp.Ajuste_Coseno,
regTemp.Imp_Ajuste_Coseno, regTemp.Cant_Cargos_Ersep, regTemp.Imp_Cargos_Ersep,
regTemp.Cant_Ajustes_Ersep, regTemp.Imp_Ajustes_Ersep, regTemp.Unid_Bonif_Exc,
regTemp.Imp_Bonif_Exc, regTemp.Unid_Reajustes, regTemp.Imp_Reajustes, regTemp.Unid_Coie,
regTemp.Imp_Coie, regTemp.Unid_Coie_Dem, regTemp.Imp_Coie_Dem, regTemp.Unid_TRA1,
regTemp.Imp_TRA1, regTemp.Unid_TRA2, regTemp.Imp_TRA2, regTemp.Unid_TSCA, regTemp.Imp_TSCA,
regTemp.Unid_TSSA, regTemp.Imp_TSSA, regTemp.UnidBonifCemdo, regTemp.ImpBonifCemdo,
regTemp.UnidTSPC, regTemp.ImpTSPC, regTemp.UnidTSPI, regTemp.ImpTSPI);
END LOOP;
END LOOP;
END;
/
variable x number
set serverout on
exec :x := xxLocalidadPorCategoria1(...)
【讨论】:
正如您在回答中所说,这就是解决方案。以上是关于任何人都可以帮助我使用流水线功能吗?的主要内容,如果未能解决你的问题,请参考以下文章