MySQL function error

MySQL function error

am 08.11.2007 08:47:49 von coosa

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 ;

Re: MySQL function error

am 08.11.2007 14:20:47 von colin.mckinnon

On 8 Nov, 07:47, coosa wrote:
> 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 $$
>

Hi Coosa,

Welcome to comp.lang.php where all things PHP get discussed. But we
tend not to talk about things which are nothing to do with PHP.

Try this list for more suitable places to post your query:

http://www.newzbot.com/search.php?t=group&q=mysql>ag=usene t

C.

Re: MySQL function error

am 08.11.2007 14:45:00 von Jerry Stuckle

coosa 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 ;
>
>

comp.databases.mysql is thataway ==>.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================