我在oracle表中具有以下值之一的列:
select csv_val from my_table where date='09-OCT-18';
output
==================
50,100,25,5000,1000
我希望此值在选择查询中按升序排列,输出看起来像:
output
==================
25,50,100,1000,5000
我尝试了this链接,但看起来它对数字位数有一些限制。
答案 0 :(得分:0)
在这里,我为您提供了链接的答案的修改版本,该答案可以处理任意数量(硬编码)的逗号。 CTE非常繁重。与大多数LISTAGG答案一样,它的上限为4000个字符。我还更改了您的正则表达式,使其能够处理空列表条目based on this answer。
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>HTML Forms</title>
<style>
.container{
width: 45%;
margin: auto;
}
.form-content{
margin: 40px;
}
.form-content input{
width: 100%;
}
label{
font-weight: bold;
}
input[type=text],[type=email],[type=tel],[type=date],[type=password]{
font-size: 16px;
border-radius: 5px;
background: #D9F1F7;
border: #000000;
padding: 10px;
}
input[type=submit]{
background: #4C63ED;
padding: 10px;
border: none;
border-radius: 5px;
font-size: 16px;
color: #fff;
cursor: pointer;
}
input[type=submit]:hover{
background: #330EEF;
font-weight: bold;
}
</style>
</head>
<body>
<div class = "container">
<form name="signup" method="get" action="">
<div class="form-content">
<label>First Name : </label>
<input type="text" name="firstname" />
</div>
<div class="form-content">
<label>Last Name : </label>
<input type="text" name="lastname" />
</div>
<div class="form-content">
<label>E-Mail : </label>
<input type="email" name="email" />
</div>
<div class="form-content">
<label>Telephone : </label>
<input type="tel" name="telephone" />
</div>
<div class="form-content">
<label>Date of Birth : </label>
<input type="date" name="dob" />
</div>
<div class="form-content">
<input type="submit" name="submit" value="Submit" />
</div>
</form>
</div>
</body>
</html>
可能可以改进,但是...
答案 1 :(得分:0)
根据您发布的样本数据,可以使用相对简单的查询(您需要第3-7行)。如果数据看起来并非如此,则可能需要调整查询。
SQL> with my_table (csv_val) as
2 (select '50,100,25,5000,1000' from dual)
3 select listagg(token, ',') within group (order by to_number(token)) result
4 from (select regexp_substr(csv_val, '[^,]+', 1, level) token
5 from my_table
6 connect by level <= regexp_count(csv_val, ',') + 1
7 );
RESULT
-------------------------
25,50,100,1000,5000
SQL>