Stored Procedure/Function of MySql

Stored Procedure/Function of MySql

Postby Armando » Mon Mar 23, 2009 7:35 pm

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
Armando
 
Posts: 3211
Joined: Fri Oct 07, 2005 8:20 pm
Location: Toluca, México

Re: Stored Procedure/Function of MySql

Postby César E. Lozada » Tue Mar 24, 2009 12:33 am

You must pass the parameters:

Code: Select all  Expand view
[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
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

Postby Armando » Tue Mar 24, 2009 1:31 am

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  Expand view

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
Armando
 
Posts: 3211
Joined: Fri Oct 07, 2005 8:20 pm
Location: Toluca, México

Re: Stored Procedure/Function of MySql

Postby César E. Lozada » Tue Mar 24, 2009 3:01 am

>>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%")]
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

Postby sajith » Tue Mar 24, 2009 7:56 am

Here is the sample to create and Execute StoredProcedure in Mysql

Code: Select all  Expand view

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  Expand view
CALL Sp_Item('Computer');


Regards,
Sajith
sajith
 
Posts: 110
Joined: Wed Feb 18, 2009 9:58 am
Location: India

Re: Stored Procedure/Function of MySql

Postby Armando » Tue Mar 24, 2009 12:07 pm

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: 3211
Joined: Fri Oct 07, 2005 8:20 pm
Location: Toluca, México

Re: Stored Procedure/Function of MySql

Postby Armando » Thu Mar 26, 2009 4:40 pm

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  Expand view

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
Armando
 
Posts: 3211
Joined: Fri Oct 07, 2005 8:20 pm
Location: Toluca, México

Re: Stored Procedure/Function of MySql

Postby César E. Lozada » Thu Mar 26, 2009 10:32 pm

It runs here!

How are you calling it?
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

Postby Armando » Thu Mar 26, 2009 11:43 pm

César:

This my code
Code: Select all  Expand view

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
Armando
 
Posts: 3211
Joined: Fri Oct 07, 2005 8:20 pm
Location: Toluca, México

Re: Stored Procedure/Function of MySql

Postby Willi Quintana » Fri Mar 27, 2009 3:20 am

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
Willi Quintana
 
Posts: 1019
Joined: Sun Oct 09, 2005 10:41 pm
Location: Cusco - Perú

Re: Stored Procedure/Function of MySql

Postby Armando » Fri Mar 27, 2009 11:45 pm

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
User avatar
Armando
 
Posts: 3211
Joined: Fri Oct 07, 2005 8:20 pm
Location: Toluca, México


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 85 guests