1
I have a procedure
correct and a view
which uses the Procedure parameter, only the view does not see the Procedure parameter, how to do to solve this problem?
Create a store So that from the customer’s code you can get the total amount of purchases with a discount of 10%
delimiter $$
drop view if exists visao $$
create view visao as select n.cod_cliente as codCli, (sum(i.qtd_vedida * i.pco_recebido)*0.9) as valorTotal
from nota_fiscal as n, item_nota_fiscal as i
where n.numero_nf = i.numero_nf and n.cod_cliente = AQUI SERIA O PARÂMETRO DA PROCEDURE, SÓ QUE A PROCEDURE VEM DEPOIS E ELE NÃO CONSEGUE PEGAR O PARÂMETRO, EXISTE ALGUMA SOLUÇÃO??(pCodCli )
group by codCli $$
DROP PROCEDURE IF EXISTS uspDesconto $$
CREATE PROCEDURE uspDesconto (pCodCli int(11))
BEGIN
DECLARE done BOOLEAN DEFAULT FALSE;
DECLARE vCodCli, vQtd_vedida int(11);
DECLARE vValorTotal decimal(10,2);
DECLARE cont integer;
declare cursor_a cursor for select * from visao;
DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = TRUE;
set cont = 0;
DROP TEMPORARY TABLE IF EXISTS tmp_Prod_Forn;
CREATE TEMPORARY TABLE tmp_Prod_Forn (
tmpCodCli int(11),
tmpValorTotal decimal(10,2)
);
OPEN cursor_a;
REPEAT FETCH cursor_a INTO vCodCli, vValorTotal;
IF NOT done THEN
insert into tmp_Prod_Forn values(vCodCli, vValorTotal);
-- set cont = cont + 1;
END IF;
UNTIL (done) END REPEAT;
close cursor_a;
SELECT * FROM tmp_Prod_Forn;
END $$
delimiter ;
You are creating a view inside the Database?
– user28595
above the view and below the precedent, if I didn’t have to call a parameter, the code would work normal, but I have to have this parameter and I don’t know how to call
– Gabriella
No questions, why does the view need to take the parameter of the previous one? Where does this parameter come from?
– user28595
is to see if the code of the client that exists in the table is equal to the past in the Procedure call
– Gabriella
You do not need to create a view to check this. Check inside the process itself through an if....
– user28595
Maybe @rray can help you in this better, Process in mysql I don’t know much.
– user28595
what is @rray? thanks in advance!
– Gabriella
What parameter are you talking about? At what point in your view should you see the parameter? Remember that a view is a table (virtual table) if you need to pass something to it, it would be through the Where.
– Jorge Campos
the pCodCli parameter you have there on the previous page. The view needs it to display the query
– Gabriella