Column order in a select * query

Suppose I have 256 columns in a table and if I query select * from  tablename ,what will the column order in the result.Will this be always same as order as in created statement?

If the columns were all in the original CREATE TABLE statement, then, yes, the ordering of columns in SELECT * FROM will match the order from the CREATE TABLE statement.
If columns were added after the initial create, then the original columns will come first (in their order) and then the added columns (in their order), etc.
In the real world, it is a very bad practice to use SELECT * and have expectations about the ordering of the columns. Consider this scenario:
Table T was created and implemented in production a year ago with columns A, B, C
A project started up three months ago and added column D but the project is stalled in development. So in development T had columns A, B, C, D
Later, another project started up and added columns E and F. Unlike the other project, it has progressed to Test. and Production. So in Development the table has columns A, B, C, D, E, F. In test and production the table has columns A, B, C, E, F.
Now that stuck project has progressed to Test and Production. Now T has columns A, B, C, E, F, D in test and production but still A, B, C, D, E, F in development.
Until someone notices and decides to fix it (where and how?)
Be very, very careful about using SELECT *.

Similar Messages

  • Order by in select query

    Hi guys
    i am getting problem in my select query which is creating one long string, it is working fine without order by but when i run this with order by it get hanged. this query using on function to concatenate multiple strings in one string as well
    Please help me what i am doing wroing.
    select
    regexp_substr(pe.emp_id,'[0-9]+$') ||'|'||
    p.title ||'|'||
    cdt.text||'|'||
    j.tit||staff_pcb.host_pub_tit ||'|'||
    jou.vol ||pcb.vol||pcp.vol ||'|'||
    jou.journal_number||'|'||
    substr (jou.pages||pcb.pages||pcp.pages, 1, instr (jou.pages||pcb.pages||pcp.pages, '-')-1)||'|'||
    substr (jou.pages||pcb.pages||pcp.pages, instr (jou.pages||pcb.pages||pcp.pages, '-')+1)||'|'||
    pcb.st||jou.st||pcp.st||'|'||
    concat_aut(p.id)
    from pub p,journal j,caa c,person pe,class_t cdt,
    (select pcj.pub_id,pcj.vol,pcj.pages,pcja.st
    From pub_C_j_a pcja,pc_j pcj
    where pcja.pub_c_j_id = pcj.pub_id)jou,
    (select pcb.pub_id,pcb.host_pub_tit,pcb.pages,pcb.vol,pcba.st
    From pub_c_b pcb,pub_c_b_a pcba
    where pcba.pub_c_b_id = pcb.pub_id)pcb,
    (select pcp.pub_id,pcp.vol,pcp.pages,pcpa.st
    From pub_c_p pcp,pub_c_p_a pcpa
    where pcpa.pub_c_p_id = pcp.pub_id)pcp,
    where
    p.id = c.pub_id
    and c.person_id = pe.id
    and p.t_c_id = cdt.c_id
    and p.journal_id = j.id(+)
    and p.id = jou.publication_id(+)
    and p.id = pcb.publication_id(+)
    and p.id = pcp.publication_id(+)
    and substr(regexp_substr(pe.emp_id,'[0-9]+$'),1,2) in('77','78')
    and pcb.st||jou.st||pcp.st='1' order by pe.emp_id
    ;

    Not sure about why it's only hanging on order by but looks like your query causing full table scan because of this in WHERE clause:
    and pcb.st||jou.st||pcp.st='1'
    I would change it to something like:
    and ((pcb.st='1'  and jou.st = '' and pcp.st = '') or (jou.st='1'  and pcb.st = '' and pcp.st = '')  or (pcp.st='1'  and jou.st = '' and pcb.st  = '') )

  • How to pull only column names from a SELECT query without running it

    How to pull only column names from a SELECT statement without executing it? It seems there is getMetaData() in Java to pull the column names while sql is being prepared and before it gets executed. I need to get the columns whether we run the sql or not.

    Maybe something like this is what you are looking for or at least will give you some ideas.
            public static DataSet MaterializeDataSet(string _connectionString, string _sqlSelect, bool _returnProviderSpecificTypes, bool _includeSchema, bool _fillTable)
                DataSet ds = null;
                using (OracleConnection _oraconn = new OracleConnection(_connectionString))
                    try
                        _oraconn.Open();
                        using (OracleCommand cmd = new OracleCommand(_sqlSelect, _oraconn))
                            cmd.CommandType = CommandType.Text;
                            using (OracleDataAdapter da = new OracleDataAdapter(cmd))
                                da.ReturnProviderSpecificTypes = _returnProviderSpecificTypes;
                                //da.MissingSchemaAction = MissingSchemaAction.AddWithKey;
                                if (_includeSchema == true)
                                    ds = new DataSet("SCHEMASUPPLIED");
                                    da.FillSchema(ds, SchemaType.Source);
                                    if (_fillTable == true)
                                        da.Fill(ds.Tables[0]);
                                else
                                    ds = new DataSet("SCHEMANOTSUPPLIED");
                                    if (_fillTable == true)
                                        da.Fill(ds);
                                ds.Tables[0].TableName = "Table";
                            }//using da
                        } //using cmd
                    catch (OracleException _oraEx)
                        throw (_oraEx); // Actually rethrow
                    catch (System.Exception _sysEx)
                        throw (_sysEx); // Actually rethrow
                    finally
                        if (_oraconn.State == ConnectionState.Broken || _oraconn.State == ConnectionState.Open)
                            _oraconn.Close();
                }//using oraconn
                if (ds != null)
                    if (ds.Tables != null && ds.Tables[0] != null)
                        return ds;
                    else
                        return null;
                else
                    return null;
            }r,
    dennis

  • Default in "order by" in select query may be different in 11g from 10g

    Hi, I am wondering if when you are querying a table in 11g and you use the order by clause and there is more than one occurrences with the same values in the order by, if the 11g default is different than from 10g.  For instance.
    DECLARE MHBulk CURSOR FOR                       
      select invoice_nbr,
                   customer_nbr,
                    post_century,
                    post_yymmdd,
         from CUSTOMERS
         where customer_nbr = 1234
         order by
               post_century,
               post_yymmdd;
    If you have more than one occurrence of the same customer_nbr, post_century, and post_yymmdd it looks like the default order for how 11g retrieves the records is a bit different than the 10g default.   Does anyone know why this is?

    JustinCave wrote:
    In any version of Oracle, if your ORDER BY does not specify a completely unique order, the order in which ties are broken is arbitrary.  Realistically, it will depend on things like the specific query plan chosen, the physical order of data on disk, which parallel query slave read the row, etc.  So it is subject to change within the same version of the database when, for example, a query plan changes.  It is entirely plausible that the results would be returned in the same order for years and then suddenly change one day.  If you care about the order of ties, you should add additional logic to the ORDER BY clause that specifies the order you want rather than assuming that there is a "default" order applied.
    Upgrading to a new version of Oracle, particularly if that was done via something like exporting and importing the data so that you're changing the Oracle version and the physical order of data and various object statistics, it is not at all unusual that you would get slightly different plans and that ties would be broken differently.  I wouldn't assume that there is a new "default" order, though.  It's entirely possible for the order to change if the query plan changes again.
    Justin
    Well, what happened is we've gotten a few new customers and those customers are on Linux oracle 11g.  All the other customers are on regular unix 10g.  So, it sounds like we've just been lucky with the order until now.  In our system we have a sequence number column which is unique and I solved this by adding that in the ORDER BY clause.  I was just curious as to whether oracle had a default when it found duplicate fields in the ORDER BY clause.  I can't imagine that oracle doesn't have a default like unique_session_id or something like that.

  • Is that important column order in a query with row_number function

    Hi folks,
    I am using Oracle 11g R2 on HP-UX machine.
    I have 2 types of query with row_number and I think they are same but output of each of them are different. I changed only column order in query2.
    Query 1 :
    (SELECT
    "LOOKUP_INPUT_SUBQUERY"."CONTRACT_SK" "CONTRACT_SK",
    "LOOKUP_INPUT_SUBQUERY"."SIMCARD_SK" "SIMCARD_SK"
    FROM (
    SELECT row_number ()
    OVER (
    PARTITION BY "R_CON_SUBS_SIMCARD_LK".
    "CONTRACT_SK"
    ORDER BY
    "R_CON_SUBS_SIMCARD_LK"."START_DATE" DESC,
    "R_CON_SUBS_SIMCARD_LK"."SEQ_NUM" DESC NULLS LAST) /* EXPRESSION_3.OUTGRP1.SIRA */
    "SIRA",
    "R_CON_SUBS_SIMCARD_LK"."CONTRACT_SK" "CONTRACT_SK",
    "R_CON_SUBS_SIMCARD_LK"."SIMCARD_SK" "SIMCARD_SK"
    FROM "SRC_OZRDS"."R_CON_SUBS_SIMCARD_LK" "R_CON_SUBS_SIMCARD_LK")
    "LOOKUP_INPUT_SUBQUERY"
    WHERE ("LOOKUP_INPUT_SUBQUERY"."SIRA" = 1))
    Output of this like that :
    CONTRACT_SK SIMCARD_SK
    1     1
    1     3
    1     4
    1     5
    1     6
    1     11
    1     12
    1     14
    1     15
    1     16
    Query 2 :
    (SELECT
    "LOOKUP_INPUT_SUBQUERY"."CONTRACT_SK" "CONTRACT_SK",
    "LOOKUP_INPUT_SUBQUERY"."SIMCARD_SK" "SIMCARD_SK"
    FROM (
    SELECT
    "R_CON_SUBS_SIMCARD_LK"."CONTRACT_SK" "CONTRACT_SK",
    "R_CON_SUBS_SIMCARD_LK"."SIMCARD_SK" "SIMCARD_SK",
    row_number ()
    OVER (
    PARTITION BY "R_CON_SUBS_SIMCARD_LK".
    "CONTRACT_SK"
    ORDER BY
    "R_CON_SUBS_SIMCARD_LK"."START_DATE" DESC,
    "R_CON_SUBS_SIMCARD_LK"."SEQ_NUM" DESC NULLS LAST) /* EXPRESSION_3.OUTGRP1.SIRA */
    "SIRA"
    FROM "SRC_OZRDS"."R_CON_SUBS_SIMCARD_LK" "R_CON_SUBS_SIMCARD_LK")
    "LOOKUP_INPUT_SUBQUERY"
    WHERE ("LOOKUP_INPUT_SUBQUERY"."SIRA" = 1))
    Output of this like that:
    2     874812
    7     70097256
    8     18734091
    9     158024
    10     815397739
    13     22657919
    19     83177779
    20     82579529
    22     5829949
    23     35348926
    25     3865978
    I expected the second output, because there are lots of contract sk but there is one contract_sk in first query result. i did not get the point. What is the problem ?

    user8649469 wrote:
    I changed only column order in query2.So what else do you expect? If you order, for example, by last name, fist name don't you think rows will be returned in a different order (and therefore same row will have different row number) than ordering by first name, last name?
    SY.

  • Changed column order not applied to interactive report

    Hi,
    I've changed column order for interactive report.
    But it is not applied.
    How can I solve this issue?
    Thanks,
    Guy

    Hi Guy
    It depends on where you have changed the column order. If you change the column order using the 'Select Columns' function when you click on the 'Wheel of Magic', then it should work.
    If you are changing the column order from the Interactive Reports Attributes page then this will only affect the column order for non displayed items and the single row view.
    I hope that helps
    Shunt

  • Report Does Not Follow Select Column Order

    Hi all,
    Apex 2.2 on 10gXE
    I always encounter this problem, the display column on report does not follow the select column sequence order in the "region source".
    It is very tedious clicking the up/down arrow one-by-one in the "report attributes" especially if the display columns are plenty like 40 columns.
    Is there a fix/patch or alternative tips for this bug?
    Thanks a lot,
    Edited by: 843228 on May 24, 2011 10:32 PM

    Apex 2.2 on 10gXEStart by upgrading from this old unsupported version.
    >
    I always encounter this problem, the display column on report does not follow the select column sequence order in the "region source".
    It is very tedious clicking the up/down arrow one-by-one in the "report attributes" especially if the display columns are plenty like 40 columns.
    Is there a fix/patch or alternative tips for this bug?
    >
    This is not a bug. APEX maintains the original column order of the report. This avoids problems downstream in areas like the processing of <tt>g_fnn</tt> arrays in declarative tabular forms, where the assigned arrays are column-order dependent.
    APEX 4.x fixes column ordering bugs that could lead to report corruption, and includes drag-and-drop column ordering in the new tree view in addition to the up/down arrow re-ordering.
    If you really want column order to follow that in the source query, the workaround is to create a new report using the modified query.

  • Select query gives result in abc order instead of creation order

    Hi,
    I used the following command in sql command window to insert some rows to my table:
    SQL>
    SQL> insert into regions (Region_ID, Region_Name) values (1 , 'Zafon');
    1 row inserted
    SQL> insert into regions (Region_ID, Region_Name) values (2 , 'Hasharon');
    1 row inserted
    SQL> insert into regions (Region_ID, Region_Name) values (3 , 'Merkaz');
    1 row inserted
    SQL> insert into regions (Region_ID, Region_Name) values (4 , 'Jerusalem');
    1 row inserted
    SQL> insert into regions (Region_ID, Region_Name) values (5 , 'Hashfela');
    1 row inserted
    SQL> insert into regions (Region_ID, Region_Name) values (6 , 'Darom');
    1 row insertedWhen I use select * query to see the table, I get the content in abc order:
    SQL> SELECT * FROM REGIONS;
    REGION_ID REGION_NAME
            6 Darom
            2 Hasharon
            5 Hashfela
            4 Jerusalem
            3 Merkaz
            1 Zafon
    6 rows selectedHow can I get the result in the creation order (first created- first shown)?
    Thanks

    >
    How can I get the result in the creation order (first created- first shown)?
    >
    You can't - not unless you use a solution that you should NEVER use unless absolutely necessary.
    WHY do you need to do this? You never provide a reason.
    To get a result in creation order there are two requirements:
    1. Use an ORDER BY when you query the table - this is the only requirement others have mentioned
    2. Control and specify the creation order when you INSERT the data
    Unfortunately there is only ONE way that I am aware of to implement #2 above (i.e. to control the insertion order) and that is to SERIALIZE the insertion of rows into the table. That means that only ONE user can insert rows into the table at a time perhaps by using a stored procedure to perform the insert.
    In a multi-user system a USER can NOT see uncommitted data of other users. If a user uses a trigger and a SEQUENCE generator to generate ascending numbers another user can use that same trigger and sequence to generate numbers also. If the first user performs an INSERT and gets number 37 but doesn't commit a second user can perform an INSERT, get number 38 and COMMIT before the first user commits.
    That means that the row with 38 was created (committed) first but has a higher sequence than the row with 37.
    The best you can do is use a sequence generator to generate unique ascending numbers. Then you can query the data using an ORDER BY on the column that contains the sequence value. But, as shown above, that doesn't guarantee that the rows were actually committed in that order.
    That may sound like a trivial distinction but it has a very important implication. It means that you can NOT use that sequenced column to extract data reliably for batch-type processing. For the above example supposed your batch process extracted data for values from 1 to 38 and then that first user did a COMMIT.
    The next extract would be for values from 39 to 50 (or some other value) and the row with 37 would never be extracted. For the same reasons you can't use a CREATION_DATE value for such extract purposes either since you would have the same issue.

  • How to create a Type Object with Dynamic select query columns in a Function

    Hi Every One,
    I'm trying to figure out how to write a piplined function that executes a dynamic select query and construct a Type Object in order to assigned it to the pipe row.
    I have tried by
    SELECT a.DB_QUERY INTO actual_query FROM mytable a WHERE a.country_code = 'US';
    c :=DBMS_SQL.OPEN_CURSOR;
    DBMS_SQL.PARSE(c,actual_query,DBMS_SQL.NATIVE);
    l_status := DBMS_SQL.EXECUTE(c);
    DBMS_SQL.DESCRIBE_COLUMNS(c, col_cnt, rec_tab);
    FOR j in 1..col_cnt LOOP
    DBMS_SQL.DEFINE_COLUMN(c,j,v_val,2000);
    END LOOP;
    FOR j in 1..col_cnt LOOP
    DBMS_SQL.COLUMN_VALUE(c,j,v_val);
    END LOOP;
    But got stuck, how to iterate the values and assign to a Type Object from the cursor. Can any one guide me how to do the process.
    Thanks,
    mallikj2

    Hi Justin,
    First of thanks for your reply, and coming to my requirement, I need to report the list of items which are there in the dynamic select statement what am getting from the DB. The select statement number of columns may vary in my example for different countries the select item columns count is different. For US its '15', for UK it may be 10 ...like so, and some of the column value might be a combination or calculation part of other table columns (The select query contains more than one table in the from clause).
    In order to execute the dynamic select statement and return the result i choose to write a function which will parse the cursor for dynamic query and then iterate the values and construct a Type Object and append it to the pipe row.
    Am relatively very new for these sort of things, welcome in case of any suggestions to make it simple (Instead of the function what i thought to work with) also a sample narrating the new procedure will be appreciated.
    Thanks in Advance,
    mallikj2.

  • Facing problem with a date column in select query

    Hi,
    I am facing problem with a date column. Below is my query and its fainling with " invalid number format model" .
    Query: SELECT *
    FROM EMP
    WHERE trunc(LAST_UPDATED) >= to_date(to_char(22-05-2009,'dd-mm-yyyy'),'dd-mm-yyyy')
    LAST_UPDATED column is "DATE" data type.
    Please help me Thanks

    Radhakrishna Sarma wrote:
    SeánMacGC wrote:
    WHERE LAST_UPDATED >= to_date('22-05-2009','dd-mm-yyyy');
    You do not need the TRUNC here in any case.
    I don't think so. What if the user wants only data for 22nd May and the table has records with date later than 22nd also? In that case your query willl not work. In order for the Index to work, I think the query can be written like this I think Sean is right though. Use of TRUNC Function is quiet useless based on the condition given here, since the to_date Function used by OP will always point to midnight of the specified date, in this case 22-05-2009 00:00:00.
    Regards,
    Jo
    Edit: I think Sean proved his point... ;)

  • Times ten not showing the column alias as column header in select query.

    Hi All,
    I am trying to execute following queries on TimesTen database 11.2.2.2.0.
    SELECT ROWNUMBER,
    floor((to_date(TO_CHAR(SYSDATE,'YYYY-MM-DD hh24:mi:ss'), 'YYYY-MM-DD hh24:mi:ss')-to_date(TO_CHAR(starttime,'YYYY-MM-DD hh24:mi:ss'), 'YYYY-MM-DD hh24:mi:ss'))*24)
    || 'h '
    || mod(floor((to_date(TO_CHAR(SYSDATE,'YYYY-MM-DD hh24:mi:ss'), 'YYYY-MM-DD hh24:mi:ss')-to_date(TO_CHAR(starttime,'YYYY-MM-DD hh24:mi:ss'), 'YYYY-MM-DD hh24:mi:ss'))*24*60),60)
    || 'm '
    || mod(floor((to_date(TO_CHAR(SYSDATE,'YYYY-MM-DD hh24:mi:ss'), 'YYYY-MM-DD hh24:mi:ss')-to_date(TO_CHAR(starttime,'YYYY-MM-DD hh24:mi:ss'), 'YYYY-MM-DD hh24:mi:ss'))*24*60*60),60)
    || 's' TIME_DIFFERENCE
    FROM
    (SELECT ROW_NUMBER() OVER (ORDER BY USERIDENTITY DESC) ROWNUMBER,
    u.*
    FROM TBLMCORESESSIONS u
    WHERE 1=1
    ) B
    WHERE ROWNUMBER BETWEEN 1 AND 5
    and I am getting the follwing output.
    ROWNUMBER,
    < 1, 8h 52m 34s >
    < 2, 8h 54m 24s >
    < 3, 8h 54m 13s >
    < 4, 8h 55m 6s >
    < 5, 8h 54m 40s >
    The issue is I should get TIME_DIFFERENCE as column header but it is not showing TIME_DIFFERENCE as the column header & it is calculating the value just fine .
    & if same query I execute on oracle 11g database every thing works fine.
    please suggest me something that column header is must.
    or suggest me any other for query
    Edited by: hiaditya04 on Apr 24, 2012 11:05 AM

    Hi,
    It is similar to bug which is raised in Timesten 11.2.2.2.. BUG 13896607 - COLUMN NAME MISSING FROM A VIEW IN TIMESTEN 11.2.2.2 . If you have MOS access then you can view about this bug. The bug is going to be fix in the future release. The bug basically indicates that we are not displaying the column name properly when select list contains complex expressions. The column itself can be accessed and values are displayed correctly.
    Regarding your issue "column TIME_DIFFERENCE not found" , I would suggest you to access the column by position, not by name like below
    I believe you are trying to access your column like below
    resultset.getString(“TIME_DIFFERENCE”)
    Instead of this you can use : -- resultset.getString(2) ( this position should based on the position of the column you are using in the query)
    Hope this helps.
    Regards
    Rajesh

  • Column order in SQL Query (PL/SQL function returning a query)

    Hi,
    when I define a PL/SQL function returning a query inside a region, I often find that the column order is arbitrarily changed.
    How do I enforce the column order ?
    Bye,
    Flavio

    I removed the 11th column called service_name from this dynamic query: and now the report says: report error:
    ORA-01403: no data found. I messed around with the Headiuns Type. It was set to Custom. I changed it to Column Names. There is no difference.
    I am not sure how to fix?
    declare topqry varchar2(32000);
    whereqry varchar2(32000);
    finalqry varchar2(32000);
    var_status varchar2(100);
    division_status varchar2(50);
    office_status varchar2(1000);
    user_status varchar2(1000);
    overdue_status varchar2(1000);
    begin
    if :P10_FALLBACK = 'All' then
    var_status:= ' and vp.status in (''FA'',''FBA'',''FBI'',''25%'',''50%'',''90%'',''Closed'') ';
    elsif :P10_FALLBACK = 'Active' then
    var_status:= ' and vp.status in (''FA'',''25%'',''50%'',''90%'',''FBA'') ';
    elsif :P10_FALLBACK = 'FB' then
    var_status:= ' and vp.status in (''FBA'',''FBI'') ';
    elsif :P10_FALLBACK = 'Closed' then
    var_status:= ' and vp.status in (''Closed'') ';
    elsif :P10_FALLBACK = 'Inactive' then
    var_status:= ' and vp.status in (''FBI'') ';
    end if;
    if :P10_DIVISION = 'All' then
    division_status:= ' and vp.vms_division in (''News'',''Ad Services'') ';
    elsif :P10_DIVISION = 'News' then
    division_status:= ' and vp.vms_division in (''News'') ';
    elsif :P10_DIVISION = 'Ad' then
    division_status:= ' and vp.vms_division in (''Ad Services'') ';
    end if;
    if :P10_OFFICE = '%' then
    office_status:= ' and OFFICE_ID in (select office
    from VMS_OFFICE_ACCESS
    where user_id = lower(:P0_user) ) ';
    else
    office_status:= ' and OFFICE_ID in :P10_OFFICE ';
    end if;
    if :P10_LIMIT_USER = '%' then
    user_status := ' and SALESPERSON in (select first_name || '' '' || last_name
    from VMS_PROSPECT_users u
    join vms_office_access o
    on u.office_id = OFFICE
    where o.user_id = lower(:P0_USER) ) ';
    else
    user_status:= ' and SALESPERSON in (:P10_LIMIT_USER ) ';
    end if;
    if :P10_SHOW_OVERDUE = 'Show' then
    overdue_status:= ' and target_close_date <= sysdate ';
    var_status:= ' and vp.status in (''25%'',''50%'',''90%'',''FBA'') ';
    else
    overdue_status:= ' and FIRST_APPOINTMENT between
    nvl(to_date(:P10_FIRST_APPT_START, ''mm/dd/yyyy''),FIRST_APPOINTMENT) and
    nvl(to_date(:P10_FIRST_APPT_END,''mm/dd/yyyy''),FIRST_APPOINTMENT) ';
    end if;
    topqry := 'SELECT OFFICE_ID ,vp.PROSPECT_ID ,ENTRY_DATE ,ACCOUNT , NEXT_CONTACT_DATE ,ACTION_STEP ,
    TARGET_CLOSE_DATE ,vp.STATUS ,SALESPERSON ,vp.SALES_TYPE ,service_name , FIRST_APPOINTMENT ,MODIFY_DATE ,EST_ANNUAL_REVENUE ,EST_INCREMENTAL_REVENUE ,
    pi.NOTES , pi.SALES_TYPE ,pi.STATUS ,Contact ,Origin_Source FROM VMS_PROSPECTING_ITEMS pi right outer join VMS_PROSPECTS vp on vp.PROSPECT_ID = pi.PROSPECT_ID left outer join VMS_SERVICES vs on vs.service_ID = pi.service_ID where 1 = 1 ';
    whereqry := ' and (not exists (select *
    from VMS_PROSPECTING_ITEMS i3
    where vp.prospect_id = i3.prospect_id)
    or exists (select *
    from VMS_PROSPECTING_ITEMS i2
    where i2.order_id = pi.order_id
    and active = ''Y'' )) and instr(upper(ACCOUNT),upper(nvl(:P10_ACCOUNT,ACCOUNT))) > 0 ';
    whereqry := whereqry || var_status || division_status || office_status || user_status || overdue_status;
    finalqry := topqry || whereqry;
    return finalqry ;
    end;

  • MDO select query: how to control sort order using parameter

    Hi experts, is there a way of controling the sort order of an MDO select query using some parameter?
    I was thinking about using some statement like CASE [Param.1] WHEN 'abc' THEN [ORDER_NO]...END in sort section of the query but it is not working.
    Of course I colud go for various select queries...but I am wondering if it can be done using only one?
    Any ideas?
    Thanks for any help

    Hi Marco,
    Yes this can be achieved dynamically using SortExpr under dynamic link assignment in MDOAction block if you are using a transaction to call it.
    Please check below thread:
    Re: MDO Query Action Block In MII Transaction
    Or else, this [Param.1] thing should work as well provided it doesn't get the logic part in it, just pass the columns names separated by comma. Haven't tried it though, will check it for you.
    Best Regards,
    Swaroop

  • Select * columns order

    Is it possible, that "SELECT *" returns records, where columns are
    ordered in a different order, than the order they were
    positioned/specified when table was created?
    For example, lets assume that table T contains columns c1,c2,..c10.
    Can this be possible, that the * (asterisk) shows the columns in a
    different orderm the c1 and c10 changed their position for example:
    query:
    "SELECT * FROM T"
    results:
    c10, c2, c3, .., c9, c1.
    I think you anderstood my question now.
    The sql-standard doesn't tell about it nothing, but i have heard that
    "selesct *" can produce columns in a random order in some situations.
    Notice, that i'm not talking about "ORDER"-operator. I have heard that if one make a table with plenty of columns and adds plenty of indexes and constraints to the columns, then "select *" really will produce mistery column order.
    Thank you for answering,
    Regards.

    FWIW I suspect that block structure is not a factor either.
    Consider
    SQL> CREATE VIEW v AS SELECT * FROM emp;
    View created.
    SQL> desc emp
    Name                          Null?    Type
    EMPNO                         NOT NULL NUMBER(4)
    ENAME                                  VARCHAR2(10)
    JOB                                    VARCHAR2(9)
    MGR                                    NUMBER(4)
    HIREDATE                               DATE
    SAL                                    NUMBER(7,2)
    COMM                                   NUMBER(7,2)
    DEPTNO                                 NUMBER(2)
    SQL> desc v
    Name                          Null?    Type
    EMPNO                         NOT NULL NUMBER(4)
    ENAME                                  VARCHAR2(10)
    JOB                                    VARCHAR2(9)
    MGR                                    NUMBER(4)
    HIREDATE                               DATE
    SAL                                    NUMBER(7,2)
    COMM                                   NUMBER(7,2)
    DEPTNO                                 NUMBER(2)
    SQL> WITH accounting_emp  AS (SELECT * FROM v WHERE deptno = 10)
      2     , accounting_dept AS (SELECT * FROM dept WHERE deptno = 10)
      3  SELECT *
      4  FROM   ( SELECT * FROM accounting_dept )
      5*      , ( SELECT * FROM accounting_emp );
    DEPTNO DNAME          LOC           EMPNO ENAME      JOB         MGR HIREDATE    SAL  COMM DEPTNO
        10 ACCOUNTING     NEW YORK       7782 CLARK      MANAGER    7839 09-JUN-81  2450           10
        10 ACCOUNTING     NEW YORK       7839 KING       PRESIDENT       17-NOV-81  5000           10
        10 ACCOUNTING     NEW YORK       7934 MILLER     CLERK      7782 23-JAN-82  1300           10
    3 rows selected.This returns rows in a consistent (if apparently undocumented) order, which seems to be something like:
    * Tables/views in FROM list
    * SELECT list
    * SELECT list within views in FROM list
    * SELECT list of subquery factoring clause
    * ALL_TAB_COLUMNS.COLUMN_ID (for tables and views)
    * ALL_TYPE_ATTRS.ATTR_NO for attributes of object types
    If it did not, it would break many valid PL/SQL constructions as others have mentioned, including %ROWTYPE , UPDATE ... SET ROW, INSERT ... VALUES [record], and INSERT without column list. This type of failure will be familiar to those developing invoker rights packages, since the table found at runtime could have columns in a different order than the one compiled against, which will produce effects such as values appearing in the wrong attributes of %ROWTYPE records.

  • Select query help for Sales order

    Hi Experts,
    I have to write a select query to fetch sales orders which are open along with the quantities which are open ( not delivered). What would the best approach for this?
    Any help is appreciated. Expecting code samples....Thanks
    Thanks
    Ricky

    hi,
    do like this,
    write a select query for vbak and vbuk as follows.
    delivery status field is <b>lfstk</b> from <b>vbuk</b>,
    and relation field is <b>vbeln</b> from the both the tables.
    reward points if useful,
    regards,
    seshu.

Maybe you are looking for

  • Multiple Payslips in PDF Document

    Hi All, We have a requirement of getting multiple Payslips in a single PDF document. Right now, we use the Java Webdynpro application to display payslips in ESS using a custom HR Form / Smartform. This allows us to display a single payslip in PDF for

  • 3 beeps when trying to install, but ram is fine

    I installed bootcamp and removed my OSX partitlon to install Windows 8 on my Macbook Pro.  Currently the machine is running Windows 8 without any problems but I want to install OSX again.  BUT when i put in my OSX install disk and it tries to load ,

  • How can I get a Leopard Install Disk?

    Hi there, I have a 13" MacBook Mid-2007 model and it ran into some problems, I got a Apple MacBook 13" Mac OS X LEOPARD 10.5.6 disk off eBay, but I get an error everytime I boot, says "Mac OS X cannot be installed on the computer." Also, I'd kinda li

  • How to take input from scanner machine

    Hello friends I am working on a application in which my task is to getting the data from scanner and store in IMAGE format on any particular location on Disk but i am not able to get data from Scanner machine as input and store that as image format S

  • Datapump exp and imp using API method

    Good Day All, I want to know what is the best way of error handling of datapump export and Import using API. I need to implement in my current project as there lot of limitations and the only way to see the process worked is writing the code with err