【问题标题】:WITH Clause - temporary table to createWITH 子句 - 要创建的临时表
【发布时间】:2016-12-07 11:12:44
【问题描述】:

我想创建一个临时表。

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

但它不起作用。

哪里错了?

【问题讨论】:

  • 请为您的问题使用更好的标签。你根本不应该使用table 标签(它在它的描述中这么说),temporary 也没有任何意义。如果您的问题是关于 MySQL 之类的,请使用 mysql 之类的内容;否则我们不知道你在说什么。
  • 请同时说明您想要达到的目标。第二个 sn-p 应该创建一个临时表吗?什么告诉你它“不工作”?你有任何类型的错误输出吗?你期望结果是什么样的?它看起来像什么?

标签: sql temp-tables


【解决方案1】:

您尝试创建的不是临时表,而是您尝试创建的 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

【讨论】:

    猜你喜欢
    • 2018-08-22
    • 2020-08-02
    • 1970-01-01
    • 2011-07-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-06
    相关资源
    最近更新 更多