0

I'm quite new to MySql. I'm trying to create a function:

CREATE FUNCTION GetDefaultLangText(tableName VARCHAR(50), fieldName VARCHAR(50), primaryFieldName VARCHAR(50), langID INT(10), 
                defaultLangID INT(10), itemID INT(10), actValue VARCHAR(200)) RETURNS VARCHAR(200)
BEGIN  
    DECLARE sqlString VARCHAR(200);
    SET sqlString = CONCAT(CONCAT('(SELECT ', fieldName, 
    CONCAT(' FROM ', tableName, ' WHERE LangID = ')), CONCAT(defaultLangID ,' AND ', 
    CONCAT(primaryFieldName, ' = ', CONCAT(itemID, ')', NULL))));

    RETURN IF(actValue = NULL OR (CHAR_LENGTH(actValue) = 0), sqlString, actValue);
END;

However this gives me a syntax error can anyone help please ? I'm not sure what I'm doing wrong since I followed the online documentation

2
  • 3
    The actual error returned would help. Commented Nov 23, 2011 at 13:21
  • I'm sure, the problem is, that it only tells me to consult the manual :/ Commented Nov 23, 2011 at 13:45

1 Answer 1

1

I don't think that will work if you use only ";" as a separator

The typical is this:

DELIMITER $$

DROP FUNCTION IF EXISTS mytest $$ CREATE FUNCTION mytest () RETURNS INT BEGIN

select ...... ;

insert ...... ;

END $$

DELIMITER ;

Sign up to request clarification or add additional context in comments.

1 Comment

yep it worked thanks. Although Now I have a new error: "Error Code: 1418. This function has none of DETERMINISTIC, NO SQL, or READS SQL DATA in its declaration and binary logging is enabled (you might want to use the less safe log_bin_trust_function_creators variable)"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.