gpt4 book ai didi

mysql - 如何生成随机代码,并多次运行sql

转载 作者:行者123 更新时间:2023-11-29 14:12:35 25 4
gpt4 key购买 nike

我有一个需要运行的查询,但有两个问题。

首先是我的查询:

INSERT INTO  `anzie_oscommerce`.`discount_codes` (
`discount_codes_id` ,
`discount_description` ,
`products_id` ,
`categories_id` ,
`manufacturers_id` ,
`excluded_products_id` ,
`customers_id` ,
`orders_total` ,
`order_info` ,
`exclude_specials` ,
`discount_codes` ,
`discount_values` ,
`minimum_order_amount` ,
`expires_date` ,
`number_of_orders` ,
`number_of_use` ,
`number_of_products` ,
`status`
)
VALUES (
'' , 'GALA 2012', '' , '' , '' , '' , '' , '2', '1', '0', substr(md5(uniqid(rand(), true)), 0, 8), 250, '0.0000', '2013-22-06', '0', '1', '0', '1'
);

第一个问题是我需要生成随机代码,我试图使用从 php 获取的 uniqid 函数来生成随机代码,但我知道这是不可能的。有没有办法在sql中做类似的事情?

第二个问题是我需要运行 250 次才能生成 250 个不同的折扣代码。有没有一种快速的方法可以多次运行一条sql?

最佳答案

对于第一个问题:这取决于您使用的数据库。 Mysql有一个rand()函数:https://dev.mysql.com/doc/refman/5.0/en/mathematical-functions.html#function_rand

对于第二个:250 对于数据库来说并不多 - 只需将其放入 php for 循环中很可能就可以了。

关于mysql - 如何生成随机代码,并多次运行sql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13225824/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com