Procedure retornar valores de SELECT - Oracle

SQL

Oracle

Stored Procedures

Oracle PL SQL

09/09/2020

Boa Tarde pessoal.
Seguinte preciso criar uma procedure que recebe um valor no parametroX e retornar valores de uma consulta SELECT...
Fui dar uma pesquisada no assunto e percebi que no oracle eu tenho que criar outras coisas alem da procedure, porem não ficou muito claro pra min essa questão.
Alguem poderia me ajuda?
Vou enviar abaixo a consulta que deve ser feita.
SELECT EST.CODBARRA,PRO.DESCRPROD,EST.CONTROLE,PRO.OBSETIQUETA,EXC.VLRVENDA AS TAB0,
(SELECT VLRVENDA FROM TGFEXC EXC,TGFPRO PRO,TGFEST EST WHERE EXC.CODPROD=PRO.CODPROD AND PRO.CODPROD=EST.CODPROD AND EXC.NUTAB = (SELECT MAX(NUTAB) FROM TGFTAB WHERE CODTAB = 1) AND EST.CODBARRA LIKE :COMPLEMENTO AND ROWNUM =1) AS TAB1,
ROUND((CASE WHEN (SELECT VLRVENDA FROM TGFEXC EXC,TGFPRO PRO,TGFEST EST WHERE EXC.CODPROD=PRO.CODPROD AND PRO.CODPROD=EST.CODPROD AND EXC.NUTAB = (SELECT MAX(NUTAB) FROM TGFTAB WHERE CODTAB = 3) AND EST.CODBARRA LIKE :COMPLEMENTO AND ROWNUM = 1 ) IS NULL THEN 108 
ELSE (SELECT VLRVENDA FROM TGFEXC EXC,TGFPRO PRO,TGFEST EST WHERE EXC.CODPROD=PRO.CODPROD AND PRO.CODPROD=EST.CODPROD AND EXC.NUTAB = (SELECT MAX(NUTAB) FROM TGFTAB WHERE CODTAB = 3) AND EST.CODBARRA LIKE :COMPLEMENTO AND ROWNUM = 1 )+100 END*EXC.VLRVENDA)/100,2) AS TAB3,
ROUND((CASE WHEN (SELECT VLRVENDA FROM TGFEXC EXC,TGFPRO PRO,TGFEST EST WHERE EXC.CODPROD=PRO.CODPROD AND PRO.CODPROD=EST.CODPROD AND EXC.NUTAB = (SELECT MAX(NUTAB) FROM TGFTAB WHERE CODTAB = 4) AND EST.CODBARRA LIKE :COMPLEMENTO AND ROWNUM = 1 ) IS NULL THEN 102 
ELSE (SELECT VLRVENDA FROM TGFEXC EXC,TGFPRO PRO,TGFEST EST WHERE EXC.CODPROD=PRO.CODPROD AND PRO.CODPROD=EST.CODPROD AND EXC.NUTAB = (SELECT MAX(NUTAB) FROM TGFTAB WHERE CODTAB = 4) AND EST.CODBARRA LIKE :COMPLEMENTO AND ROWNUM = 1 )+100 END*EXC.VLRVENDA)/100,2) AS TAB4,
ROUND((CASE WHEN (SELECT VLRVENDA FROM TGFEXC EXC,TGFPRO PRO,TGFEST EST WHERE EXC.CODPROD=PRO.CODPROD AND PRO.CODPROD=EST.CODPROD AND EXC.NUTAB = (SELECT MAX(NUTAB) FROM TGFTAB WHERE CODTAB = 5) AND EST.CODBARRA LIKE :COMPLEMENTO AND ROWNUM = 1 ) IS NULL THEN 108 
ELSE (SELECT VLRVENDA FROM TGFEXC EXC,TGFPRO PRO,TGFEST EST WHERE EXC.CODPROD=PRO.CODPROD AND PRO.CODPROD=EST.CODPROD AND EXC.NUTAB = (SELECT MAX(NUTAB) FROM TGFTAB WHERE CODTAB = 5) AND EST.CODBARRA LIKE :COMPLEMENTO AND ROWNUM = 1 )+100 END*EXC.VLRVENDA)/100,2) AS TAB5,
ROUND((CASE WHEN (SELECT VLRVENDA FROM TGFEXC EXC,TGFPRO PRO,TGFEST EST WHERE EXC.CODPROD=PRO.CODPROD AND PRO.CODPROD=EST.CODPROD AND EXC.NUTAB = (SELECT MAX(NUTAB) FROM TGFTAB WHERE CODTAB = 6) AND EST.CODBARRA LIKE :COMPLEMENTO AND ROWNUM = 1 ) IS NULL THEN 97 
ELSE (SELECT VLRVENDA FROM TGFEXC EXC,TGFPRO PRO,TGFEST EST WHERE EXC.CODPROD=PRO.CODPROD AND PRO.CODPROD=EST.CODPROD AND EXC.NUTAB = (SELECT MAX(NUTAB) FROM TGFTAB WHERE CODTAB = 6) AND EST.CODBARRA LIKE :COMPLEMENTO AND ROWNUM = 1 )+100 END*EXC.VLRVENDA)/100,2) AS TAB6,
ROUND((CASE WHEN (SELECT VLRVENDA FROM TGFEXC EXC,TGFPRO PRO,TGFEST EST WHERE EXC.CODPROD=PRO.CODPROD AND PRO.CODPROD=EST.CODPROD AND EXC.NUTAB = (SELECT MAX(NUTAB) FROM TGFTAB WHERE CODTAB = 7) AND EST.CODBARRA LIKE :COMPLEMENTO AND ROWNUM = 1 ) IS NULL THEN 108 
ELSE (SELECT VLRVENDA FROM TGFEXC EXC,TGFPRO PRO,TGFEST EST WHERE EXC.CODPROD=PRO.CODPROD AND PRO.CODPROD=EST.CODPROD AND EXC.NUTAB = (SELECT MAX(NUTAB) FROM TGFTAB WHERE CODTAB = 7) AND EST.CODBARRA LIKE :COMPLEMENTO AND ROWNUM = 1 )+100 END*EXC.VLRVENDA)/100,2) AS TAB7,
ROUND((CASE WHEN (SELECT VLRVENDA FROM TGFEXC EXC,TGFPRO PRO,TGFEST EST WHERE EXC.CODPROD=PRO.CODPROD AND PRO.CODPROD=EST.CODPROD AND EXC.NUTAB = (SELECT MAX(NUTAB) FROM TGFTAB WHERE CODTAB = 8) AND EST.CODBARRA LIKE :COMPLEMENTO AND ROWNUM = 1 ) IS NULL THEN 100 
ELSE (SELECT VLRVENDA FROM TGFEXC EXC,TGFPRO PRO,TGFEST EST WHERE EXC.CODPROD=PRO.CODPROD AND PRO.CODPROD=EST.CODPROD AND EXC.NUTAB = (SELECT MAX(NUTAB) FROM TGFTAB WHERE CODTAB = 8) AND EST.CODBARRA LIKE :COMPLEMENTO AND ROWNUM = 1 )+100 END*EXC.VLRVENDA)/100,2) AS TAB8,
ROUND((CASE WHEN (SELECT VLRVENDA FROM TGFEXC EXC,TGFPRO PRO,TGFEST EST WHERE EXC.CODPROD=PRO.CODPROD AND PRO.CODPROD=EST.CODPROD AND EXC.NUTAB = (SELECT MAX(NUTAB) FROM TGFTAB WHERE CODTAB = 9) AND EST.CODBARRA LIKE :COMPLEMENTO AND ROWNUM = 1 ) IS NULL THEN 94 
ELSE (SELECT VLRVENDA FROM TGFEXC EXC,TGFPRO PRO,TGFEST EST WHERE EXC.CODPROD=PRO.CODPROD AND PRO.CODPROD=EST.CODPROD AND EXC.NUTAB = (SELECT MAX(NUTAB) FROM TGFTAB WHERE CODTAB = 9) AND EST.CODBARRA LIKE :COMPLEMENTO AND ROWNUM = 1 )+100 END*EXC.VLRVENDA)/100,2) AS TAB9,
ROUND((CASE WHEN (SELECT VLRVENDA FROM TGFEXC EXC,TGFPRO PRO,TGFEST EST WHERE EXC.CODPROD=PRO.CODPROD AND PRO.CODPROD=EST.CODPROD AND EXC.NUTAB = (SELECT MAX(NUTAB) FROM TGFTAB WHERE CODTAB = 10) AND EST.CODBARRA LIKE :COMPLEMENTO AND ROWNUM = 1 ) IS NULL THEN 100 
ELSE (SELECT VLRVENDA FROM TGFEXC EXC,TGFPRO PRO,TGFEST EST WHERE EXC.CODPROD=PRO.CODPROD AND PRO.CODPROD=EST.CODPROD AND EXC.NUTAB = (SELECT MAX(NUTAB) FROM TGFTAB WHERE CODTAB = 10) AND EST.CODBARRA LIKE :COMPLEMENTO AND ROWNUM = 1 )+100 END*EXC.VLRVENDA)/100,2) AS TAB10,
ROUND((CASE WHEN (SELECT VLRVENDA FROM TGFEXC EXC,TGFPRO PRO,TGFEST EST WHERE EXC.CODPROD=PRO.CODPROD AND PRO.CODPROD=EST.CODPROD AND EXC.NUTAB = (SELECT MAX(NUTAB) FROM TGFTAB WHERE CODTAB = 11) AND EST.CODBARRA LIKE :COMPLEMENTO AND ROWNUM = 1 ) IS NULL THEN 89 
ELSE (SELECT VLRVENDA FROM TGFEXC EXC,TGFPRO PRO,TGFEST EST WHERE EXC.CODPROD=PRO.CODPROD AND PRO.CODPROD=EST.CODPROD AND EXC.NUTAB = (SELECT MAX(NUTAB) FROM TGFTAB WHERE CODTAB = 11) AND EST.CODBARRA LIKE :COMPLEMENTO AND ROWNUM = 1 )+100 END*EXC.VLRVENDA)/100,2) AS TAB11,
ROUND((CASE WHEN (SELECT VLRVENDA FROM TGFEXC EXC,TGFPRO PRO,TGFEST EST WHERE EXC.CODPROD=PRO.CODPROD AND PRO.CODPROD=EST.CODPROD AND EXC.NUTAB = (SELECT MAX(NUTAB) FROM TGFTAB WHERE CODTAB = 12) AND EST.CODBARRA LIKE :COMPLEMENTO AND ROWNUM = 1 ) IS NULL THEN 100 
ELSE (SELECT VLRVENDA FROM TGFEXC EXC,TGFPRO PRO,TGFEST EST WHERE EXC.CODPROD=PRO.CODPROD AND PRO.CODPROD=EST.CODPROD AND EXC.NUTAB = (SELECT MAX(NUTAB) FROM TGFTAB WHERE CODTAB = 12) AND EST.CODBARRA LIKE :COMPLEMENTO AND ROWNUM = 1 )+100 END*EXC.VLRVENDA)/100,2) AS TAB12,
G.ESTOQUE 
FROM TGFPRO PRO, TGFEXC EXC,TGFEST EST,TGFTAB TAB, ESTOQUE_CODPROD_G G
WHERE PRO.CODPROD=EXC.CODPROD
AND EXC.CODPROD=EST.CODPROD
AND EST.CODPROD=G.CODPROD 
AND G.CONTROLE =EST.CONTROLE
AND EXC.NUTAB=TAB.NUTAB
AND EST.CODBARRA LIKE :COMPLEMENTO
AND EXC.NUTAB = (SELECT MAX(NUTAB) FROM TGFTAB WHERE CODTAB = 0)
GROUP BY EST.CODBARRA,PRO.DESCRPROD,EST.CONTROLE,PRO.OBSETIQUETA,EXC.VLRVENDA,G.ESTOQUE 

Onde está escrito ":COMPLEMENTO" seria onde o parametro seria informado.

Agradeceria muito se pudessem me ajudar de alguma maneira
Gustavo Paula

Gustavo Paula

Curtidas 0

Melhor post

Emerson Nascimento

Emerson Nascimento

09/09/2020

tomei a liberdade de alterar a consulta.
pense em algo assim (não sei se vai funcionar porque, obviamente, não tenho como testar):
SELECT
	T.CODBARRA, T.DESCRPROD, T.CONTROLE, T.OBSETIQUETA,
	T.VALTAB00 TAB0,
	T.VALTAB01 TAB1,
	ROUND((CASE WHEN T.VALTAB03 IS NULL THEN 108 ELSE T.VALTAB03+100 END*EXC.VLRVENDA)/100,2) AS TAB3,
	ROUND((CASE WHEN T.VALTAB04 IS NULL THEN 102 ELSE T.VALTAB04+100 END*EXC.VLRVENDA)/100,2) AS TAB4,
	ROUND((CASE WHEN T.VALTAB05 IS NULL THEN 108 ELSE T.VALTAB05+100 END*EXC.VLRVENDA)/100,2) AS TAB5,
	ROUND((CASE WHEN T.VALTAB06 IS NULL THEN 97  ELSE T.VALTAB06+100 END*EXC.VLRVENDA)/100,2) AS TAB6,
	ROUND((CASE WHEN T.VALTAB07 IS NULL THEN 108 ELSE T.VALTAB07+100 END*EXC.VLRVENDA)/100,2) AS TAB7,
	ROUND((CASE WHEN T.VALTAB08 IS NULL THEN 100 ELSE T.VALTAB08+100 END*EXC.VLRVENDA)/100,2) AS TAB8,
	ROUND((CASE WHEN T.VALTAB09 IS NULL THEN 94  ELSE T.VALTAB09+100 END*EXC.VLRVENDA)/100,2) AS TAB9,
	ROUND((CASE WHEN T.VALTAB10 IS NULL THEN 100 ELSE T.VALTAB10+100 END*EXC.VLRVENDA)/100,2) AS TAB10,
	ROUND((CASE WHEN T.VALTAB11 IS NULL THEN 89  ELSE T.VALTAB11+100 END*EXC.VLRVENDA)/100,2) AS TAB11,
	ROUND((CASE WHEN T.VALTAB12 IS NULL THEN 100 ELSE T.VALTAB12+100 END*EXC.VLRVENDA)/100,2) AS TAB12,
	T.ESTOQUE 
FROM
(
	SELECT
		EST.CODBARRA, PRO.DESCRPROD, EST.CONTROLE, PRO.OBSETIQUETA, EXC.VLRVENDA,
		(CASE WHEN TAB.CODTAB = 00 THEN EXC.VLRVENDA ELSE NULL END) AS VALTAB00,
		(CASE WHEN TAB.CODTAB = 01 THEN EXC.VLRVENDA ELSE NULL END) AS VALTAB01,
		(CASE WHEN TAB.CODTAB = 03 THEN EXC.VLRVENDA ELSE NULL END) AS VALTAB03,
		(CASE WHEN TAB.CODTAB = 04 THEN EXC.VLRVENDA ELSE NULL END) AS VALTAB04,
		(CASE WHEN TAB.CODTAB = 05 THEN EXC.VLRVENDA ELSE NULL END) AS VALTAB05,
		(CASE WHEN TAB.CODTAB = 06 THEN EXC.VLRVENDA ELSE NULL END) AS VALTAB06,
		(CASE WHEN TAB.CODTAB = 07 THEN EXC.VLRVENDA ELSE NULL END) AS VALTAB07,
		(CASE WHEN TAB.CODTAB = 08 THEN EXC.VLRVENDA ELSE NULL END) AS VALTAB08,
		(CASE WHEN TAB.CODTAB = 09 THEN EXC.VLRVENDA ELSE NULL END) AS VALTAB09,
		(CASE WHEN TAB.CODTAB = 10 THEN EXC.VLRVENDA ELSE NULL END) AS VALTAB10,
		(CASE WHEN TAB.CODTAB = 11 THEN EXC.VLRVENDA ELSE NULL END) AS VALTAB11,
		(CASE WHEN TAB.CODTAB = 12 THEN EXC.VLRVENDA ELSE NULL END) AS VALTAB12,
		G.ESTOQUE 
	FROM
		TGFPRO PRO
	INNER JOIN
		TGFEXC EXC ON EXC.CODPROD = PRO.CODPROD
	INNER JOIN
		TGFEST EST ON EST.CODPROD = EXC.CODPROD
	INNER JOIN
		TGFTAB TAB ON TAB.NUTAB = EXC.NUTAB
	INNER JOIN
		ESTOQUE_CODPROD_G G ON G.CODPROD = EST.CODPROD AND G.CONTROLE = EST.CONTROLE
	WHERE
		EST.CODBARRA LIKE :COMPLEMENTO
		AND EXC.NUTAB IN (SELECT MAX(NUTAB) FROM TGFTAB WHERE CODTAB BETWEEN 0 AND 12 GROUP BY CODTAB)
) T
Fica melhor estruturado e mais fácil de entender.
Estou pesquisando sobre o retorno da stored procedure. assim que eu tiver uma resposta eu posto aqui.
GOSTEI 1

Mais Respostas

Gustavo Paula

Gustavo Paula

09/09/2020

tomei a liberdade de alterar a consulta.
pense em algo assim (não sei se vai funcionar porque, obviamente, não tenho como testar):
SELECT
	T.CODBARRA, T.DESCRPROD, T.CONTROLE, T.OBSETIQUETA,
	T.VALTAB00 TAB0,
	T.VALTAB01 TAB1,
	ROUND((CASE WHEN T.VALTAB03 IS NULL THEN 108 ELSE T.VALTAB03+100 END*EXC.VLRVENDA)/100,2) AS TAB3,
	ROUND((CASE WHEN T.VALTAB04 IS NULL THEN 102 ELSE T.VALTAB04+100 END*EXC.VLRVENDA)/100,2) AS TAB4,
	ROUND((CASE WHEN T.VALTAB05 IS NULL THEN 108 ELSE T.VALTAB05+100 END*EXC.VLRVENDA)/100,2) AS TAB5,
	ROUND((CASE WHEN T.VALTAB06 IS NULL THEN 97  ELSE T.VALTAB06+100 END*EXC.VLRVENDA)/100,2) AS TAB6,
	ROUND((CASE WHEN T.VALTAB07 IS NULL THEN 108 ELSE T.VALTAB07+100 END*EXC.VLRVENDA)/100,2) AS TAB7,
	ROUND((CASE WHEN T.VALTAB08 IS NULL THEN 100 ELSE T.VALTAB08+100 END*EXC.VLRVENDA)/100,2) AS TAB8,
	ROUND((CASE WHEN T.VALTAB09 IS NULL THEN 94  ELSE T.VALTAB09+100 END*EXC.VLRVENDA)/100,2) AS TAB9,
	ROUND((CASE WHEN T.VALTAB10 IS NULL THEN 100 ELSE T.VALTAB10+100 END*EXC.VLRVENDA)/100,2) AS TAB10,
	ROUND((CASE WHEN T.VALTAB11 IS NULL THEN 89  ELSE T.VALTAB11+100 END*EXC.VLRVENDA)/100,2) AS TAB11,
	ROUND((CASE WHEN T.VALTAB12 IS NULL THEN 100 ELSE T.VALTAB12+100 END*EXC.VLRVENDA)/100,2) AS TAB12,
	T.ESTOQUE 
FROM
(
	SELECT
		EST.CODBARRA, PRO.DESCRPROD, EST.CONTROLE, PRO.OBSETIQUETA, EXC.VLRVENDA,
		(CASE WHEN TAB.CODTAB = 00 THEN EXC.VLRVENDA ELSE NULL END) AS VALTAB00,
		(CASE WHEN TAB.CODTAB = 01 THEN EXC.VLRVENDA ELSE NULL END) AS VALTAB01,
		(CASE WHEN TAB.CODTAB = 03 THEN EXC.VLRVENDA ELSE NULL END) AS VALTAB03,
		(CASE WHEN TAB.CODTAB = 04 THEN EXC.VLRVENDA ELSE NULL END) AS VALTAB04,
		(CASE WHEN TAB.CODTAB = 05 THEN EXC.VLRVENDA ELSE NULL END) AS VALTAB05,
		(CASE WHEN TAB.CODTAB = 06 THEN EXC.VLRVENDA ELSE NULL END) AS VALTAB06,
		(CASE WHEN TAB.CODTAB = 07 THEN EXC.VLRVENDA ELSE NULL END) AS VALTAB07,
		(CASE WHEN TAB.CODTAB = 08 THEN EXC.VLRVENDA ELSE NULL END) AS VALTAB08,
		(CASE WHEN TAB.CODTAB = 09 THEN EXC.VLRVENDA ELSE NULL END) AS VALTAB09,
		(CASE WHEN TAB.CODTAB = 10 THEN EXC.VLRVENDA ELSE NULL END) AS VALTAB10,
		(CASE WHEN TAB.CODTAB = 11 THEN EXC.VLRVENDA ELSE NULL END) AS VALTAB11,
		(CASE WHEN TAB.CODTAB = 12 THEN EXC.VLRVENDA ELSE NULL END) AS VALTAB12,
		G.ESTOQUE 
	FROM
		TGFPRO PRO
	INNER JOIN
		TGFEXC EXC ON EXC.CODPROD = PRO.CODPROD
	INNER JOIN
		TGFEST EST ON EST.CODPROD = EXC.CODPROD
	INNER JOIN
		TGFTAB TAB ON TAB.NUTAB = EXC.NUTAB
	INNER JOIN
		ESTOQUE_CODPROD_G G ON G.CODPROD = EST.CODPROD AND G.CONTROLE = EST.CONTROLE
	WHERE
		EST.CODBARRA LIKE :COMPLEMENTO
		AND EXC.NUTAB IN (SELECT MAX(NUTAB) FROM TGFTAB WHERE CODTAB BETWEEN 0 AND 12 GROUP BY CODTAB)
) T
Fica melhor estruturado e mais fácil de entender.
Estou pesquisando sobre o retorno da stored procedure. assim que eu tiver uma resposta eu posto aqui.

Bom dia meu amigo, obrigado pela dica de estrutura da query.
Vou ficar aguardano seu retorno e vou testar a query aqui agora
GOSTEI 0
Emerson Nascimento

Emerson Nascimento

09/09/2020

SELECT
    T.CODBARRA, T.DESCRPROD, T.CONTROLE, T.OBSETIQUETA,
    SUM(T.VALTAB00) TAB0,
    SUM(T.VALTAB01) TAB1,
    ROUND((CASE WHEN SUM(T.VALTAB03) IS NULL THEN 108 ELSE SUM(T.VALTAB03)+100 END*EXC.VLRVENDA)/100,2) AS TAB3,
    ROUND((CASE WHEN SUM(T.VALTAB04) IS NULL THEN 102 ELSE SUM(T.VALTAB04)+100 END*EXC.VLRVENDA)/100,2) AS TAB4,
    ROUND((CASE WHEN SUM(T.VALTAB05) IS NULL THEN 108 ELSE SUM(T.VALTAB05)+100 END*EXC.VLRVENDA)/100,2) AS TAB5,
    ROUND((CASE WHEN SUM(T.VALTAB06) IS NULL THEN 97  ELSE SUM(T.VALTAB06)+100 END*EXC.VLRVENDA)/100,2) AS TAB6,
    ROUND((CASE WHEN SUM(T.VALTAB07) IS NULL THEN 108 ELSE SUM(T.VALTAB07)+100 END*EXC.VLRVENDA)/100,2) AS TAB7,
    ROUND((CASE WHEN SUM(T.VALTAB08) IS NULL THEN 100 ELSE SUM(T.VALTAB08)+100 END*EXC.VLRVENDA)/100,2) AS TAB8,
    ROUND((CASE WHEN SUM(T.VALTAB09) IS NULL THEN 94  ELSE SUM(T.VALTAB09)+100 END*EXC.VLRVENDA)/100,2) AS TAB9,
    ROUND((CASE WHEN SUM(T.VALTAB10) IS NULL THEN 100 ELSE SUM(T.VALTAB10)+100 END*EXC.VLRVENDA)/100,2) AS TAB10,
    ROUND((CASE WHEN SUM(T.VALTAB11) IS NULL THEN 89  ELSE SUM(T.VALTAB11)+100 END*EXC.VLRVENDA)/100,2) AS TAB11,
    ROUND((CASE WHEN SUM(T.VALTAB12) IS NULL THEN 100 ELSE SUM(T.VALTAB12)+100 END*EXC.VLRVENDA)/100,2) AS TAB12,
    T.ESTOQUE 
FROM
(
    SELECT
        EST.CODBARRA, PRO.DESCRPROD, EST.CONTROLE, PRO.OBSETIQUETA, EXC.VLRVENDA,
        (CASE WHEN TAB.CODTAB = 00 THEN EXC.VLRVENDA ELSE NULL END) AS VALTAB00,
        (CASE WHEN TAB.CODTAB = 01 THEN EXC.VLRVENDA ELSE NULL END) AS VALTAB01,
        (CASE WHEN TAB.CODTAB = 03 THEN EXC.VLRVENDA ELSE NULL END) AS VALTAB03,
        (CASE WHEN TAB.CODTAB = 04 THEN EXC.VLRVENDA ELSE NULL END) AS VALTAB04,
        (CASE WHEN TAB.CODTAB = 05 THEN EXC.VLRVENDA ELSE NULL END) AS VALTAB05,
        (CASE WHEN TAB.CODTAB = 06 THEN EXC.VLRVENDA ELSE NULL END) AS VALTAB06,
        (CASE WHEN TAB.CODTAB = 07 THEN EXC.VLRVENDA ELSE NULL END) AS VALTAB07,
        (CASE WHEN TAB.CODTAB = 08 THEN EXC.VLRVENDA ELSE NULL END) AS VALTAB08,
        (CASE WHEN TAB.CODTAB = 09 THEN EXC.VLRVENDA ELSE NULL END) AS VALTAB09,
        (CASE WHEN TAB.CODTAB = 10 THEN EXC.VLRVENDA ELSE NULL END) AS VALTAB10,
        (CASE WHEN TAB.CODTAB = 11 THEN EXC.VLRVENDA ELSE NULL END) AS VALTAB11,
        (CASE WHEN TAB.CODTAB = 12 THEN EXC.VLRVENDA ELSE NULL END) AS VALTAB12,
        G.ESTOQUE 
    FROM
        TGFPRO PRO
    INNER JOIN
        TGFEXC EXC ON EXC.CODPROD = PRO.CODPROD
    INNER JOIN
        TGFEST EST ON EST.CODPROD = EXC.CODPROD
    INNER JOIN
        TGFTAB TAB ON TAB.NUTAB = EXC.NUTAB
    INNER JOIN
        ESTOQUE_CODPROD_G G ON G.CODPROD = EST.CODPROD AND G.CONTROLE = EST.CONTROLE
    WHERE
        EST.CODBARRA LIKE :COMPLEMENTO
        AND EXC.NUTAB IN (SELECT MAX(NUTAB) FROM TGFTAB WHERE CODTAB BETWEEN 0 AND 12 GROUP BY CODTAB)
) T
GROUP BY
    T.CODBARRA, T.DESCRPROD, T.CONTROLE, T.OBSETIQUETA,
    T.ESTOQUE, T.VLRVENDA

GOSTEI 0
Gustavo Paula

Gustavo Paula

09/09/2020

Alguem? kkk
to precisando de ajuda nisso ai
GOSTEI 0
Jair N.

Jair N.

09/09/2020

Bom Dia Gustavo, me passe alguns questionamentos
1º sua consulta é funcional? Isto é ela está te trazendo algum resultado?
2º Você fala de procedimento, porém quer que, lhe traga o resultado da consulta quando passado o parâmetro, certo! Então você quer uma "função" e neste caso o resultado é registro ou algum valor, apenas um ou vários...
3º Seu banco de dados é Oracle? Vou te dar uma operação se for tem que retornar um type de registro, o mesmo que no MSSQLServer retorna o tipo tabela.
neste caso veja :
a) Craindo no Oracle o tipo de retorno....
CREATE OR REPLACE TYPE typobj_retorno AS OBJECT (criar aqui a estrutura de retorno exemplo (id INTEGER, data TIMESTAMP, etc);
CREATE OR REPLACE TYPE typtab_retorno AS TABLE OF typobj_retorno;

b) Criando no Oracle a função para o retorno...
CREATE OR REPLACE FUNCTION fnctyp_retorno (< seus paramentros>)
RETURN typtab_retorno PIPELINED IS retorno typobj_retorno;
CURSOR cur_consulta IS <SELECT ... FROM..(sua consulta). >
BEGIN
-- Tem que passar aqui para data atributo do seu tipo de retorno como nulo...
retorno = typobj_retorno(NULL, NULL, ... para cada atributo criado no seu TYPE OBJECT);
OPEN cur_consulta
LOOP
EXIT WHEN cur_consulta%NOTFOUND;
retorno.<atributo> = cur_consulta.<>atributo>;
-- Exemplo:
retorno.<id> = cur_consulta.<id x>;
retorno.<data> = cur_consulta.<data x>;
PIPE ROW(retorno);
END LOOP;
CLOSE cur_consulta;
RETURN;
END;


GOSTEI 0
Gustavo Paula

Gustavo Paula

09/09/2020

Boa tarde Jair, Muito obrigado pela ajuda.
Deu certinho, está me retornando conforme eu esperava. Ajudou muito.
GOSTEI 0
POSTAR