Results 1 to 1 of 1
  1. #1
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    161

    Unanswered: Not able to assign variable without using SET

    PHP Code:
    DROP FUNCTION IF EXISTS `foo`;
    DELIMITER $$$
    CREATE FUNCTION `foo`(n INTRETURNS VARCHAR(100NO SQL
    BEGIN
           
    DECLARE asciir INT;
           
    SET r FLOOR(RAND() * 35);

           IF 
    10 THEN
              SET ascii 
    48;
           ELSE
              
    SET ascii 65;
           
    END IF;

           RETURN 
    ascii;
    END $$$
    DELIMITER 
    Based on the manual, setting a variable without using the SET command should work.
    But I cant seem to do ascii = r + 48; - never works. I have to use SET.
    Why do I need to use the SET keyword to make it work ?

    PHP Code:
    DROP FUNCTION IF EXISTS `foo`;
    DELIMITER $$$
    CREATE FUNCTION `foo`(n INTRETURNS VARCHAR(100NO SQL
    BEGIN
           
    DECLARE asciir INT;
           
    FLOOR(RAND() * 35);

           IF 
    10 THEN
              ascii 
    48;
           ELSE
              
    ascii 65;
           
    END IF;

           RETURN 
    ascii;
    END $$$
    DELIMITER 
    MySQL 5.0.45-community-nt
    Last edited by anjanesh; 03-13-08 at 10:28.
    MySQL 5.1

Posting Permissions

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