如何在PLSQL中使用UPDATE和WITH
有谁有如何在 PLSQL 查询中使用WITH 和 UPDATE 的示例吗?
我狂饮并谷歌搜索但没有成功。
这就是我想做的
WITH
OldRecords AS
(
SELECT 'New Records' as RecordLabel, rowid, OrDev.*
FROM CDR.MSRS_OR_ORDEV OrDev
WHERE 1=1
AND OrDev.ASOFENDDATETIME IS NULL
AND OrDev.REPORTSTARTDATE = to_date ('7/1/2010', 'mm/dd/yyyy')
AND OrDev.REPORTENDDATE = to_date ('7/31/2010', 'mm/dd/yyyy')
AND OrDev.downloadrequestid <> 3
),
NewRecords AS
(
SELECT 'Old Records' as RecordLabelrowid, OrDev.*
FROM CDR.MSRS_OR_ORDEV OrDev
WHERE 1=1
AND OrDev.ASOFENDDATETIME IS NULL
AND OrDev.REPORTSTARTDATE = to_date ('7/1/2010', 'mm/dd/yyyy')
AND OrDev.REPORTENDDATE = to_date ('7/31/2010', 'mm/dd/yyyy')
AND OrDev.downloadrequestid = 3
)
UPDATE CDR.MSRS_OR_ORDEV SET ASOFENDDATETIME = GETDATE()
WHERE RowID IN
(
SELECT OldRecords.RowId
FROM OldRecords
INNER JOIN NewRecords
ON OldRecords.Customer_Id = NewRecords.Customer_Id
AND OldRecords.BusinesKey1 = NewRecords.BusinesKey1
AND OldRecords.BusinesKey2 = NewRecords.BusinesKey2
)
基本上这是一个 II 型维度更新。
Does anyone have a sample of how to use WITH and UPDATE in a query in PLSQL?
I binged and googled without success.
Here is what I am trying to do
WITH
OldRecords AS
(
SELECT 'New Records' as RecordLabel, rowid, OrDev.*
FROM CDR.MSRS_OR_ORDEV OrDev
WHERE 1=1
AND OrDev.ASOFENDDATETIME IS NULL
AND OrDev.REPORTSTARTDATE = to_date ('7/1/2010', 'mm/dd/yyyy')
AND OrDev.REPORTENDDATE = to_date ('7/31/2010', 'mm/dd/yyyy')
AND OrDev.downloadrequestid <> 3
),
NewRecords AS
(
SELECT 'Old Records' as RecordLabelrowid, OrDev.*
FROM CDR.MSRS_OR_ORDEV OrDev
WHERE 1=1
AND OrDev.ASOFENDDATETIME IS NULL
AND OrDev.REPORTSTARTDATE = to_date ('7/1/2010', 'mm/dd/yyyy')
AND OrDev.REPORTENDDATE = to_date ('7/31/2010', 'mm/dd/yyyy')
AND OrDev.downloadrequestid = 3
)
UPDATE CDR.MSRS_OR_ORDEV SET ASOFENDDATETIME = GETDATE()
WHERE RowID IN
(
SELECT OldRecords.RowId
FROM OldRecords
INNER JOIN NewRecords
ON OldRecords.Customer_Id = NewRecords.Customer_Id
AND OldRecords.BusinesKey1 = NewRecords.BusinesKey1
AND OldRecords.BusinesKey2 = NewRecords.BusinesKey2
)
Basically this is a Type-II dimension update.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是如何在 PLSQL 的 UPDATE 中使用WITH。请注意,这仅适用于单列更新。
This is how to use WITH in an UPDATE in PLSQL. Note that this only works for a single column update.
查看 update 和 < 的语法图a href="http://download.oracle.com/docs/cd/B14117_01/server.101/b10759/statements_10002.htm#i2077142" rel="nofollow">选择,我不确定子查询分解可以与更新一起使用。您可以将这些查询完整地替换回 UPDATE 语句的子查询部分,或者您可以为它们创建视图。我会选择观点。
Looking at the syntax diagrams for update and select, I'm not sure the subquery factoring can be used with update. You could either substitute those queries in full back into the subquery part of your UPDATE statement, OR you could create views for them. I'd go with the views.