• <small id='iG3R4'></small><noframes id='iG3R4'>

    1. <legend id='iG3R4'><style id='iG3R4'><dir id='iG3R4'><q id='iG3R4'></q></dir></style></legend>
    2. <i id='iG3R4'><tr id='iG3R4'><dt id='iG3R4'><q id='iG3R4'><span id='iG3R4'><b id='iG3R4'><form id='iG3R4'><ins id='iG3R4'></ins><ul id='iG3R4'></ul><sub id='iG3R4'></sub></form><legend id='iG3R4'></legend><bdo id='iG3R4'><pre id='iG3R4'><center id='iG3R4'></center></pre></bdo></b><th id='iG3R4'></th></span></q></dt></tr></i><div id='iG3R4'><tfoot id='iG3R4'></tfoot><dl id='iG3R4'><fieldset id='iG3R4'></fieldset></dl></div>

      • <bdo id='iG3R4'></bdo><ul id='iG3R4'></ul>

        <tfoot id='iG3R4'></tfoot>

        如何在 Where 子句中使用别名?

        How to use Alias in Where clause?(如何在 Where 子句中使用别名?)

        <tfoot id='mCtzY'></tfoot>

            <legend id='mCtzY'><style id='mCtzY'><dir id='mCtzY'><q id='mCtzY'></q></dir></style></legend>
          1. <i id='mCtzY'><tr id='mCtzY'><dt id='mCtzY'><q id='mCtzY'><span id='mCtzY'><b id='mCtzY'><form id='mCtzY'><ins id='mCtzY'></ins><ul id='mCtzY'></ul><sub id='mCtzY'></sub></form><legend id='mCtzY'></legend><bdo id='mCtzY'><pre id='mCtzY'><center id='mCtzY'></center></pre></bdo></b><th id='mCtzY'></th></span></q></dt></tr></i><div id='mCtzY'><tfoot id='mCtzY'></tfoot><dl id='mCtzY'><fieldset id='mCtzY'></fieldset></dl></div>

            <small id='mCtzY'></small><noframes id='mCtzY'>

              <tbody id='mCtzY'></tbody>
                <bdo id='mCtzY'></bdo><ul id='mCtzY'></ul>
                1. 本文介绍了如何在 Where 子句中使用别名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有这个程序:

                   PROCEDURE P_LOAD_EXPIRED_ACCOUNT
                    (
                    pDayDiff IN NUMBER,
                    ExpiredCur OUT MEGAGREEN_CUR
                    )
                    IS
                    BEGIN
                    OPEN ExpiredCur FOR
                    SELECT 
                    ACCOUNT_NAME, SERVICE_TYPE, 
                        CASE 
                        WHEN SERVICE_TYPE = 1 THEN ADD_MONTHS(ACTIVATED_DATE,3)
                        WHEN SERVICE_TYPE = 2 THEN ADD_MONTHS(ACTIVATED_DATE,6)
                        WHEN SERVICE_TYPE = 3 THEN ADD_MONTHS(ACTIVATED_DATE,12)        
                         END 
                         AS EXPIRED_DATE
                    FROM SUBSCRIBERS
                    WHERE (EXPIRED_DATE - CURRENT_DATE) < pDayDiff;
                    END;
                  

                  但 SQL Developer 生成此错误:

                  but SQL Developer generate this error:

                  错误(20,10):PL/SQL:ORA-00904:EXPIRED_DATE":标识符无效

                  Error(20,10): PL/SQL: ORA-00904: "EXPIRED_DATE": invalid identifier

                  我相信 PLSQL 允许我在 Where 子句中使用别名,但是我忘记了什么吗?

                  I believe that PLSQL allows me to use Alias in Where clause, but is there something I forgot?

                  提前致谢.

                  推荐答案

                  您不能在 WHERE 子句中引用列别名 - 您的选择是:

                  You can't reference the column alias in the WHERE clause - your options are:

                  • 复制 WHERE 子句中的 CASE 语句
                  • 使用子查询:

                  • replicate the CASE statement in the WHERE clause
                  • use a subquery:

                  PROCEDURE P_LOAD_EXPIRED_ACCOUNT(pDayDiff NUMBER,
                                                   ExpiredCur OUT MEGAGREEN_CUR)
                  IS
                  BEGIN
                  
                  
                     OPEN ExpiredCur FOR
                     SELECT x.account_name,
                            x.service_type, 
                            x.expired_date
                       FROM (SELECT s.account_name,
                                    s.service_type, 
                                    CASE 
                                       WHEN s.service_type = 1 THEN ADD_MONTHS(ACTIVATED_DATE,3)
                                       WHEN s.service_type = 2 THEN ADD_MONTHS(ACTIVATED_DATE,6)
                                       WHEN s.service_type = 3 THEN ADD_MONTHS(ACTIVATED_DATE,12)        
                                    END AS EXPIRED_DATE
                               FROM SUBSCRIBERS s) x
                      WHERE x.expired_date - CURRENT_DATE < pDayDiff;
                  
                  
                  END;
                  

                  甲骨文 9i+

                  WITH summary AS (
                    SELECT s.account_name,
                           s.service_type, 
                           CASE 
                              WHEN s.service_type = 1 THEN ADD_MONTHS(ACTIVATED_DATE,3)
                              WHEN s.service_type = 2 THEN ADD_MONTHS(ACTIVATED_DATE,6)
                              WHEN s.service_type = 3 THEN ADD_MONTHS(ACTIVATED_DATE,12)        
                           END AS EXPIRED_DATE
                      FROM SUBSCRIBERS s)
                     SELECT x.account_name,
                            x.service_type, 
                            x.expired_date
                       FROM summary x
                      WHERE x.expired_date - CURRENT_DATE < pDayDiff;
                  

                  这篇关于如何在 Where 子句中使用别名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Accessing another user#39;s table within an Oracle Stored Procedure(在 Oracle 存储过程中访问另一个用户的表)
                  Maximum stored procedure, function, trigger, or view nesting level exceeded (limit 32)(超出最大存储过程、函数、触发器或视图嵌套级别(限制 32))
                  How to View Oracle Stored Procedure using SQLPlus?(如何使用 SQLPlus 查看 Oracle 存储过程?)
                  How to debug stored procedure in VS 2015?(如何在 VS 2015 中调试存储过程?)
                  How to Pass Java List of Objects to Oracle Stored Procedure Using MyBatis?(如何使用 MyBatis 将 Java 对象列表传递给 Oracle 存储过程?)
                  Set the variable result, from query(设置变量结果,来自查询)

                  <small id='qRitO'></small><noframes id='qRitO'>

                    <bdo id='qRitO'></bdo><ul id='qRitO'></ul>

                    1. <tfoot id='qRitO'></tfoot>

                        <legend id='qRitO'><style id='qRitO'><dir id='qRitO'><q id='qRitO'></q></dir></style></legend>
                          <tbody id='qRitO'></tbody>

                          • <i id='qRitO'><tr id='qRitO'><dt id='qRitO'><q id='qRitO'><span id='qRitO'><b id='qRitO'><form id='qRitO'><ins id='qRitO'></ins><ul id='qRitO'></ul><sub id='qRitO'></sub></form><legend id='qRitO'></legend><bdo id='qRitO'><pre id='qRitO'><center id='qRitO'></center></pre></bdo></b><th id='qRitO'></th></span></q></dt></tr></i><div id='qRitO'><tfoot id='qRitO'></tfoot><dl id='qRitO'><fieldset id='qRitO'></fieldset></dl></div>