0

Can anyone please tell me where i'm wrong at

CREATE OR REPLACE FUNCTION ttestt (url varchar(255)) RETURNS VOID AS
BEGIN
    DECLARE @IMAGE_ID INT
    INSERT INTO images(url,ajoute_par) VALUES ("http://www.example.com","3")
    SET @IMAGE_ID = SCOPE_IDENTITY() 
    INSERT INTO Dossier(nom, etat, dossierImage) VALUES ('NameTest', 1, @IMAGE_ID)
END

I'm getting this error :

    #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 'FUNCTION ttestt (url varchar(255)) RETURNS VOID AS
    BEGIN
        DECLARE @IMAGE_ID' at line 1
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
bxxb
  • 740
  • 1
  • 9
  • 20

1 Answers1

0

Based on your comments and the script you've provided the error here is that you don't have a return statement in your function. Functions in SQL must have some form of return statement. If you don't want to return any value use a stored procedure instead.

Like @GordonLinoff said, functions cannot be used to alter tables. Again, more reasons to use a stored procedure.

Regarding the SCOPE_IDENTITY(), here are some alternatives to look into

PausePause
  • 746
  • 2
  • 9
  • 21