Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6845069
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:27:18+00:00 2026-05-27T00:27:18+00:00

mysql> CREATE FUNCTION test () -> RETURNS CHAR(16) -> NOT DETERMINISTIC -> BEGIN ->

  • 0
mysql> CREATE FUNCTION test ()
    -> RETURNS CHAR(16)
    -> NOT DETERMINISTIC
    -> BEGIN
    -> RETURN 'IWantThisText';
    -> END$$
Query OK, 0 rows affected (0.00 sec)

mysql> SELECT test();
+------------------+
|    test()        |
+------------------+
| IWantThisText    | 
+------------------+
1 row in set (0.00 sec)

mysql> UPDATE `table`
    -> SET field = test()
    -> WHERE id = 1
Query OK, 1 row affected, 1 warning (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 1

mysql> SHOW WARNINGS;
+---------+------+----------------------------------------------------------------+
| Level   | Code | Message                                                        |
+---------+------+----------------------------------------------------------------+
| Warning | 1265 | Data truncated for column 'test' at row 1                      | 
+---------+------+----------------------------------------------------------------+
1 row in set (0.00 sec)


mysql> SELECT field FROM table WHERE id = 1;
+------------------+
| field            |
+------------------+
| NULL             | 
+------------------+
1 row in set (0.00 sec)

What I am doing wrong? I just want field to be set to the returned value of test()
Forgot to mention field is VARCHR(255)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T00:27:18+00:00Added an answer on May 27, 2026 at 12:27 am

    (Not a real answer, but too long for a comment)
    Can you please try this self-contained example?

    use test;
    CREATE TEMPORARY TABLE soFoo (id int auto_increment, field varchar(255), primary key(id));
    delimiter $$
    CREATE FUNCTION soTest ()
    RETURNS CHAR(16)
    NOT DETERMINISTIC
    BEGIN
        RETURN 'IWantThisText';
    END$$
    delimiter ;
    INSERT INTO soFoo (field) VALUES ('abc'),(NULL);
    UPDATE `soFoo` SET field = soTest() WHERE id = 1;
    UPDATE `soFoo` SET field = soTest() WHERE id = 2;
    SELECT * FROM soFoo;
    

    works fine on my machine:

    C:\web\xampp\mysql\bin>mysql -u volker -p
    Enter password: ***************
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 7
    Server version: 5.5.8 MySQL Community Server (GPL)
    
    Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
    
    Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates. Other names may be trademarks of their respective
    owners.
    
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    
    mysql> use test;
    Database changed
    mysql> CREATE TEMPORARY TABLE soFoo (id int auto_increment, field varchar(255), primary key(id));
    Query OK, 0 rows affected (0.00 sec)
    
    mysql> delimiter $$
    mysql> CREATE FUNCTION soTest ()
        -> RETURNS CHAR(16)
        -> NOT DETERMINISTIC
        -> BEGIN
        ->  RETURN 'IWantThisText';
        -> END$$
    Query OK, 0 rows affected (0.00 sec)
    
    mysql> delimiter ;
    mysql> INSERT INTO soFoo (field) VALUES ('abc'),(NULL);
    Query OK, 2 rows affected (0.00 sec)
    Records: 2  Duplicates: 0  Warnings: 0
    
    mysql> UPDATE `soFoo` SET field = soTest() WHERE id = 1;
    Query OK, 1 row affected (0.00 sec)
    Rows matched: 1  Changed: 1  Warnings: 0
    
    mysql> UPDATE `soFoo` SET field = soTest() WHERE id = 2;
    Query OK, 1 row affected (0.00 sec)
    Rows matched: 1  Changed: 1  Warnings: 0
    
    mysql> SELECT * FROM soFoo;
    
    +----+---------------+
    | id | field         |
    +----+---------------+
    |  1 | IWantThisText |
    |  2 | IWantThisText |
    +----+---------------+
    2 rows in set (0.00 sec)
    
    mysql>
    

    And which server version do you use?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the following tsql... create function dbo.wtfunc(@s varchar(50)) returns varchar(10) begin return left(@s, 2);
I'm trying to create a simple database table using the PHP MySQL query Create
For some reason, this MySQL fails: CREATE SCHEMA IF NOT EXISTS `partB` DEFAULT CHARACTER
In this MySQL table definition: CREATE TABLE groups ( ug_main_grp_id smallint NOT NULL default
am making function to count rows using WHERE, but i get a mysql error
For MySQL, I want a query that returns a SUM of an expression, EXCEPT
I'm trying to create a MySQL function with multiple inputs, but keep getting an
I see that within MySQL there are Cast() and Convert() functions to create integers
I have a members table in MySQL CREATE TABLE `members` ( `id` int(10) unsigned
I want to implement the following constraints in mysql: create table TypeMapping( ... constraint

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.