求一行 sql

2021-09-04 20:56:45 +08:00
 Routeros

如果可以的话我提一个要求就是希望这个 sql 能在 mysql 和 oracle 上使用。 目前有如下两个表: tableA 字段众多,其中一个是 codeA 。 tableB 就两个字段,一个是 id:1 、2 、3 、4 、5.... 另一个是 codeB:6 位数字。 tableA 、tableB 无任何关联....

要求:
随机选择 codeB 中的一个 给表格 A 的 codeA 字段。

比如表格 A 有一百行,就随机一百次 codeB 列给 codeA 即可。。
1721 次点击
所在节点    MySQL
9 条回复
ReferenceE
2021-09-04 21:24:14 +08:00
产品请去找自己公司的程序员(🐶
fiypig
2021-09-04 22:32:06 +08:00
随机插入 a 是吧,不难
liuguangxuan
2021-09-04 22:38:59 +08:00
啊,这…
auh
2021-09-04 22:42:17 +08:00
挺好,能不能一行 sql 帮我实现一下人生巅峰
xmtpw
2021-09-05 00:05:14 +08:00
给你,一行 sql
KKLeon
2021-09-05 00:13:53 +08:00
sqlsqlsqlsqlsqlsqlsql🐶
Routeros
2021-09-05 00:27:06 +08:00
纯讨论,可以不说,没必要瞎指点。抖机灵更没 6
wunonglin
2021-09-05 00:29:36 +08:00
sql := "一行 sql"
Routeros
2021-09-05 23:22:23 +08:00
create or replace procedure proc_random_records_test is
v_cur_count int := 0;
v_cur_random int;
v_cur_seq_row rowid;
begin
for item in (select rowid from yangsonglin1) loop
v_cur_seq_row := item.rowid;
select code2
into v_cur_random
from (select code2
from yangsonglin2
order by dbms_random.value)
where rownum <= 1;
update yangsonglin1
set code1 = v_cur_random
where rowid = v_cur_seq_row;
if v_cur_count = 0 then
exit;
end if;
dbms_output.put_line('success !');
end loop;
--commit;
end;

begin
proc_random_records_test;
end;

select * from yangsonglin1;

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/799895

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX