declare @t table(col nvarchar(4)) insert @t select nchar(cast(19968+rand()*40868 as int)) insert @t select nchar(cast(19968+rand()*40868 as int)) insert @t select nchar(cast(19968+rand()*40868 as int)) select * from @t 能插入所有漢字範圍包括繁體在 MSSQL下 .
倒是有这么个转法: mysql> select cast((conv(cast((19968.0 + rand()*40868) as signed int), 10, 16)) as nchar); +-----------------------------------------------------------------------------+ | cast((conv(cast((19968.0 + rand()*40868) as signed int), 10, 16)) as nchar) | +-----------------------------------------------------------------------------+ | E6D3 | +-----------------------------------------------------------------------------+ 1 row in set (0.00 sec)
mysql> select unhex(hex(19968+rand()*40868)); +--------------------------------+ | unhex(hex(19968+rand()*40868)) | +--------------------------------+ | 曜 | +--------------------------------+ 1 row in set (0.00 sec)mysql>
设计的表如下:create table table1(username varchar(20) ,addtime datetime,id int) 创建存储过程如下: create PROCEDURE d() BEGIN declare i int; set i=0; while i<1000 do insert into table1(addtime,id) values(NOW(),i); set i=i+1; end while; END 我想让这表随机插入用户名USERNAME 结果没做出来
declare @t table(col nvarchar(4))
insert @t select nchar(cast(19968+rand()*40868 as int))
insert @t select nchar(cast(19968+rand()*40868 as int))
insert @t select nchar(cast(19968+rand()*40868 as int))
select * from @t
能插入所有漢字範圍包括繁體在 MSSQL下 .
mysql> select cast((conv(cast((19968.0 + rand()*40868) as signed int), 10, 16)) as nchar);
+-----------------------------------------------------------------------------+
| cast((conv(cast((19968.0 + rand()*40868) as signed int), 10, 16)) as nchar) |
+-----------------------------------------------------------------------------+
| E6D3 |
+-----------------------------------------------------------------------------+
1 row in set (0.00 sec)
+--------------------------------+
| unhex(hex(19968+rand()*40868)) |
+--------------------------------+
| 曜 |
+--------------------------------+
1 row in set (0.00 sec)mysql>
,addtime datetime,id int) 创建存储过程如下:
create PROCEDURE d()
BEGIN
declare i int;
set i=0;
while i<1000 do
insert into table1(addtime,id) values(NOW(),i);
set i=i+1;
end while;
END
我想让这表随机插入用户名USERNAME 结果没做出来
MySQL 中文显示乱码
这段语句可以把字符集改成中文.
+--------------------------------+
| unhex(hex(19968+rand()*40868)) |
+--------------------------------+
| |
+--------------------------------+
1 row in set
还是一片空白
+--------------------------------+
| unhex(hex(19968+rand()*40868)) |
+--------------------------------+
| T |
+--------------------------------+
1 row in set (0.00 sec)mysql> select unhex(hex(19968+rand()*40868));
+--------------------------------+
| unhex(hex(19968+rand()*40868)) |
+--------------------------------+
| ? |
+--------------------------------+
1 row in set (0.00 sec)mysql> select unhex(hex(19968+rand()*40868));
+--------------------------------+
| unhex(hex(19968+rand()*40868)) |
+--------------------------------+
| 扗 |
+--------------------------------+
1 row in set (0.00 sec)有点意思,不过总出问号