临时表是动态的吗?

时间:2014-07-01 21:48:52

标签: sql ibm-midrange rpgle

我创建了一个模仿RPGLE程序的sql,它在工作过程中显示数据。 我的问题是这段代码是动态的,我不需要做任何事情,或者必须经常运行吗?这会创建一个* PGM对象CLE。

 CREATE table RTRINTx(
    PROGR1PST int, PROGR1PUN int, PROGR1TOD int, PROGR1TUN int, PROGR1TOM int, PROGR1MUN int, 
    LASGR1PST int, LASGR1PUN int, LASGR1TOD int, LASGR1TUN int, LASGR1TOM int, LASGR1MUN int, 
    PCKGR1PST int, PCKGR1PUN int, PCKGR1TOD int, PCKGR1TUN int, PCKGR1TOM int, PCKGR1MUN int, 
    ASSGR1PST int, ASSGR1PUN int, ASSGR1TOD int, ASSGR1TUN int, ASSGR1TOM int, ASSGR1MUN int, 
    SHPGR1PST int, SHPGR1PUN int, SHPGR1TOD int, SHPGR1TUN int, SHPGR1TOM int, SHPGR1MUN int, 
    HLDGR1PST int, HLDGR1PUN int, HLDGR1TOD int, HLDGR1TUN int, HLDGR1TOM int, HLDGR1MUN int);    

-- Engraving Processing
-- Count for Previous Day
Insert into RTRINTx(PROGR1PST)
SELECT count(*) FROM ASTCCDTA.OEORH48,ASTCCDTA.TRNSTAT2,ASTCCDTA.OETRA99  
WHERE OHCOM# = TSCOM# AND OHORD# = TSORD# 
AND (otCOM# = OHCOM# AND OTORD#= OHORD# AND ottrnc = 'AQC')
AND TSSTAT IN('AEP','BGE')  
AND OHORDT IN('RTR','INT','SAM') 
AND OHREQD < replace(char(current date, iso), '-', '')  
AND OHHLDC = ' ' AND OHORD# in(SELECT a.TSORD# FROM ASTCCDTA.TRNSTAT2 a    
WHERE a.tsstat IN('AEP','BGE','EAS','REL','STP'));

-- Quantity Total Previous Day
update RTRINTx set PROGR1PUN = 
(select COALESCE(SUM(OdQty#),0) FROM ASTCCDTA.OEORH48,ASTCCDTA.TRNSTAT2,ASTDTA.OEORD1  
WHERE OHCOM# = TSCOM# AND OHORD# = TSORD# 
AND OHCOM# = ODCOM# AND OHORD# = ODORD#  
AND TSSTAT IN('AEP','BGE')  
AND OHORDT IN('RTR','INT','SAM')  
AND OHREQD < replace(char(current date, iso), '-', '')  
AND OHHLDC = ' '  AND ODPRLC = 'ENG'  
AND substr(odprt#,1,5) <> 'NOENG' 
AND OHORD# in(SELECT a.TSORD# FROM ASTCCDTA.TRNSTAT2 a    
WHERE a.tsstat IN('AEP','BGE','EAS','REL','STP')));

-- Count for Today
Update RTRINTx set PROGR1TOD = 
(SELECT count(*) FROM ASTCCDTA.OEORH48,ASTCCDTA.TRNSTAT2,ASTCCDTA.OETRA99  
WHERE OHCOM# = TSCOM# AND OHORD# = TSORD# 
AND (otCOM# = OHCOM# AND OTORD#= OHORD# AND ottrnc = 'AQC')
AND TSSTAT IN('AEP','BGE')  
AND OHORDT IN('RTR','INT','SAM') 
AND OHREQD = replace(char(current date, iso), '-', '')  
AND OHHLDC = ' ' AND OHORD# in(SELECT a.TSORD# FROM ASTCCDTA.TRNSTAT2 a    
WHERE a.tsstat IN('AEP','BGE','EAS','REL','STP')));

-- Quantity Total Previous Day
Update RTRINTx set PROGR1TUN =
(SELECT COALESCE(SUM(OdQty#),0) FROM ASTCCDTA.OEORH48,ASTCCDTA.TRNSTAT2,ASTDTA.OEORD1
WHERE OHCOM# = TSCOM# AND OHORD# = TSORD# 
AND OHCOM# = ODCOM# AND OHORD# = ODORD#
AND TSSTAT IN('AEP','BGE')
AND OHORDT IN('RTR','INT','SAM')
AND OHREQD = replace(char(current date, iso), '-', '')
AND OHHLDC = ' ' AND ODPRLC = 'ENG'
AND substr(odprt#,1,5) <> 'NOENG' 
AND OHORD# in(SELECT a.TSORD# FROM ASTCCDTA.TRNSTAT2 a    
WHERE a.tsstat IN('AEP','BGE','EAS','REL','STP')));

-- Count for Tomorrow
Update RTRINTx set PROGR1TOM=
(SELECT count(*) FROM ASTCCDTA.OEORH48,ASTCCDTA.TRNSTAT2,ASTCCDTA.OETRA99  
WHERE OHCOM# = TSCOM# AND OHORD# = TSORD# 
AND (otCOM# = OHCOM# AND OTORD#= OHORD# AND ottrnc = 'AQC')
AND TSSTAT IN('AEP','BGE')  
AND OHORDT IN('RTR','INT','SAM') 
AND OHREQD =cast(Right(Replace(Char(current date + 1 day, ISO), '-', ''),8)as int) 
AND OHHLDC = ' ' AND OHORD# in(SELECT a.TSORD# FROM ASTCCDTA.TRNSTAT2 a    
WHERE a.tsstat IN('AEP','BGE','EAS','REL','STP')));

-- Quantity Total Tomorrow
Update RTRINTx set PROGR1MUN =
(SELECT COALESCE(SUM(OdQty#),0) FROM ASTCCDTA.OEORH48,ASTCCDTA.TRNSTAT2,ASTDTA.OEORD1
WHERE OHCOM# = TSCOM# AND OHORD# = TSORD# 
AND OHCOM# = ODCOM# AND OHORD# = ODORD#
AND TSSTAT IN('AEP','BGE')
AND OHORDT IN('RTR','INT','SAM')
AND OHREQD=cast(Right(Replace(Char(current date + 1 day, ISO), '-', ''),8)as int) 
AND OHHLDC = ' '
AND ODPRLC = 'ENG'
AND substr(odprt#,1,5) <> 'NOENG' AND OHORD# in(SELECT a.TSORD# FROM ASTCCDTA.TRNSTAT2 a    
WHERE a.tsstat IN('AEP','BGE','EAS','REL','STP')));

2 个答案:

答案 0 :(得分:2)

这些陈述是静态的。它们必须定期执行才能使数据保持最新状态。

如果您想要动态更新,可以将这些语句转换为单个view,只需通过访问即可重新计算。

答案 1 :(得分:0)

我认为您需要使用的是MQT(物化查询表)。

CREATE TABLE INVTOTALS AS                              
(WITH TEMP AS (SELECT DEC(SUM(QTY),7,0) as TOTAL,      
PART FROM INVDETL                                      
 GROUP BY PART)                                        
SELECT INVMAST.PART, DESC, PRICE, COST, TOTAL FROM INVMAST 
 LEFT JOIN TEMP ON INVMAST.PART = TEMP.PART)           
 DATA INITIALLY DEFERRED                               
 REFRESH DEFERRED    
 ENABLE QUERY OPTIMIZATION                                  
 MAINTAINED BY USER

要刷新此表,您只需要在程序中执行

REFRESH TABLE INVTOTALS