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 ;

I get the following error messages:

Error Code : 1064
You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use
near '' at line 4
(0 ms taken)

Error Code : 1193
Unknown system variable 'parent_id'
(0 ms taken)

Error Code : 1064
You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use
near 'END' at line 1
(0 ms taken)

Reply via email to