How: making column value as column of select statement

Hi
Quickly I have searched in this forum for following solution but not able to find it.
I need to make a query in such a way that the value of one column in one table should act as a column-name of another table
Eg:-
tab1
col1,col2,*col3*,col4
tab2
col11 col22 col33 col44
row1 a b col3 d
row2 aa bb cc dd
So the query should be something like --- in row2 if the value is col3 then from tab1 I should pick the col3 in select statement (basically there will be some join in tab1 and tab2 )
Hope I am able to make u all understand my query.
regards

Hi all,
Sorry for late response.Just now I checked all the replies.
Actually I tried in this way.
CREATE OR REPLACE function Proc_caption (in_tan varchar2, in_order in number)
return varchar2
is
d varchar2(100) ;
begin
SELECT col1 into d
from tab1
Where
col2 = in_tanid
AND col3 = 'Y'
AND col4 = in_order ;
return d ;
Exception
WHen No_DATA_FOund then
return 'N' ;
end ;
create or replace procedure proc_generate_view(in_tan varchar2, in_soc varchar2)
is
x varchar2(2000);
v4 varchar2(50) ;
v5 varchar2(50) ;
cnt number ;
begin
v4:= PROC_Caption (in_tan,4) ;
v5:= PROC_Caption (in_tan,5) ;
x := ' Create view v_generate as '
|| ' SELECT a , b, c, d ' ;
if v4 <> 'N' THEN
x := x || ' , ' || PROC_Caption (in_tan,4) || ' as Caption4 ' ;
end if;
if v5 <> 'N' THEN
x := x || ' , ' || PROC_Caption (in_tan,5) || ' as Caption5 ' ;
end if;
x := x || ' FROM tab2 WHERE col1 = ''' || in_socid || ''''
|| ' AND col2 = ''' || in_tan || '''' ;
select count(1) into cnt from USER_OBJECTS where OBJECT_NAME = 'V_GENERATE'
and OBJECT_TYPE = 'VIEW' ;
if cnt > 0 then
EXECUTE IMMEDIATE ' DROP view V_GENERATE' ;
END IF ;
execute immediate x ;
end ;
NOTE:- I have just renamed the table name and column names in order to make it non confedential...
I have created this successfully with actual table name and column names and able to get the result as per my requirement.
regards

Similar Messages

  • How to restrict values displayed using a select-options

    Can someone please tell me how to restrict values displayed using a select-options.
    Example- in my table I have 100 entries. However when the user will click on the required field- I want to be display only 25 options based on a given value of another field in the table.
    Thanks,
    Mahesh.

    get the screen value for the selectd field  using the fm
    DYNP_VALUES_READ.
    for that value filter the internal table values and pass the table to f4 help of the field.
    below code will help u
    write the f4 help for the field.
    At Selection Screen on value request                                *
    F4 help for Corporate
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_CORP.
    Get Corporates for selected division
      PERFORM GET_CORP.
      PERFORM F4HELP_CORP.
    *&      Form  GET_CORP
    Get the corporates for the selected division
    There are no interface parameters to be passed to this routine
    FORM GET_CORP .
    Table for conglomerate
      DATA:
        LT_CONG      LIKE STANDARD TABLE OF FS_CORP,
    Fields of current screen
        LFS_DYNPREAD TYPE DYNPREAD,
    Table for current Screen fields
        LT_DYNPREAD  LIKE STANDARD TABLE OF LFS_DYNPREAD.
      LFS_DYNPREAD-FIELDNAME = 'P_DIV'.
      APPEND LFS_DYNPREAD TO LT_DYNPREAD.
    Get selection screen value for division
      CALL FUNCTION 'DYNP_VALUES_READ'
        EXPORTING
          DYNAME               = SY-REPID
          DYNUMB               = SY-DYNNR
        TABLES
          DYNPFIELDS           = LT_DYNPREAD
        EXCEPTIONS
          INVALID_ABAPWORKAREA = 1
          INVALID_DYNPROFIELD  = 2
          INVALID_DYNPRONAME   = 3
          INVALID_DYNPRONUMMER = 4
          INVALID_REQUEST      = 5
          NO_FIELDDESCRIPTION  = 6
          INVALID_PARAMETER    = 7
          UNDEFIND_ERROR       = 8
          DOUBLE_CONVERSION    = 9
          STEPL_NOT_FOUND      = 10
          OTHERS               = 11.
      IF SY-SUBRC EQ 0.
        READ TABLE LT_DYNPREAD INTO LFS_DYNPREAD INDEX 1.
        IF SY-SUBRC EQ 0.
          P_DIV = LFS_DYNPREAD-FIELDVALUE.
        ENDIF.                             " IF SY-SUBRC EQ 0
      ENDIF.                               " IF SY-SUBRC EQ 0
      REFRESH T_CORP.
    Get the conglomerate for the selected division
      SELECT KUNNR                         " Conglomerate
        FROM KNVH
        INTO TABLE  LT_CONG
       WHERE HITYP  EQ C_HITYP
         AND VKORG  EQ C_VKORG
         AND VTWEG  EQ C_VTWEG
         AND SPART  EQ P_DIV
         AND DATAB  LE SY-DATUM
         AND DATBI  GE SY-DATUM
         AND HKUNNR EQ SPACE.
      IF SY-SUBRC EQ 0.
        SORT LT_CONG BY KUNNR.
        DELETE ADJACENT DUPLICATES FROM LT_CONG
                        COMPARING KUNNR.
    Get the corporates for the selected conglomerates
        SELECT KUNNR                       " Customer Number
          FROM KNVH
          INTO TABLE  T_CORP
           FOR ALL ENTRIES IN LT_CONG
         WHERE HITYP  EQ C_HITYP
           AND VKORG  EQ C_VKORG
           AND VTWEG  EQ C_VTWEG
           AND SPART  EQ P_DIV
           AND DATAB  LE SY-DATUM
           AND DATBI  GE SY-DATUM
           AND HKUNNR EQ LT_CONG-KUNNR.
        IF SY-SUBRC NE 0.
          CLEAR: SSCRFIELDS.
          MESSAGE I531(0U) WITH TEXT-005.
          STOP.
        ENDIF.                             " IF SY-SUBRC NE 0
      ELSE.
        CLEAR: SSCRFIELDS.
        MESSAGE I531(0U) WITH TEXT-004.
        STOP.
      ENDIF.                               " IF SY-SUBRC EQ 0
    ENDFORM.                               " GET_CORP
    *&      Form  F4HELP_CORP
    F4 help for corporate
    There are no interface parameters to be passed to this routine
    FORM F4HELP_CORP .
    F4 help for corporate
      CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
        EXPORTING
          RETFIELD        = 'KUNNR'
          DYNPPROG        = 'Z_EXCESS_USAGE'
          DYNPNR          = '1000'
          DYNPROFIELD     = 'P_CORP'
          VALUE_ORG       = 'S'
        TABLES
          VALUE_TAB       = T_CORP
        EXCEPTIONS
          PARAMETER_ERROR = 1
          NO_VALUES_FOUND = 2
          OTHERS          = 3.
      IF SY-SUBRC EQ 0.
    Do nothing
      ENDIF.                               " IF SY-SUBRC EQ 0
    ENDFORM.                               " F4HELP_CORP

  • How to compile the hint to force selection statement to use index

    Hello expert,
    will you please tell me how to compile the hint to force selection statement to use index?
    Many Thanks,

    Not sure what you mean by compile, but hint is enclosed in /*+ hint */. Index hint is INDEX(table_name,index_name). For example:
    SQL> explain plan for
      2  select * from emp
      3  /
    Explained.
    SQL> @?\rdbms\admin\utlxpls
    PLAN_TABLE_OUTPUT
    Plan hash value: 3956160932
    | Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT  |      |    14 |   546 |     3   (0)| 00:00:01 |
    |   1 |  TABLE ACCESS FULL| EMP  |    14 |   546 |     3   (0)| 00:00:01 |
    8 rows selected.
    SQL> explain plan for
      2  select /*+ index(emp,pk_emp) */ *
      3  from emp
      4  /
    Explained.
    SQL> @?\rdbms\admin\utlxpls
    PLAN_TABLE_OUTPUT
    Plan hash value: 4170700152
    | Id  | Operation                   | Name   | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT            |        |    14 |   546 |     2   (0)| 00:00:01 |
    |   1 |  TABLE ACCESS BY INDEX ROWID| EMP    |    14 |   546 |     2   (0)| 00:00:01 |
    |   2 |   INDEX FULL SCAN           | PK_EMP |    14 |       |     1   (0)| 00:00:01 |
    9 rows selected.
    SQL> Hint in the above example is forcing optimizer to use index which resul;ts in a bad execution plan. Most of the time optimizer does not need hints and chooses an optimal plan. In most cases sub-optimal plan is result of stale or incomplete statistics.
    SY.

  • How to avoid data repetation when using select statements with innerjoin

    how to avoid data repetation when using select statements with innerjoin.
    thanks in advance,
    satheesh

    you can use a query like this...
      SELECT DISTINCT
             frg~prc_group1                  "Product Group 1
             frg~prc_group2                  "Product Group 2
             frg~prc_group3                  "Product Group 3
             frg~prc_group4                  "Product Group 4
             frg~prc_group5                  "Product Group 5
             prc~product_id                  "Product ID
             txt~short_text                  "Product Description
    UP TO 10 ROWS
    INTO TABLE l_i_data
    FROM
    Joining CRMM_PR_SALESG and
    COMM_PR_FRG_ROD
    crmm_pr_salesg AS frg
    INNER JOIN comm_pr_frg_rod AS prd
    ON frgfrg_guid = prdfragment_guid
    Joining COMM_PRODUCT and
    COMM_PR_FRG_ROD
    INNER JOIN comm_product AS prc
    ON prdproduct_guid = prcproduct_guid
    Joining COMM_PRSHTEXT and
    COMM_PR_FRG_ROD
    INNER JOIN comm_prshtext AS txt
    ON prdproduct_guid = txtproduct_guid
    WHERE frg~prc_group1 IN r_zprc_group1
       AND frg~prc_group2 IN r_zprc_group2
       AND frg~prc_group3 IN r_zprc_group3
       AND frg~prc_group4 IN r_zprc_group4
       AND frg~prc_group5 IN r_zprc_group5.
    reward it it helps
    Edited by: Apan Kumar Motilal on Jun 24, 2008 1:57 PM

  • Retrieving multiple values from one column in SELECT statement

    Hi,
    I have a slight dilemma in that I'm trying to pull down all the values from a column from a select statement that includes some JOINS in it.
    If I run the query at the SQL Plus prompt, it pulls back all the values/rows.
    When I run the select (and prepared ) statement in my JSP, it only pulls back one of the 4 values I'm trying to retrieve.
    e.g.
    at the DB level :
    SELECT role_name, CC_ID FROM votetbl a
    INNER JOIN APPROVERS b ON
    a.BUSVP = b.BUSVP AND
    a.BRANCH = b.BRANCH
    WHERE CC_ID = 1688this will return:
    ROLE_NAME CC_ID
    ops 1688
    ops 1688
    comply 1688
    legal 1688
    comply 1688
    When run in my JSP, like so:
    String primID3a = request.getParameter("primID");
    Statement stmtovoter = connection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
    String prepvotSQL = "SELECT role_name, CC_ID FROM votetbl a INNER JOIN APPROVERS b ON a.BUSVP = b.BUSVP AND " +
                         "a.BRANCH = b.BRANCH WHERE CC_ID = ?";
    PreparedStatement prepvotstmt = connection.prepareStatement(prepvotSQL);
    prepvotstmt.setString(1, primID3a);
    ResultSet rest3 = prepvotstmt.executeQuery();
    rest3.next();
    String votecat = rest3.getString(1);
    out.println("Vote category: "+votecat);I only get ops returned.
    Do I need to run an enumerator? Or reqest.getParameterValues or use a while statement around the results set?
    Any feedback and direction here is welcomed!
    Thanks!

    Actually, I tried looping and still only get 1, but returned several times.
    i.e.
    PreparedStatement prepvotstmt = connection.prepareStatement(prepvotSQL);
    prepvotstmt.setString(1, primID3a);
    ResultSet rest3 = prepvotstmt.executeQuery();
    rest3.next();
    String votecat = rest3.getString(1);
    while (rest3.next()) {
    out.print("category roles "+votecat);
    }then I get returned the following:
    admincategory roles admincategory roles admincategory roles admincategory roles admincategory roles admincategory roles admincategory roles admincategory roles admincategory roles admincategory roles admincategory roles admin
    like so.
    Where as at the DB level I get
    ROLE_NAME CC_ID
    admin 1688
    ops 1688
    ops 1688
    ops 1688
    ops 1688
    ops 1688
    ops 1688
    ops 1688
    risk 1688
    comply 1688
    legal 1688
    legal 1688
    ops 1688
    comply 1688
    Maybe the while should go around the getString(1) designation? But I was thinking I'd tried that and gotten invalid cursor error
    Something is definitely amiss, between the prepared statement in the servlet and the SELECT statement at the DB level.
    I can totally hardcode the statement in the servlet or JSP and it will return one value potentially several times, but only one.
    Other times, it will not return a value at all, even though one resides in the db.
    Yet go to the DB/SQL Plus prompt and it returns perfectly. I can simply copy and paste the SELECT statement from the out.print line I made and it works like a champ in SQL Plus. Any ideas why the same exact thing cannot return the proper values within the servlet/JSP?
    Yeeeeeeesh!!! : (
    Message was edited by:
    bpropes20

  • Leaving out columns in Select statements

    Hello! I'm just looking for confirmation on something really for some work I'm doing at uni..
    I'm looking to put together a query that can disregard certain columns depending on whats stored in them. E.g, I'm making a football management system.. my results table contains fields for goal scorers (columns for goalone, goaltwo - up to goal ten, etc). Each row for this table is obviously going to have different amounts of goal scorers, e.g. there will be times when goalfour - goalten are null when there are 3 goalscorers. There are also going to be times when I only want to display certain goalscorer names and not other names, so I'll be wanting to disregard columns that contains anyone but Wayne Rooney for example.
    What I'm asking therefore is if there is any query that can display a row, but disregard the columns that contain certain values, e.g. Select * from ResultsTable, Ignore where goalone, goaltwo, goalthree, (etc etc) = Null;
    I'm currently getting the following results with the queries I'm trying:
    COLUMN HEADER: goalone goaltwo goalthree goal four goal five
    ROW 1: Rooney Drogba Van Persie NULL NULL
    ROW 2: Van Persie NULL NULL NULL NULL
    (i.e displaying nulls when, if its possible, I want something like:
    COLUMN HEADER: goalone goaltwo goalthree goal four goal five
    ROW 1: Rooney Drogba Van Persie
    ROW 2: Van Persie
    e.g. It will only show goal scorers and not a huge list of Null none scorers.
    On reflection there may even be better approaches to storing goal scorers but I'm against time now and i'm hoping there'll be a query to do something like what I want. I've only been able to find queries through Google that look for Nulls and then disregard the whole row if it finds one, which is obviously not what I want!
    Any help is hugely appreciated! Thanks! :)

    Hi,
    986500 wrote:
    Hello! I'm just looking for confirmation on something really for some work I'm doing at uni..
    I'm looking to put together a query that can disregard certain columns depending on whats stored in them. E.g, I'm making a football management system.. my results table contains fields for goal scorers (columns for goalone, goaltwo - up to goal ten, etc). Each row for this table is obviously going to have different amounts of goal scorers, e.g. there will be times when goalfour - goalten are null when there are 3 goalscorers. There are also going to be times when I only want to display certain goalscorer names and not other names, so I'll be wanting to disregard columns that contains anyone but Wayne Rooney for example.
    What I'm asking therefore is if there is any query that can display a row, but disregard the columns that contain certain values, e.g. Select * from ResultsTable, Ignore where goalone, goaltwo, goalthree, (etc etc) = Null;
    I'm currently getting the following results with the queries I'm trying:
    COLUMN HEADER: goalone goaltwo goalthree goal four goal five
    ROW 1: Rooney Drogba Van Persie NULL NULL
    ROW 2: Van Persie NULL NULL NULL NULLSee the forum FAQ {message:id=9360002} for how to use \ tags when posting formatted text.
    (i.e displaying nulls when, if its possible, I want something like:
    COLUMN HEADER: goalone goaltwo goalthree goal four goal five
    ROW 1: Rooney Drogba Van Persie
    ROW 2: Van Persie
    e.g. It will only show goal scorers and not a huge list of Null none scorers.Sure, you can display NULLs any way you want.
    that's the kind of thing your front end would be best at.  In SQL*Plus, for example, you can saySET NULL ""
    to have nothing display when a column is NULL.
    If you had to do it in SQL, you could do something likeNVL (goalone, ' ')
    to explicitly map NULL to a space.
    On reflection there may even be better approaches to storing goal scorers but I'm against time now and i'm hoping there'll be a query to do something like what I want. I've only been able to find queries through Google that look for Nulls and then disregard the whole row if it finds one, which is obviously not what I want!It's quite unclear what you you want.
    Perhaps the reason you can't find anything close to what you want is that what you want is a terrible thing to attempt in a relational database.  This is what the first reply said, too.
    Is foalone the person who happened to score the first goal in a particular game, goaltwo the person who scored the second goal (if there was a second goal), and so on?  A much better way to model that would beCREATE TABLE goals
    ( game_id NUMBER (8)
    , goal_num NUMBER (2) -- This assumes there will never be more than 99 goals in any one game
    , player_id NUMBER (8)
    You could have other columns, too, if you need them.  Something to indicate the team might be handy, even if that can be derived from the player.
    Any help is hugely appreciated! Thanks! :)Can you give a better idea of what kind of data your going to store, and what kind of questions  this database will need to answer.  Give some specific examples, like this:
    "Two games were played.  In the first game,  Rooney scored a goa for team A, then Drogba and  Van Persie  scored goals for team B.  In the second game, Van Persie scored the only goal for team B, and tem C didn't score at all.  Some typical questions I'll want to answer are
    (a) Who are the top scorers of all time? (With the sample data I just gave, I'd like to see output like this: ...)
    (b) In what percentage of the games did player ... score?
    (c) Given N specific players, what are the games when all N of them scored?
    Here's something you may not realize about tables in relational databases, such as Oracle.
    When tables are printed in books or papers, it's usually not important what the columns represent, and what the rows represent.  For example, you may have a row for each player, and separate columns for name, age, team, and various statistics, but you might just as well have a column for each player (especially if you are comparing 2 or 3 players) and separate columns for name, age, team, and so on. *RELATION DATABASE TABLES DO NOT WORK LIKE THAT!* In a relational database, columns are relatively fixed things; for example, you must hard-code the number of columns into every query.  Rows, on the other hand, are much more flexible.  It's easy to write queries where the number of rows in the output will depend on what data happens to be in the table when the query is run.  This is not intuitive, and may take some time to get used to, but you'll only cause trouble for yourself if you don't get the hang of it.
    When I hear something like "show goal scorers and not a huge list of Null none scorers"  it seems very obvious that there should be separate *rows* for the goal scorers.  Again, I don't really knwo wht kind of data you want to keep, or how you plan to use that data, but if you're storing it in a relational database, that much seems obvious,                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • How to display value based on LOV selection

    Hi,
    I have an editable table. On create operation one of the field is LOV, based on LOV selection the next field should be auto populated, please help me how to achive this.
    Thanks,

    Thanks for your reply........
    I did all these to get value based on LOV selection, but my problem is when i am trying to create a new record then everthing is working fine but normal search i am not getting the value of that attribute.
    below is my code
    Page:
    <af:column sortProperty="ProcessType" filterable="true"
    sortable="true"
    headerText="#{bindings.CmWeeklyProcesses.hints.ProcessType.label}"
    id="c36" width="340px;">
    <af:inputComboboxListOfValues id="processTypeId"
    popupTitle="Search and Select: #{bindings.CmWeeklyProcesses.hints.ProcessType.label}"
    value="#{row.bindings.ProcessType.inputValue}"
    model="#{row.bindings.ProcessType.listOfValuesModel}"
    required="#{bindings.CmWeeklyProcesses.hints.ProcessType.mandatory}"
    columns="#{bindings.CmWeeklyProcesses.hints.ProcessType.displayWidth}"
    shortDesc="#{bindings.CmWeeklyProcesses.hints.ProcessType.tooltip}" inlineStyle="width:800px;"
    valueChangeListener="#{backingBeanScope.backing_app_CalcSchedules.weeklyDescription}"
    autoSubmit="true" >
    <!-- <f:validator binding="#{row.bindings.ProcessType.validator}"/>-->
    </af:inputComboboxListOfValues>
    </af:column>
    <!--value="#{row.bindings.Description.inputValue}" backingBeanScope.backing_app_CalcSchedules.description-->//If i use this value in the below property line then i am not getting value while creating time but if i done blind search then i am not getting any value in this field.
    <af:column sortProperty="Description" filterable="true"
    sortable="true"
    headerText="#{bindings.CmWeeklyProcesses.hints.Description.label}"
    id="c35" width="390px;">
    <af:inputComboboxListOfValues id="descriptionId"
    popupTitle="Search and Select: #{bindings.CmWeeklyProcesses.hints.Description.label}"
    value="#{row.bindings.Description.inputValue}"
    model="#{row.bindings.Description.listOfValuesModel}"
    required="#{bindings.CmWeeklyProcesses.hints.Description.mandatory}"
    columns="#{bindings.CmWeeklyProcesses.hints.Description.displayWidth}"
    shortDesc="#{bindings.CmWeeklyProcesses.hints.Description.tooltip}" inlineStyle="width:1000px;"
    readOnly="true" partialTriggers="processTypeId">
    <f:validator binding="#{row.bindings.Description.validator}"/>
    </af:inputComboboxListOfValues>
    </af:column>

  • SQL column as select statement to be referenced into a group by

    Is there a notation or solution to be able to reference a column that is a inline select statement within a group by as detailed below? The group by will not accept the alias. I also tried to make the SQL a MAX to remove the need for the group by reference and this returned invalid expression.
    SELECT DISTINCT hdr.BUSINESS_UNIT,
    hdr.SESSN_ID,
    hdr.STREAM_ROOT_ID,
    hdr.SESSN_STS_CD,
    hdr.SESSN_CRE_DTTM,
    CASE
    WHEN C.OPRID <> ' ' THEN C.OPRID
    ELSE S.OPERATOR
    END OPRID,
    strm.QS_APP_CONTEXT,
    RECV.QTY_SH_RECVD Quantity_Received,
    CASE
    WHEN hdr.BUSINESS_UNIT = 'MFG01' THEN MAX(G.MFDS_SGRP_SIZE)
    ELSE MAX(S.SESSN_SGRP_SIZE)
    END Quantity_Inspected,
    MAX(S.QS_VALUEREADING_1) Defect_Count,
    CASE
    WHEN MAX(S.QS_VALUEREADING_1) = 0 THEN ' '
    ELSE MAX(G.MFDS_NAME)
    END Characteristic,
    MAX(CMNT.QS_COMMENT2) COMMENTS,
    strm.INV_ITEM_ID,
    itm.DESCR,
    strm.WORK_CENTER_CODE,
    strm.VENDOR_ID,
    *(SELECT V.NAME1 FROM PS_VENDOR V WHERE strm.VENDOR_ID = V.VENDOR_ID AND V.SETID = (SELECT SETID FROM PS_SET_CNTRL_REC*
    WHERE  RECNAME = 'VENDOR'
    AND SETCNTRLVALUE = strm.BUSINESS_UNIT)) VENDOR_NAME,
    strm.PRDN_AREA_CODE,
    strm.COMPL_OP_SEQ,
    strm.PRODUCTION_TYPE,
    C.RECEIVER_ID,
    C.RECV_LN_NBR,
    RECV.PO_ID,
    RECV.LINE_NBR,
    RECV.SCHED_NBR,
    C.PRODUCTION_ID,
    C.SERIAL_ID,
    C.INV_LOT_ID
    FROM PS_QS_SESSN_HDR8 hdr
    LEFT OUTER JOIN PS_QS_SESSN_TRACE8 C
    ON hdr.BUSINESS_UNIT = C.BUSINESS_UNIT
    AND hdr.SESSN_ID = C.SESSN_ID
    LEFT OUTER JOIN PS_RECV_INSPDTL_VW RECV
    ON C.BUSINESS_UNIT = RECV.BUSINESS_UNIT
    AND C.RECEIVER_ID = RECV.RECEIVER_ID
    AND C.RECV_LN_NBR = RECV.RECV_LN_NBR
    LEFT OUTER JOIN PS_QS_STREAM_ROOT strm
    ON hdr.STREAM_ROOT_ID = strm.STREAM_ROOT_ID
    AND hdr.BUSINESS_UNIT = strm.BUSINESS_UNIT
    LEFT OUTER JOIN PS_QS_STREAM8_VW G
    ON strm.STREAM_ROOT_ID = G.STREAM_ROOT_ID
    AND strm.BUSINESS_UNIT = G.BUSINESS_UNIT
    LEFT OUTER JOIN PS_QS_SUBGROUP S
    ON hdr.BUSINESS_UNIT = S.BUSINESS_UNIT
    AND hdr.SESSN_ID = S.SESSN_ID
    AND S.STREAM_ID = G.STREAM_ID
    LEFT OUTER JOIN PS_QS_SESSN_COMM8 CMNT
    ON S.BUSINESS_UNIT = CMNT.BUSINESS_UNIT
    AND S.SESSN_ID = CMNT.SESSN_ID
    AND S.STREAM_ID = CMNT.STREAM_ID
    AND C.SAMPLE = CMNT.SAMPLE
    LEFT OUTER JOIN PS_MASTER_ITEM_TBL itm
    ON itm.INV_ITEM_ID = strm.INV_ITEM_ID
    LEFT OUTER JOIN PS_SET_CNTRL_REC cntrl
    ON itm.SETID = cntrl.SETID
    AND cntrl.RECNAME = 'MASTER_ITEM_TBL'
    AND cntrl.SETCNTRLVALUE = strm.BUSINESS_UNIT
    WHERE S.QS_VALUEREADING_1 = (SELECT MAX(S2.QS_VALUEREADING_1)
    FROM PS_QS_SUBGROUP S2
    WHERE S2.BUSINESS_UNIT = S.BUSINESS_UNIT
    AND S2.SESSN_ID = S.SESSN_ID
    AND S2.STREAM_ID = S.STREAM_ID)
    GROUP BY hdr.BUSINESS_UNIT,
    hdr.SESSN_ID,
    hdr.STREAM_ROOT_ID,
    hdr.SESSN_STS_CD,
    hdr.SESSN_CRE_DTTM,
    C.OPRID,
    S.OPERATOR,
    strm.QS_APP_CONTEXT,
    RECV.QTY_SH_RECVD,
    strm.INV_ITEM_ID,
    itm.DESCR,
    strm.WORK_CENTER_CODE,
    strm.VENDOR_ID,
    VENDOR_NAME,
    strm.PRDN_AREA_CODE,
    strm.COMPL_OP_SEQ,
    strm.PRODUCTION_TYPE,
    C.RECEIVER_ID,
    C.RECV_LN_NBR,
    RECV.PO_ID,
    RECV.LINE_NBR,
    RECV.SCHED_NBR,
    C.PRODUCTION_ID,
    C.SERIAL_ID,
    C.INV_LOT_ID

    Hi,
    Assign the alias in a sub-query. Then you'll be able to use it wherever you want to, and how many times you want to, in a super-query.
    For example:
    WITH     got_vendor     AS
         SELECT     hdr.business_unit
                  SELECT  v.name1
                  FROM    ps_vendor     v
                  WHERE   strm.vendor_id     = v.vendor_id
                  AND     v.setid          = (
                                                SELECT  setid
                                        FROM    ps_set_cntrl_rec
                                        WHERE   recname          = 'VENDOR'
                                        AND     setcntrlvalue      = strm.business_unit
              )           AS vendor_name
         FROM      ps_qs_sessn_hdr8     hdr
    SELECT       business_unit          -- NOTE: no hdr.; all columns are from got_vendor now
    ,       vendor
    FROM       got_vendor
    GROUP BY  business_unit
    ,       vendor
    ;When you define an alias (such as vendor) in a query, you can use that alias in the ORDER BY clause of that same query, but that's the only place in that same query where you can use it. If you want to use the alias anywhere else (e.g., in the GROUP BY clause, as in your example, the WHERE clause, or elsewhere in the SELECT clause), then you probably want to compute it in a sub-query, as shown above.
    There's probably a better way to compute vendor, but that's a separate problem.
    Edited by: Frank Kulash on Jan 3, 2012 10:37 AM
    Added example

  • Columns in Select Statement

    Does the column selected in the select statement will effect the table access. I have a query selecting 10 columns from different tables using joins and inline views. One table is going for a Full table Scan.
    When I searched for the cause, I couldn't find anything. Everything looks correct. When I comment 2 two particular columns from the select statement the table is not scanned fully.
    Those two columns are not the part of the index. Why does a selection of columns affect the Explain plan?
    Thanks,
    GM

    Hi Gints,
    Thank you for your reply. This is my query and
    nvl(TICKET_JOIN.TDQRLV,0) ACC_SHIPPED_QTY,
    TICKET_JOIN.TDSOQS QUANTITY_TICKETED are the columns tha's creating issue. If I comment those columns Index is accessed properly.
    select
    'TKT' SOURCE,
    TICKET_JOIN.TKDO01 HIRE_ID,
    TICKET_JOIN.TKQ101 TRUCK_ID,
    TICKET_JOIN.TKVEHT TRUCK_TYPE,
    1 TRUCK_COMM,
    nvl(TKCMP1,0) TICKET_NUM,
    nvl(TKADTM,0) TICKET_TIME,
    --TICKET_JOIN.TDSOQS QUANTITY_TICKETED,
    0 CHECKIN_TIME,
    --nvl(TICKET_JOIN.TDQRLV,0) ACC_SHIPPED_QTY,
    nvl(DDADTM,0) START_TIME
    from
    (select
    TICKET.TKCMP1,
    TICKET.TKDO01,
    TICKET.TKQ101,
    TICKET.TKADTM ,
    TICKET.TKVEHT,
    TICKET_DETAILS.TDAITM ,
    TICKET_DETAILS.TDQRLV ,
    TICKET_DETAILS.TDSOQS ,
    TICKET.TKCNTF,
    TICKET.TKTRDJ,
    TICKET.TK58GA8
    from
    CRPDTA.F5800091 TICKET_DETAILS ,
    CRPDTA.F5800090 TICKET
    where TICKET.TKCMP1 = TICKET_DETAILS.TDCMP1
    and TICKET.TKTRDJ = TICKET_DETAILS.TDTRDJ
    and TICKET.TKTRDJ = 107085
    and TICKET.TKEV12 <> 'Y'
    and TICKET.TK58GA8='ECSEO'
    and TICKET.TKCNTF = '11') TICKET_JOIN ,
    (select
    DDDOCO,
    DDCNTF,
    DDQTFN,
    DDAITM,
    DDADTM,
    DD58GA8,
    DDTRDJ
    from
    CRPDTA.F5800051 ORDER_DETAILS,
    CRPDTA.F5800050 ORDER_HEADER
    where
    ORDER_HEADER.DHDOCO = ORDER_DETAILS.DDDOCO
    and ORDER_HEADER.DHTRDJ = ORDER_DETAILS.DDTRDJ
    and ORDER_HEADER.DH58GA8 = ORDER_DETAILS.DD58GA8
    and ORDER_HEADER.DHDCTO = ORDER_DETAILS.DDDCTO
    /*and
    (ORDER_HEADER.DHTRDJ = 107085
    OR (ORDER_HEADER.DHTRDJ = 107084 and ORDER_HEADER.DHEV04='Y')
    and TRIM(ORDER_HEADER.DH58GA8) = 'ECSEO'
    and TRIM(ORDER_DETAILS.DDCNTF) = '11' ) ORDER_VIEW
    where TICKET_JOIN.TKTRDJ = ORDER_VIEW.DDTRDJ
    and TICKET_JOIN.TDAITM = ORDER_VIEW.DDAITM
    and TICKET_JOIN.TKCNTF = ORDER_VIEW.DDCNTF
    and TICKET_JOIN.TK58GA8 = ORDER_VIEW.DD58GA8
    and NOT EXISTS ( select 1 from CRPDTA.F5800120 TRUCK_ASSIGNMENT
    where TATRDJ = 107085
    and TACNTF = '11'
    and TA58GA8 = 'ECSEO'
    and TICKET_JOIN.TKQ101||TICKET_JOIN.TKVEHT = TAQ101||TAVEHT )
    Thanks
    GM

  • Adding columns in select statements

    All if i have the following statement and i wanted to add the two volume columns in the select statement can i just do a A1.volume + A2.Volume as vol
    SELECT A1.ORDERID,A1.MARKET,A1.GIMSG, A2.ORDERID,A2.MARKET,A2.TRADERID, A1.VOLUME, A2.VOLUME
    FROM table1 A1 JOIN table2
      ON A1.TRADEDATE = A2.TRADEDATE

    No that wouldnt work,
    Error will be invalid no(error no ORA-01722)
    but you can use pipe(||)
    select col1||col2 as col from ......
    ex: SQL> select e.ename||d.dname as result_col from emp e,dept d where e.deptno=d.deptno;
    RESULT_COL
    SMITHRESEARCH
    ALLENSALES
    WARDSALES
    JONESRESEARCH
    MARTINSALES
    BLAKESALES
    CLARKACCOUNTING
    SCOTTRESEARCH
    KINGACCOUNTING
    TURNERSALES
    ADAMSRESEARCH
    RESULT_COL
    JAMESSALES
    FORDRESEARCH
    MILLERACCOUNTING
    14 rows selected.
    Message was edited by:
    user517498

  • How to use variables in an sql select statement.

    Hi, I have seen examples using the update, but nothing using a select statement.
    I have four variables I am getting from drop down menus in my JSP I set the user selected items to strings.
    How would I create the select statement like this:
    .String XName = request.getParameter("UserInputX");
    rsInResult = stmtInResult.executeQuery("SELECT ColumxX FROM TableZ WHERE ColumnX = XName")Obviously it tries to read "XName" as a column and of course can't find it, how would I set it up to have it see the Value of XName and not the literal XName.

    read this:
    rsInResult = stmtInResult.executeQuery("SELECT ColumxX FROM TableZ WHERE ColumnX = '"+XName+"')
    {code}
    better way is PreparedStatement:
    {code}
         // example code to change password to an user in the USERS table
         String newPWD = "my password";
         String user = "luxjava";
         PreparedStatement prepStat;
         String updatePWD = "UPDATE LOGISTIC.USERS "+
                                  "SET logistic.users.password = ? "+
                                  "WHERE logistic.users.username = ?";
         prepStat = ql.conDb.prepareStatement(updatePWD);
         prepStat.setString(1, newPwd);
         prepStat.setString(2, user);
         int zeroNotFound = prepStat.executeUpdate();
         if (zeroNotFound==0)
              ql.conDb.rollback();
              prepStat.close();
         else
              ql.conDb.commit();
              prepStat.close();
    {code}
    ... use the SQLException to capture errors                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • How do you include static text in select statement in Dynamic pl/sql

    I want to include some atatic text and get the output of 4 columns joined with a ":" delimiter within them in a select statement built using Dynamic PL/SQL. How do I build it.
    e.g.
    Normal select statement would be
    select 'MY SKU IS : ', col1||':'||col2||':'||col3||':'||col4 from table1 where ....where condition
    and output looks like :
    MY SKU IS A:B:C:D
    MY SKU IS a:b:c:d
    Dynamically I have -
    SQL_Stmt := 'select 'MY SKU IS : ', col1||':'||col2||':'||col3||':'||col4 from table1 where '|| wherecondition;
    I understand that this does not work because the single quote terminates the string. But my question is how do I achieve the same result with dynamic PL/SQL ? How do I include the static strings and the delimiters. I have tried using double quote, '\'....
    ????

    SQL_Stmt := 'select ''MY SKU is ' || col1 || '':'' ||
                                         col2 || '':'' ||
                                         col3 || '':'' ||
                                         col4 ||
                 ' from table1 where ' || wherecondition;

  • How to create a mapping for a select statement containing DENSE_RANK( )?

    Hi,
    I want help with a select statement that I want to make a mapping of in OWB 11.1 g. Can anyone please tell me how is code can be incorporated in a mapping?
    SELECT DISTINCT MAX (dimension_key) KEEP (DENSE_RANK FIRST ORDER BY day DESC) OVER (PARTITION BY calendar_week_name),
    MAX (day) KEEP (DENSE_RANK FIRST ORDER BY DAY DESC) OVER (PARTITION BY calendar_week_name), calendar_week_end_date, calendar_week_number
    FROM time_dim;I have been trying to use the Aggregator operator but I am not entirely sure how to go about it. Any help will be highly appreciated.
    Thanks in advance,
    Ann.

    Hi Ann
    You can just use an EXPRESSION operator. Configure the mapping to be set based only code generation and operating mode.
    You will have an expression output attribute for each one of your projected columns;
    MAX (dimension_key) KEEP (DENSE_RANK FIRST ORDER BY day DESC) OVER (PARTITION BY calendar_week_name),
    MAX (day) KEEP (DENSE_RANK FIRST ORDER BY DAY DESC) OVER (PARTITION BY calendar_week_name),
    calendar_week_end_date,
    calendar_week_number
    Cheers
    David

  • How to : rownum and order by in select statement

    Say I have a select statement with additional 'order by' clause.
    The result set I want prepended by the rownum column.
    But, and here comes the flaw, I want the rownum for the already ordered result set
    not the unordered.
    An example:
    select firstname, lastname from myTable order by lastname;
    When I add the rownum to the select clause,
    'select rownum, firstname, lastname from myTable order by lastname;'
    I might get something like:
    20 Mike Adams
    13 Nina Bravo
    1 Tom Charlie
    But I want the following result:
    1 Mike Adams
    2 Nina Bravo
    3 Tom Charlie
    I could now
    'Select rownum, lastname, firstname from (select firstname, lastname from myTable order by lastname);
    But I guess there is a better way!?!
    which is the best way to accomplish that?
    Thanks for your advice!

    >
    'Select rownum, lastname, firstname from (select firstname, lastname from myTable order by lastname)
    >
    Well if you ask me there is very little difference between this query and the above query
    select rownum, lastname, firstname from mytable;Because rownum is assigned before the order by. The difference is in your query you are assigning a rownum to an ordered resultset but still there is no guarantee oracle is going to read the data in an ordered fashion. In the second query rownum is assigned to an unordered resultset. Again it is the samething. So if you want to guarantee it then I will go for the following option
    select row_number() over(order by lastname) rn, lastname, firstname from mytable
    order by lastnameAlso check this link.
    http://www.oracle.com/technology/oramag/oracle/07-jan/o17asktom.html
    Regards
    Raj
    Edited by: R.Subramanian on Jan 13, 2009 6:20 AM

  • How to create MIN/MAX limitations in SELECT statement ??

    Hey,
    I have a table which rank90 (city population ranked from 1>*) and state_abrv which has the corresponding state for each city rank.
    Is there a way to select only the maximum AND minimum ranks for each state ??
    I realise there is a max and min function, but i need to do it for EACH state_abrv.
    An example say Los Angeles is ranked 2, San Diego is ranked 6, and San Fransico is ranked 14 (All of these citys are in california (CA)). How do i display a table which lists only Los Angeles (Highest rank) and San Fransico (lowest rank) but DOESNT list San diego ??
    Thanks, you guys are helping me heaps and im starting to learn a lot more :P
    Message was edited by:
    user495524

    SQL> create table t (state varchar2(2), city varchar2(20), n number);
    Table created.
    SQL> insert into t values ('CA','San Francisco',14);
    1 row created.
    SQL> insert into t values ('CA','San Diego',6);
    1 row created.
    SQL> insert into t values ('CA','Los Angeles',2);
    1 row created.
    SQL> insert into t values ('NY','Buffalo',4);
    1 row created.
    SQL> insert into t values ('NY','Syracuse',7);
    1 row created.
    SQL> insert into t values ('NY','Mt Kisco',2);
    1 row created.
    SQL> insert into t values ('NY','Albany',5);
    1 row created.
    SQL> select * from t order by state, n desc;
    ST CITY                          N
    CA San Francisco                14
    CA San Diego                     6
    CA Los Angeles                   2
    NY Syracuse                      7
    NY Albany                        5
    NY Buffalo                       4
    NY Mt Kisco                      2
    7 rows selected.
    SQL> select state, city, n from
      2    (
      3    select t.*, min(n) over (partition by state) min_n,
      4      max(n) over (partition by state) max_n from t
      5    )
      6  where n in (min_n, max_n) order by state, n desc;
    ST CITY                          N
    CA San Francisco                14
    CA Los Angeles                   2
    NY Syracuse                      7
    NY Mt Kisco                      2
    SQL>

Maybe you are looking for

  • How do i map a small business server's windows path to my imac

    Trying to map a Small Business Server's shared drive on my business network to a new iMac on the same network. Ethernet hardwired into network. I can see other PC's but not the server. Trying to enter the server's name and shared drive but having no

  • Connect an external monitor

    I am unable to get my hp pavilion entertainment pc to recognize an external monitor - orion  please help is it my resolution settings? I am using windows vista thanks

  • Mac installer wont even start...

    Hi, On my very old and wise G4 at home, the installer crash at startup, even when the installer is copied on "real" hard drive, not the mounted DMG... EXC_BAD_ACCESS (0x0001) KERN_INVALID_ADDRESS (0x0001) at 0xda000000 Thread 0 Crashed: 0 CSMemDispos

  • Reinstalling windows printer to print in Tiger

    I recently had to uninstall and re-install my windows XP printer (the Brother HL-1435 laser printer) in windows. In doing so, my Powerbook G4 couldn't print to it, so I had to uninstall it and try to re-install it on my mac. The problem is, now i get

  • ATV2: Aired date is incorrect

    Hello, everyone. I've come across a little puzzle that I have not been able to solve so I thought I would post here and see what we might be able to come up with. Also Apple's KB didn't really address the problem either. I have several TV show episod