Jump to content

[Resolvido] Erro de sintaxe IF NOT EXISTS


samesdavis
 Share

Recommended Posts

Olá pessoal,

Estou com problemas de erro de sintaxe nessa procedure onde a intenção é receber dois parametros e apenas inserir na tabela de log se não existir nessa mesma tabela de log.

************************************************************************************************************************

CREATE DEFINER = 'root'@'localhost' PROCEDURE `spEntidadesBuscar`(

IN pOrdem INTEGER(11),

IN pUser INTEGER(11)

)

NOT DETERMINISTIC

CONTAINS SQL

SQL SECURITY DEFINER

COMMENT ''

IF NOT EXISTS (SELECT * FROM `tblentidades_log` WHERE ordem_entidade = pOrdem AND ordem_user = pUser)

BEGIN

INSERT INTO `tblentidades_log` ( Ordem_entidade,Ordem_user) VALUES ( pOrdem,pUser) ;

END

************************************************************************************************************************

Está dando esse erro

Error: Use near 'IF NOT EXISTS (SELECT * FROM `tblentidades_log` WHERE ordem_entidade = pOrdem AN' at lin9

Link to comment
Share on other sites

mas isso eu já fiz e está descrito acima, o erro continua no mesmo lugar

BEGIN

IF NOT EXISTS (SELECT * FROM `tblentidades_log` WHERE ordem_entidade = pOrdem AND ordem_user = pUser)

INSERT INTO `tblentidades_log` ( Ordem_entidade,Ordem_user) VALUES ( pOrdem,pUser) ;

END

Link to comment
Share on other sites

HappyHippyHippo
CREATE DEFINER = 'root'@'localhost' PROCEDURE `spEntidadesBuscar`(
       IN pOrdem INTEGER(11),
       IN pUser INTEGER(11)
   )
   NOT DETERMINISTIC
   CONTAINS SQL
   SQL SECURITY DEFINER
   COMMENT ''

BEGIN       -- begin do procedure
 IF NOT EXISTS (SELECT * FROM `tblentidades_log` WHERE ordem_entidade = pOrdem AND ordem_user = pUser)
 THEN      -- begin do if
   INSERT INTO `tblentidades_log` ( Ordem_entidade,Ordem_user)  VALUES  ( pOrdem,pUser) ;
 END IF;    -- end do if
END;         -- end do procedure

edit : "then", "end if" and ';'

Edited by HappyHippyHippo
IRC : sim, é algo que ainda existe >> #p@p
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.