Example of how to generate random numbers and concatenate strings in MySQL

Example of how to generate random numbers and concatenate strings in MySQL

This article uses an example to describe how MySQL generates random numbers and concatenates strings. Share with you for your reference, the details are as follows:

Methods used:

concat('a','b','c'); connect string

rand(); Generate random numbers

floor(); take the integer

SQL statement example:

Copy the code as follows:
UPDATE user set reg_ip = concat(floor(RAND() * 250),'.',floor(RAND() * 250),'.',floor(RAND() * 250),'.',floor(RAND() * 250)) where username = 'xxx'

PS: Here are two commonly used SQL online tools for your reference (including SQL statement usage instructions):

SQL online compression/formatting tool:
http://tools.jb51.net/code/sql_format_compress

SQL code online formatting and beautification tool:
http://tools.jb51.net/code/sqlcodeformat

In addition: I would like to recommend an online random number tool for your reference:

Online random number/string generation tool:
http://tools.jb51.net/aideddesign/suijishu

Readers who are interested in more MySQL-related content can check out the following topics: "Summary of MySQL Common Functions", "Summary of MySQL Log Operation Skills", "Summary of MySQL Transaction Operation Skills", "Summary of MySQL Stored Procedure Skills" and "Summary of MySQL Database Lock-Related Skills".

I hope this article will be helpful to everyone's MySQL database design.

You may also be interested in:
  • MySQL Query Random Data 4 Methods and Performance Comparison
  • Tips for using MySQL's specified range random number function rand()
  • Code to extract random data from MySQL database table
  • How to get random data in mysql
  • MySQL optimizes the slow method of fetching random data
  • mysql insert a random number into a field (insert a random number into the MySQL database)
  • Detailed explanation of the usage of the concat function in MySQL (connecting strings)
  • Python connects to MySQL and uses fetchall() method to filter special characters
  • sqlserver, mysql connection string steps
  • How to set MySQL connection character set in PHP

<<:  Mini Programs enable product attribute selection or specification selection

>>:  How to manually build a new image with docker

Recommend

Three Ways to Find the Longest Word in a String in JavaScript (Recommended)

This article is based on the Free Code Camp Basic...

Install Centos7 using Hyper-v virtual machine

Table of contents introduce Prepare Download syst...

A must-read career plan for web design practitioners

Original article, please indicate the author and ...

Tutorial on installing mysql5.7.18 on windows10

This tutorial shares the installation and configu...

A detailed introduction to the basics of Linux scripting

Table of contents 1. Script vim environment 2. Ho...

Configure Java development environment in Ubuntu 20.04 LTS

Download the Java Development Kit jdk The downloa...

How to use node scaffolding to build a server to implement token verification

content Use scaffolding to quickly build a node p...

Detailed installation tutorial of mysql 5.7.11 under Win7 system

Operating system: Win7 64-bit Ultimate Edition My...

Detailed explanation of client configuration for vue3+electron12+dll development

Table of contents Modify the repository source st...

Detailed analysis of the chmod command to modify file permissions under Linux

Use the Linux chmod command to control who can ac...