Stored Procedure/Function of MySql

Post Reply
User avatar
Armando
Posts: 2479
Joined: Fri Oct 07, 2005 8:20 pm
Location: Toluca, México
Contact:

Stored Procedure/Function of MySql

Post by Armando »

Hello:

Someone has a simple example to run a stored procedure/function of Mysql ?

Regards
SOI, s.a. de c.v.
estbucarm@gmail.com
http://www.soisa.mex.tl/
http://sqlcmd.blogspot.com/
Tel. (722) 174 44 45
Carpe diem quam minimum credula postero
User avatar
César E. Lozada
Posts: 128
Joined: Wed Oct 26, 2005 12:18 pm
Location: Los Teques, Miranda, Venezuela

Re: Stored Procedure/Function of MySql

Post by César E. Lozada »

You must pass the parameters:

Code: Select all

[SELECT * FROM CLIENTS WHERE State(CLIENTS.ADDRESS,"%WYOMING%")]

CREATE DEFINER = 'root'@'localhost' FUNCTION `State`(cAddress TEXT,cState TEXT)
    RETURNS tinyint(1)
    NOT DETERMINISTIC
    CONTAINS SQL
    SQL SECURITY DEFINER
    COMMENT ''
BEGIN
  RETURN cAdress LIKE cState;
END;
Regards

PD:
#xDefine Carpe_diem_quam_minimum_credula_postero "Aprovecha el día, no confíes en mañana"
Thanks!
User avatar
Armando
Posts: 2479
Joined: Fri Oct 07, 2005 8:20 pm
Location: Toluca, México
Contact:

Re: Stored Procedure/Function of MySql

Post by Armando »

César:

Thanks a lot.

As I know your sample is to create the stored procedure, Now, how can I execute it ?

Regards

Code: Select all

PD:
#xDefine Carpe_diem_quam_minimum_credula_postero "Aprovecha el día, no confíes en mañana"
 
Return(.T.) :D
SOI, s.a. de c.v.
estbucarm@gmail.com
http://www.soisa.mex.tl/
http://sqlcmd.blogspot.com/
Tel. (722) 174 44 45
Carpe diem quam minimum credula postero
User avatar
César E. Lozada
Posts: 128
Joined: Wed Oct 26, 2005 12:18 pm
Location: Los Teques, Miranda, Venezuela

Re: Stored Procedure/Function of MySql

Post by César E. Lozada »

>>As I know your sample is to create the stored procedure, Now, how can I execute it ?

You can execute it only from a MySQL query:

[SELECT * FROM CLIENTS WHERE State(CLIENTS.ADDRESS,"%WYOMING%")]
sajith
Posts: 110
Joined: Wed Feb 18, 2009 9:58 am
Location: India
Contact:

Re: Stored Procedure/Function of MySql

Post by sajith »

Here is the sample to create and Execute StoredProcedure in Mysql

Code: Select all

create Procedure Sp_Item(IN name varchar(25))//Here name is parameter
Begin
 select * from Item where Item.name=name;
 end;
Command to Execute Procedure Sp_Item

Code: Select all

CALL Sp_Item('Computer');
Regards,
Sajith
User avatar
Armando
Posts: 2479
Joined: Fri Oct 07, 2005 8:20 pm
Location: Toluca, México
Contact:

Re: Stored Procedure/Function of MySql

Post by Armando »

César & Sajith:

Thank you very much to both

I'll try it

Regards
SOI, s.a. de c.v.
estbucarm@gmail.com
http://www.soisa.mex.tl/
http://sqlcmd.blogspot.com/
Tel. (722) 174 44 45
Carpe diem quam minimum credula postero
User avatar
Armando
Posts: 2479
Joined: Fri Oct 07, 2005 8:20 pm
Location: Toluca, México
Contact:

Re: Stored Procedure/Function of MySql

Post by Armando »

Dear Friends:

With your help I was able to create and execute a stored procedure successfully
thanks a lot for that, but I can't execute a STORED FUNCTION, is there a diference ?

Here is the code for my stored function

Code: Select all

CREATE FUNCTION `sf_hola`() RETURNS char(50)
RETURN('Hola !')
 
Regards
SOI, s.a. de c.v.
estbucarm@gmail.com
http://www.soisa.mex.tl/
http://sqlcmd.blogspot.com/
Tel. (722) 174 44 45
Carpe diem quam minimum credula postero
User avatar
César E. Lozada
Posts: 128
Joined: Wed Oct 26, 2005 12:18 pm
Location: Los Teques, Miranda, Venezuela

Re: Stored Procedure/Function of MySql

Post by César E. Lozada »

It runs here!

How are you calling it?
User avatar
Armando
Posts: 2479
Joined: Fri Oct 07, 2005 8:20 pm
Location: Toluca, México
Contact:

Re: Stored Procedure/Function of MySql

Post by Armando »

César:

This my code

Code: Select all

CALL sf_hola('Armandito');
 
The error message is "Procedure sf_hola does not exist"

And I use MySql 5.0.18

Regards
SOI, s.a. de c.v.
estbucarm@gmail.com
http://www.soisa.mex.tl/
http://sqlcmd.blogspot.com/
Tel. (722) 174 44 45
Carpe diem quam minimum credula postero
User avatar
Willi Quintana
Posts: 859
Joined: Sun Oct 09, 2005 10:41 pm
Location: Cusco - Perú
Contact:

Re: Stored Procedure/Function of MySql

Post by Willi Quintana »

HI Maese.

//------------------
DELIMITER $$

DROP PROCEDURE IF EXISTS `cijmey`.`prueba` $$
CREATE PROCEDURE `cijmey`.`prueba` (IN cCodigo VARCHAR(20))
BEGIN
SELECT * FROM kardex WHERE cod_producto = cCodigo ;
END $$

DELIMITER ;
//---------
crealo cpon el Administrator del MySQL, con el Script

y lueco lo llamas con:

CALL prueba('CAS200065')


Salu2
User avatar
Armando
Posts: 2479
Joined: Fri Oct 07, 2005 8:20 pm
Location: Toluca, México
Contact:

Re: Stored Procedure/Function of MySql

Post by Armando »

Willi:

Muchas gracias por el ejemplo, ando buscando un ejemplo pero
de stored function.

Saludos
SOI, s.a. de c.v.
estbucarm@gmail.com
http://www.soisa.mex.tl/
http://sqlcmd.blogspot.com/
Tel. (722) 174 44 45
Carpe diem quam minimum credula postero
Post Reply