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

Analysis of the difference between absolute path and relative path in HTML

As shown in the figure: There are many files conne...

MySQL Error 1290 (HY000) Solution

I struggled with a problem for a long time and re...

Ubuntu 16.04 mysql5.7.17 open remote port 3306

Enable remote access to MySQL By default, MySQL u...

How to solve the problem of character set when logging in to Linux

Character set error always exists locale: Cannot ...

MySQL dual-machine hot standby implementation solution [testable]

Table of contents 1. Concept 2. Environmental Des...

JS implements random generation of verification code

This article example shares the specific code of ...

How to notify users of crontab execution results by email

symptom I set a crontab task on a centos7 host, b...

How to install ROS Noetic in Ubuntu 20.04

Disclaimer: Since the project requires the use of...

TypeScript union types, intersection types and type guards

Table of contents 1. Union Type 2. Crossover Type...

js to achieve image fade-in and fade-out effect

This article shares the specific code of js to ac...