WITH Clause - 要创建的临时表

时间:2016-08-02 07:48:57

标签: sql temp-tables

我想创建一个临时表。

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'
);

但它不起作用。

哪里错了?

1 个答案:

答案 0 :(得分: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