2016-08-02 100 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