2016-08-02 39 views
-2

我想创建一个临时表。WITH子句 - 临时表创建

select * from TFW_ARCHIVETRANSACTION 
    where TYPE = 'openAccountTransferLifeCycle' and STATUS = 5 and 
      to_char(substr(
       TRANSACTIONDATA, 
       instr(TRANSACTIONDATA,'<ns:CredentialFunction>') + length('<ns:CredentialFunction>'), 
       instr(substr(
        TRANSACTIONDATA, 
        instr(TRANSACTIONDATA,'<ns:CredentialFunction>') + length('<ns:CredentialFunction>') 
       ), '</ns:CredentialFunction>') - 1 
     )) = 'OpenCurrentAccount'; 

我想这样的:

with openAccountTransferLifeCycle_c AS (
    select * from TFW_ARCHIVETRANSACTION 
     where TYPE = 'openAccountTransferLifeCycle'and STATUS = 5 and 
       to_char(substr(
        TRANSACTIONDATA, 
        instr(TRANSACTIONDATA,'<ns:CredentialFunction>') + length('<ns:CredentialFunction>'), 
        instr(substr(
         TRANSACTIONDATA, 
         instr(TRANSACTIONDATA,'<ns:CredentialFunction>') + length('<ns:CredentialFunction>') 
       ), '</ns:CredentialFunction>') - 1 
      )) = 'OpenCurrentAccount' 
); 

,但它无法正常工作。

哪里出错?

+0

请使用更好的标签为您的问题。你根本不应该使用[tag:table]标签(它在描述中是这样说的),[tag:temporary]也不代表任何意思。如果你的问题是关于MySQL或类似的话,请使用[tag:mysql]之类的东西;否则我们不知道你在说什么。 – deceze

+0

请同时说明你正在努力达到的目标。第二个片段是否应该创建一个临时表?什么告诉你它是“不工作”?你有任何一种错误输出?你期望结果是什么样的?它看起来像什么? – Julian

回答

0

你正在尝试建立不是临时表,你要创建CTE可以像图被认为是,但只有它没有物化和范围是立即..

您是几乎没有,除了选择部分,并确保您添加;开始cte

;with openAccountTransferLifeCycle_c 
AS 
(select * from TFW_ARCHIVETRANSACTION 
where TYPE = 'openAccountTransferLifeCycle'and STATUS = 5 
and 
to_char(substr(TRANSACTIONDATA, instr(TRANSACTIONDATA,'<ns:CredentialFunction>') + length('<ns:CredentialFunction>'), 
instr(substr(TRANSACTIONDATA, 
instr(TRANSACTIONDATA,'<ns:CredentialFunction>') + length('<ns:CredentialFunction>')), 
'</ns:CredentialFunction>') - 1)) = 'OpenCurrentAccount'); 
select * from openAccountTransferLifeCycle_c