在Oracle中为varchar2字段创建序列 [英] Creating a sequence for a varchar2 field in Oracle
问题描述
我想为这个varchar创建一个序列。这本来是更容易,如果它是一个数字,而不是varchar。在这种情况下,我可以执行
seq_no:= seq_no + 1;
但是,当我想将列中的下一个值存储为A0000002时,当前一个值为A0000001(以便在下一个varchar row中增加1)时,该怎么办?
$这可以通过to_char(seq_no,'FM0000000')来完成。b $ b
)。
您可以在oracle中创建序列 创建序列seq_no以1增量1开始;
然后
select'A'|| to_char(seq_no.nextval,'FM0000000')from dual;
现在我已经使用了双重.. ..这里
'A '|| to_char(seq_no.nextval,'FM0000000')
。
I want to create a sequence for this varchar. It would have been easier had it been a number instead of varchar. In that case, I could do
seq_no := seq_no + 1;
But what can I do when I want to store next value in column as A0000002, when the previous value was A0000001 (to increment the number in the next varchar rowby 1)?
this can be done by
to_char(seq_no,'FM0000000')..
your example can be done by creating sequence in oracle
create sequence seq_no start with 1 increment by 1;
then
select 'A'||to_char(seq_no.nextval,'FM0000000') from dual;
right now i have used in dual ..but place this 'A'||to_char(seq_no.nextval,'FM0000000') in your required query ..this will create sequence as you mentioned
这篇关于在Oracle中为varchar2字段创建序列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!