Home > database >  How to use an SQL statement to create a function
How to use an SQL statement to create a function

Time:04-22

Because the client is online update the database by the software, so be through SQL statement execution, unable to import a SQL file, similar to add table, add fields, such as can use SQL statements
But create a function in the structure, the content of the similar line of what, is there any way to handle it?

SET FOREIGN_KEY_CHECKS=0;

DROP PROCEDURE IF the EXISTS ` ugiacenza `;
DELIMITER;;
The CREATE DEFINER=` root @ localhost ` PROCEDURE ` ugiacenza ` (in ` id ` int, ` in sl ` int, in ` n ` int)
The BEGIN
DECLARE designed.the gn VARCHAR (10) DEFAULT CONCAT (' G ', n);

IF the EXISTS (select * from giacenza where CodArticolo=id) then
The SET @ SQLCMD=concat (' update giacenza SET 'and designed.the gn,'='designed.the gn,' + ', sl, 'where CodArticolo=', id);
Prepare STMT from @ SQLCMD;
The execute STMT.
Deallocate prepare STMT.
The ELSE
SET @ SQLCMD=concat (' INSERT INTO giacenza (CodArticolo, 'and designed.the gn,) VALUES (' id,', 'and designed.the gn,') ');
Prepare STMT from @ SQLCMD;
The execute STMT.
Deallocate prepare STMT.
end if;
END
;;
DELIMITER.



The above content, if it is compressed into a SQL to conn. Execute SQL to create this form?
  • Related