mysql function error

This is a discussion on mysql function error within the MySQL Database forums, part of the Database Forums category; dear all, I have a table called "distributor" having "distributor_id" as a PK and taking an ...


Go Back   Usenet Forums > Database Forums > MySQL Database

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 11-07-2007
coosa
 
Posts: n/a
Default 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 ;

Reply With Quote
  #2 (permalink)  
Old 11-08-2007
coosa
 
Posts: n/a
Default 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?

Reply With Quote
  #3 (permalink)  
Old 11-08-2007
Kees Nuyt
 
Posts: n/a
Default 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)
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 09:59 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0