根据对 table 列的查询,Sp 到 return 序列号字符串
Sp to return string of sequence numbers based on query against table column
我正在开发一个接受两个输入的程序(ID(例如12345
),要输出的批号数量(例如5
))
并从序列 (??) 或其他方式输出值到 return(例如 '01'、'02'、'03'、'04'、'05' ).
该输出基于对 table 中的新 batch_id 列的查找,该列的初始值默认为“1”(并且 table 已经更改后有一列 ID)。随着客户端应用程序不断调用 SP,此列会递增到每个 ID ('12345') 的最后一个输出 ('05') 的最大值。我有以下代码使用这样的序列获取下一个批号:
select btchnum_seq.nextval seq_num
from dual
connect by level <= in_total_batches;
其中 in_total_batches 是上面提到的参数中的第二个。
- 我如何将它与 table 中实际上保持最后一个 运行 之后的最大值的列相关联?
- 我将如何输出这 5 个值?作为一个字符串?如果上面的 select 在游标中,我将如何显示记录?
- 我如何获取输出的最大值并将 table 列更新为末尾的那个值?
谢谢大家
听起来你想要这样的东西(未经测试)。如果您曾经在多用户环境中使用它,请注意您可能会在不同的会话中获得相同的返回值,并且您可能会在调用中多次返回相同的值。
create table batch (
batch_id integer primary key,
last_val integer not null
);
insert into batch( batch_id, last_val )
values( 12345, 0 );
create procedure get_next_values( p_batch_id IN batch.batch_id%type,
p_num_vals IN integer,
p_values OUT varchar2 )
as
l_start_val integer;
begin
select last_val
into l_start_val
from batch
where batch_id = p_batch_id;
update batch
set last_val = last_val + p_num_vals
where batch_id = p_batch_id;
select listagg( last_val + level, ',' )
within group( order by level )
into p_values
from dual
connect by level <= p_num_vals;
end;
我正在开发一个接受两个输入的程序(ID(例如12345
),要输出的批号数量(例如5
))
并从序列 (??) 或其他方式输出值到 return(例如 '01'、'02'、'03'、'04'、'05' ).
该输出基于对 table 中的新 batch_id 列的查找,该列的初始值默认为“1”(并且 table 已经更改后有一列 ID)。随着客户端应用程序不断调用 SP,此列会递增到每个 ID ('12345') 的最后一个输出 ('05') 的最大值。我有以下代码使用这样的序列获取下一个批号:
select btchnum_seq.nextval seq_num
from dual
connect by level <= in_total_batches;
其中 in_total_batches 是上面提到的参数中的第二个。
- 我如何将它与 table 中实际上保持最后一个 运行 之后的最大值的列相关联?
- 我将如何输出这 5 个值?作为一个字符串?如果上面的 select 在游标中,我将如何显示记录?
- 我如何获取输出的最大值并将 table 列更新为末尾的那个值?
谢谢大家
听起来你想要这样的东西(未经测试)。如果您曾经在多用户环境中使用它,请注意您可能会在不同的会话中获得相同的返回值,并且您可能会在调用中多次返回相同的值。
create table batch (
batch_id integer primary key,
last_val integer not null
);
insert into batch( batch_id, last_val )
values( 12345, 0 );
create procedure get_next_values( p_batch_id IN batch.batch_id%type,
p_num_vals IN integer,
p_values OUT varchar2 )
as
l_start_val integer;
begin
select last_val
into l_start_val
from batch
where batch_id = p_batch_id;
update batch
set last_val = last_val + p_num_vals
where batch_id = p_batch_id;
select listagg( last_val + level, ',' )
within group( order by level )
into p_values
from dual
connect by level <= p_num_vals;
end;