如何有效地将大(1米到5米记录)表的内容混洗?已知该列具有唯一值,但您可以假设为此目的删除了所有约束。我的头痛主要是因为我正在更新我选择的同一列。我的目标是使用PL / SQL执行此操作,以便我可以通过编程方式执行其他操作,例如记录或更新其他表。
character
我最近的尝试是创建一个使用**Original table:**
+----+-----------+
| id | fname |
+----+-----------+
| 1 | mike |
| 2 | ricky |
| 3 | jane |
| 4 | august |
| 6 | dave |
| 9 | Jérôme |
+----+-----------+
**Possible output:**
+----+-----------+
| id | fname |
+----+-----------+
| 1 | dave |
| 2 | jane |
| 3 | mike |
| 4 | ricky |
| 6 | Jérôme |
| 9 | august |
+----+-----------+
的游标,并尝试根据rownum进行合并或更新。也许我可以通过创建各种临时表来绕过修改自我约束?我相当自信Oracle有一些奇特的方法可以做到这一点,但我的SQL能力有限于基本的CRUD命令。
根据戈登的回答,完整的解决方案就在这里:
over (order by dbms_random.value)
答案 0 :(得分:2)
您可以使用随机行号进行自联接:
select t.id, t2.name
from (select t.*, row_number() over (order by dbms_random.value) as seqnum
from t
) t join
(select t.*, row_number() over (order by dbms_random.value) as seqnum
from t
) t2
on t.seqnum = t2.seqnum;
实际上,你不需要两者都是随机的:
select t.id, t2.name
from (select t.*, rownum as seqnum
from t
) t join
(select t.*, row_number() over (order by dbms_random.value) as seqnum
from t
) t2
on t.seqnum = t2.seqnum;
答案 1 :(得分:2)
直接从这个答案中获取(这是我的,所以我相信我可以重复使用它): https://community.oracle.com/thread/3995265
<强>制备强>
<?php
//make connection
mysqli_connect('localhost', 'root', '');
//select db
mysqli_select_db('altislife-dev');
$sql="SELECT * FROM players";
$records=mysqli_query($sql);
?>
<html>
<head>
<title>Data</title>
</head>
<body>
<table width="600" border="1" cellpadding="1" cellspacing="1">
<tr>
<th>uid</th>
<th>name</th>
<th>aliases</th>
<th>playerid</th>
<th>cash</th>
<th>bankacc</th>
<th>coplevel</th>
<tr>
<?php
while($players=mysqli_fetch_assoc($records)) {
echo "<tr>";
echo "<td>".$players['uid']."</td>";
echo "<td>".$players['name']."</td>";
echo "<td>".$players['aliases']."</td>";
echo "<td>".$players['playerid']."</td>";
echo "<td>".$players['cash']."</td>";
echo "<td>".$players['bankacc']."</td>";
echo "<td>".$players['coplevel']."</td>";
echo "</tr>";
}
?>
</table>
</body>
</html>
使用置换名称更新行:
create table original_table ( id number, name varchar2(30) );
insert into original_table
select 1, 'mike' from dual union all
select 2, 'ricky' from dual union all
select 3, 'jane' from dual union all
select 4, 'august' from dual union all
select 6, 'dave' from dual union all
select 9, 'Jérôme' from dual
;
select * from original_table;
ID NAME
-- ------
1 mike
2 ricky
3 jane
4 august
6 dave
9 Jérôme