V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
MySQL 5.5 Community Server
MySQL 5.6 Community Server
Percona Configuration Wizard
XtraBackup 搭建主从复制
Great Sites on MySQL
Percona
MySQL Performance Blog
Severalnines
推荐管理工具
Sequel Pro
phpMyAdmin
推荐书目
MySQL Cookbook
MySQL 相关项目
MariaDB
Drizzle
参考文档
http://mysql-python.sourceforge.net/MySQLdb.html
Routeros
V2EX  ›  MySQL

求一行 sql

  •  
  •   Routeros · 2021-09-04 20:56:45 +08:00 · 1695 次点击
    这是一个创建于 937 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

    要求:
    随机选择 codeB 中的一个 给表格 A 的 codeA 字段。
    
    比如表格 A 有一百行,就随机一百次 codeB 列给 codeA 即可。。
    
    ReferenceE
        1
    ReferenceE  
       2021-09-04 21:24:14 +08:00 via Android   ❤️ 2
    产品请去找自己公司的程序员(🐶
    fiypig
        2
    fiypig  
       2021-09-04 22:32:06 +08:00 via iPhone
    随机插入 a 是吧,不难
    liuguangxuan
        3
    liuguangxuan  
       2021-09-04 22:38:59 +08:00 via Android
    啊,这…
    auh
        4
    auh  
       2021-09-04 22:42:17 +08:00
    挺好,能不能一行 sql 帮我实现一下人生巅峰
    xmtpw
        5
    xmtpw  
       2021-09-05 00:05:14 +08:00 via iPhone
    给你,一行 sql
    KKLeon
        6
    KKLeon  
       2021-09-05 00:13:53 +08:00 via Android
    sqlsqlsqlsqlsqlsqlsql🐶
    Routeros
        7
    Routeros  
    OP
       2021-09-05 00:27:06 +08:00
    纯讨论,可以不说,没必要瞎指点。抖机灵更没 6
    wunonglin
        8
    wunonglin  
       2021-09-05 00:29:36 +08:00
    sql := "一行 sql"
    Routeros
        9
    Routeros  
    OP
       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;
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2839 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 789ms · UTC 14:31 · PVG 22:31 · LAX 07:31 · JFK 10:31
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.