PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.databases.mysql > mysql function error
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
mysql function error

Réponse
 
LinkBack Outils de la discussion
Vieux 07/11/2007, 05h35   #1
coosa
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut mysql function error

dear all,

I have a table called "distributor" having "distributor_id" as a PK
and taking an integer data type as well as "distributor_parent_id"
which also takes an integer data type but can accept null values;

I tried to make this simple function that returns the parent_id by
taking a parameter representing the distributor id; still it fails, I
assume due to the delimiters.

I appreciate any assistance to this regard.

DELIMITER $$

CREATE FUNCTION last_inserted_parent_id ( inserted_id INT )
RETURNS INT
BEGIN
DECLARE parent_id INT$$
SET parent_id = (
SELECT distributor_parent_id
FROM distributor
WHERE distributor_id = inserted_id
)
RETURN parent_id$$
END$$
$$

DELIMITER ;

  Réponse avec citation
Vieux 08/11/2007, 19h24   #2
coosa
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: mysql function error

On Nov 7, 1:35 pm, coosa <coos...@gmail.com> wrote:
> dear all,
>
> I have a table called "distributor" having "distributor_id" as a PK
> and taking an integer data type as well as "distributor_parent_id"
> which also takes an integer data type but can accept null values;
>
> I tried to make this simple function that returns the parent_id by
> taking a parameter representing the distributor id; still it fails, I
> assume due to the delimiters.
>
> I appreciate any assistance to this regard.
>
> DELIMITER $$
>
> CREATE FUNCTION last_inserted_parent_id ( inserted_id INT )
> RETURNS INT
> BEGIN
> DECLARE parent_id INT$$
> SET parent_id = (
> SELECT distributor_parent_id
> FROM distributor
> WHERE distributor_id = inserted_id
> )
> RETURN parent_id$$
> END$$
> $$
>
> DELIMITER ;


any answers?

  Réponse avec citation
Vieux 08/11/2007, 23h28   #3
Kees Nuyt
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: mysql function error

On Tue, 06 Nov 2007 21:35:32 -0800, coosa
<coosa76@gmail.com> wrote:

>dear all,
>
>I have a table called "distributor" having "distributor_id" as a PK
>and taking an integer data type as well as "distributor_parent_id"
>which also takes an integer data type but can accept null values;
>
>I tried to make this simple function that returns the parent_id by
>taking a parameter representing the distributor id; still it fails, I
>assume due to the delimiters.


Your assumption is correct.
Read it up in the manual, there is a nice example in the
first hit when you search the MySQL 5.1 Reference manual
for DELIMITER.

>I appreciate any assistance to this regard.


I would appreciate if you would assist yourself.
You can express your appreciation for the creators of
MySQL and its manual by using that same manual.

>DELIMITER $$
>
>CREATE FUNCTION last_inserted_parent_id ( inserted_id INT )
> RETURNS INT
> BEGIN
> DECLARE parent_id INT$$
> SET parent_id = (
> SELECT distributor_parent_id
> FROM distributor
> WHERE distributor_id = inserted_id
> )
> RETURN parent_id$$
> END$$
>$$
>
>DELIMITER ;

--
( Kees
)
c[_] Remember that you are unique. Just like everyone else. (#13)
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 22h39.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,08305 seconds with 11 queries