dcsimg
Results 1 to 5 of 5

Thread: MYSQL - Function Not working

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2017
    Posts
    52

    MYSQL - Function Not working

    Hi All

    I have written a function in Mysql and it is returning nothing and i cannot see what the problem is.
    I have simplified it to test it and it still returns nothing


    Code:
    CREATE DEFINER = 'root'@'localhost' FUNCTION `test`()
        RETURNS char(10) CHARSET latin1
        NOT DETERMINISTIC
        CONTAINS SQL
        SQL SECURITY DEFINER
        COMMENT ''
    BEGIN
    DECLARE documentnumber CHAR(12);
    SET documentnumber='ABC456789012';
    RETURN CAST(document_number AS CHAR(12));
    END;
    Any help would be greatly appreciated

  2. #2

    Thread Starter
    Member
    Join Date
    Jan 2017
    Posts
    52

    Re: MYSQL - Function Not working

    apologies code should be:

    Code:
    CREATE DEFINER = 'root'@'localhost' FUNCTION `test`()
        RETURNS char(12) CHARSET latin1
        NOT DETERMINISTIC
        CONTAINS SQL
        SQL SECURITY DEFINER
        COMMENT ''
    BEGIN
    DECLARE documentnumber CHAR(12);
    SET documentnumber='123456789012';
    RETURN CAST(document_number AS CHAR(12));
    END;

  3. #3

    Thread Starter
    Member
    Join Date
    Jan 2017
    Posts
    52

    Re: MYSQL - Function Not working

    apologies code should be:

    Code:
    CREATE DEFINER = 'root'@'localhost' FUNCTION `test`()
        RETURNS char(12) CHARSET latin1
        NOT DETERMINISTIC
        CONTAINS SQL
        SQL SECURITY DEFINER
        COMMENT ''
    BEGIN
    DECLARE documentnumber CHAR(12);
    SET documentnumber='123456789012';
    RETURN CAST(document_number AS CHAR(12));
    END;

  4. #4

    Thread Starter
    Member
    Join Date
    Jan 2017
    Posts
    52

    Re: MYSQL - Function Not working

    Apologies once again, i have just seen my mistake document_number and documentnumber!!!

  5. #5
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    32,381

    Re: MYSQL - Function Not working

    No apologies need, sometimes that's all we need... It's called the Rubber Duck Effect. I can;t begin to count the number of times I've started a post here, only to realize the answer to the problem... sometimes it happens as I'm writing out the post, sometimes it doesn't happen until just after I've hit the Submit button, sometimes, it happens a little while after. I host 4 hours one day because I had a folder named plugins instead of plugin ... in the past week alone, another 6 hours because of a single missing annotation on a function. It's almost always that simple thing that trips us up.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width