【问题标题】:Jumble up names in the table column oracle在表列 oracle 中混淆名称
【发布时间】:2021-05-31 06:52:39
【问题描述】:

我的要求是为了混淆目的将 oracle 表中的名称混在一起,如下所示

规则

  1. 同一记录不应具有相同的名称
  2. 应根据性别进行混编
  3. 逻辑应该是完全随机的

员工

ID Name Gender
1 Peter M
2 Pascal M
3 Robin M
4 Stephanie F
5 Arya F

员工-预期

ID Name Gender
1 Robin M
2 Peter M
3 Pascal M
4 Arya F
5 Stephanie F

下面的链接中提到了我到目前为止所尝试的内容,但不知何故我无法修复它,因为数据可能以数百万计 http://sqlfiddle.com/#!4/460bda/5

【问题讨论】:

    标签: sql oracle oracle12c obfuscation


    【解决方案1】:

    您可以使用row_number() 随机化每个性别中的名称:

    select e.*, e2.name as new_name
    from (select e.*,
                 row_number() over (partition by gender order by name) as seqnum
          from employee e
         ) e join
         (select e.*,
                 row_number() over (partition by gender order by dbms_random.random()) as seqnum
          from employee e
         ) e2
         on e.gender = e2.gender and e.seqnum = e2.seqnum;
    

    这并不能保证永远不会重复使用名称。事实上,考虑到其他限制,这是不可能的——一个性别可能只有一个名字。但是,这会随机分配名称,因此不太可能保持相同的名称。

    如果您的姓名可以重复,请使用dense_rank() 而不是row_number()

    Here 是一个 dbfiddle。

    您可以使用“转移”方法避免将名称映射回相同的名称。然而,这种转变是可以撤销的。随机分配重新分配概率很小的名称的解决方案可能更适合混淆。

    【讨论】:

    • 我认为,如果已知名称是出于混淆目的而随机化的,那么尽管有 OP 的规定,偶尔使用“真实”名称也没关系“要求”。
    猜你喜欢
    • 2011-10-17
    • 1970-01-01
    • 1970-01-01
    • 2010-09-27
    • 1970-01-01
    • 2015-07-16
    • 2018-12-11
    • 2018-08-20
    • 1970-01-01
    相关资源
    最近更新 更多