如何创建将自动创建序列ID的触发器
我一直在尝试实施逻辑。但仅是关于SQL的基本知识。
我有以下下表
create upload
(
fileblob blob,
mimetype varchar2(4000 char),
filename varchar2(4000 char),
createddate date,
getsequence varchar2(4000 char)
)
我在其中有以下数据
fileblob,mimetype,filename,createddate,getsequeence
(BLOB) ,text/plain , ABC.txt , 12-JULY-19
(BLOB) ,text/plain , XYZ.txt , 13-JULY-19
(BLOB) ,text/plain , HTC.txt , 14-JULY-19
(BLOB) ,text/plain , LKG.txt , 15-JULY-19
我需要在执行插入的情况下,根据create> createDate
> 序列应自动插入到序列列中以获得相应的记录。
预期输出:
fileblob,mimetype,filename,createddate,getsequeence
(BLOB) ,text/plain , ABC.txt , 12-JULY-22,20220712_002414
(BLOB) ,text/plain , XYZ.txt , 13-JULY-22,20220713_003513
(BLOB) ,text/plain , HTC.txt , 14-JULY-22,20220714_004510
(BLOB) ,text/plain , LKG.txt , 15-JULY-22,20220715_001711
序列将就像yyyymmdd_hhmmss
它来自createDate
,因为它设置为date
。我将插入前4列,最后一列数据应通过触发本身插入CreateDate
列的基础。
此4列数据是从我的Oracle Apex
Web应用程序中填充的
I have been trying to implement the logic. But as only basic knowledge on SQL.
I have a below following table
create upload
(
fileblob blob,
mimetype varchar2(4000 char),
filename varchar2(4000 char),
createddate date,
getsequence varchar2(4000 char)
)
I have following data in it
fileblob,mimetype,filename,createddate,getsequeence
(BLOB) ,text/plain , ABC.txt , 12-JULY-19
(BLOB) ,text/plain , XYZ.txt , 13-JULY-19
(BLOB) ,text/plain , HTC.txt , 14-JULY-19
(BLOB) ,text/plain , LKG.txt , 15-JULY-19
I need to write some trigger as soon as the insert is performed depending upon createddate
a sequence should be automatically inserted to sequence column for respective record.
Expected output :
fileblob,mimetype,filename,createddate,getsequeence
(BLOB) ,text/plain , ABC.txt , 12-JULY-22,20220712_002414
(BLOB) ,text/plain , XYZ.txt , 13-JULY-22,20220713_003513
(BLOB) ,text/plain , HTC.txt , 14-JULY-22,20220714_004510
(BLOB) ,text/plain , LKG.txt , 15-JULY-22,20220715_001711
The sequence will be like YYYYMMDD_HHMMSS
it comes from createddate
as it is set to date
. I will insert first 4 columns and last column data should be inserted base on createddate
column by trigger itself.
This 4 column data is populated from my Oracle APEX
web application using form
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您没有序列列,因为如果两个行具有相同的
createDate
,则仍然可以具有非唯一值。相反,您只有一个格式的日期。在这种情况下,只需将列转换为虚拟列:如果您确实想要一个序列值(所有值都是唯一的),那么,从Oracle 12中,您可以使用身份列:
You don't have a sequence column as you can still have non-unique values if two rows have the same
createddate
. Instead, you just have a formatted date. In this case, just convert the column to a virtual column:If you do want a sequence value (where all the values are unique) then, from Oracle 12, you can use an identity column: