光标中的参考字段

时间:2015-11-12 15:35:49

标签: oracle plsql

我需要从同一个光标引用不同的字段,但我不能选择我要显示的名称。 我已经尝试过“...... AS'NAME1”

有什么想法吗?

SET SERVEROUTPUT ON SIZE UNLIMITED;
SET FEEDBACK OFF;

DECLARE
CURSOR GET_TOOLKITS
    IS
        SELECT PROJ.NAME -- first name
             , PROJ.SHORT_NAME  
         , SNAP.NAME SNAP_NAME --second name
         , BRAN.NAME AS BRANCH_NAME -- third name
         , SNAP.SNAPSHOT_ID
         , PROJ.PROJECT_ID
         , TRUNC(PROJ.CREATED_ON)
          FROM LSW_SNAPSHOT SNAP
         , LSW_PROJECT PROJ 
               , LSW_BRANCH BRAN
         WHERE 1=1 
           AND SNAP.PROJECT_ID = PROJ.PROJECT_ID
           AND SNAP.BRANCH_ID = BRAN.BRANCH_ID
           AND PROJ.IS_TOOLKIT = 'T'
           AND SNAP.IS_ARCHIVED = 'F'
           AND SNAP.NAME IS NOT NULL;

CURSOR GET_SNAPSHOTS
    IS
        SELECT PROJ.NAME
         , PROJ.SHORT_NAME
         , SNAP.NAME SNAP_NAME 
         , BRAN.NAME AS BRANCH_NAME
         , SNAP.SNAPSHOT_ID
         , PROJ.PROJECT_ID
         , TRUNC(PROJ.CREATED_ON)
          FROM LSW_SNAPSHOT SNAP
         , LSW_PROJECT PROJ
         , LSW_BRANCH BRAN
         WHERE 1=1 
           AND SNAP.PROJECT_ID = PROJ.PROJECT_ID
           AND SNAP.BRANCH_ID = BRAN.BRANCH_ID
           AND PROJ.IS_TOOLKIT = 'F'
           AND SNAP.IS_ARCHIVED = 'F'
           AND SNAP.NAME IS NOT NULL;

    SET_TOOLKITS GET_TOOLKITS%ROWTYPE;
    SET_SNAPSHOTS GET_SNAPSHOTS%ROWTYPE;

  V_COUNT NUMBER:=0;

BEGIN   
    OPEN GET_TOOLKITS;

    LOOP
        FETCH GET_TOOLKITS INTO SET_TOOLKITS;
        EXIT WHEN GET_TOOLKITS%NOTFOUND;
    V_COUNT := V_COUNT+1;

        DBMS_OUTPUT.PUT_LINE (SET_TOOLKITS.NAME --ref first name
                      || ' '
                      || SET_TOOLKITS.NAME --ref second name
                      || ' '
                      || SET_TOOLKITS.NAME --ref third name
                      || ' ');

    END LOOP;
END;

如果有人能帮助我解决这个问题“IS_TOOLKIT”动态改变我会坦克。

谢谢你们!

1 个答案:

答案 0 :(得分:1)

应该是这个:

   DBMS_OUTPUT.PUT_LINE (SET_TOOLKITS.NAME --ref first name
                  || ' '
                  || SET_TOOLKITS.SNAP_NAME --ref second name
                  || ' '
                  || SET_TOOLKITS.BRANCH_NAME --ref third name
                  || ' ');