with data(order_num, qty) as (
select '34905', 2 from dual union all
select '39754', 5 from dual
)
select order_num || '-' || level as newsequence
from data
connect by level <= qty and prior order_num = order_num
and prior sys_guid() is not null
;
with data(order_num, qty) as (
select '34905', 2 from dual union all
select '39754', 5 from dual
)
select order_num ||'-'|| column_value as new_sequence
from data,
lateral
(
select level as column_value from dual
connect by level <= qty
);
with num(n) as ( values (1),(2),(3),(4),(5))
select o.orderno || '-' || cast(num.n as varchar(2))
from num
join orders o
on o.qty >= num.n
order by o.orderno, n;
insert into numbers (n)
select 1 from dual
union all
select 2 from dual
union all
select 3 from dual
union all
select 4 from dual
union all
select 5 from dual;
型 您可以将查询编写为:
select o.orderno || '-' || cast(numbers.n as varchar(2))
from numbers
join orders o
on o.qty >= numbers.n
order by o.orderno, n;
3条答案
按热度按时间wgeznvg71#
你有很多基于验证方式的变体:
字符串
...
gzjq41n42#
你将需要一个域来生成序列。这里我使用了一个带有常量的cte,你可以使用1和max qty之间的递归cte(或者你有这样的数字表):
字符串
Fiddle
使用数字表,如
型
您可以将查询编写为:
型
ckocjqey3#
这是某种类型的行生成器,正如你已经被告知的那样。在 * 较低 * Oracle数据库版本(我的意思是低于23c)中工作的版本是:
样本数据:
字符串
查询:
型