Select based on rownum

Experts I need your input.
We have a select sql query to spool data into a flat file. There can be scenario where we need to split that spooled file into multiple data files due to size limits in staging location and transfer data limits. Given this scenario which one would be the better solution.
Solution 1. Basic select statement to select necessary data upon which there will be wrapper query which will restrict the data based on rownum
Ex:-
Basic select query
select * from table_a
Spoole file 1 will have
Select table_a_id
From (select * from table_a)
Where rownum >0 and rownum<101
Spool file 2 will have
Select table_a_id
From (select * from table_a)
Where rownum >100 and rownum<201
And so on..
Solution 2. One select statement which spools all the selected data into a spool file.
Ex:
spool test.spl
Select * from table_a_id
From table_a
Then split the file into multiple files using unix split command.
I think in step 1 all though it seems like multiple parallel queries can be run to extract data but, the inline view, which is our basic select statement selects the complete data from the table then it restricts data output based on rownum. So each select query execution time will be equal to or more time than its inline sql query execution time.
Say if our basic select statement takes 30 mnts to query then the select statement in each spool files takes 30 or more than 30 mnts to query.
Am I right in my assumtion?
Pls advise
S

First off, the proposed queries to populate the 2 spool files are incorrect. The second statement will never return any rows and you have no order by clause, so you're selecting an arbitrary 100 rows in the first query. If you want to do something like this, you'd need something like (stolen from asktom.oracle.com at http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:127412348064)
select *
  from ( select a.*, rownum rnum
           from ( YOUR_QUERY_GOES_HERE -- including the order by ) a
          where rownum <= MAX_ROWS )
where rnum >= MIN_ROWSSecond, assuming you're using Tom's syntax, Oracle will be smart enough not to have to materialize every row from the table in order to return the range you want. That being said, the larger MAX_ROWS value, the more rows have to be materialized and the slower the query gets. The presence of an ORDER BY may force Oracle to do some additional work depending on the access path. You also have to start worrying about contention for resources among parallel queries.
I'd tend to prefer the Unix split command all things being equal.
Justin

Similar Messages

  • How do I handle my Final SELECT based on a @ReportType Run Parameter

    So I have multiple CTEs in my SQL...
    WITH CTE_1 AS
    (SELECT...)
    CTE_2 AS
    (SELECT...)
    CTE_3 AS
    (SELECT...)
    My Final SELECT then will be based on my CTE drill-downs and the filtering will be based on the @ReportType that will be chosen within SSRS and Report Manager. How can I handle the varying portions of my FINAL SELECT based on @ReportType? Do I have to do
    this via dynamic SQL? I know that dynamic SQL is frowned upon. So this is what I'm talking about...
    SELECT ...
    CASE WHEN @ReportType = 'Renewal People'
    THEN INNER JOIN...
    WHEN @ReportType = 'New People'
    THEN NOT IN (SELECT...)
    END
    CASE WHEN @ReportType = 'Renewal People'
    THEN WHERE...
    WHEN @ReportType = 'New People'
    THEN WHERE...
    END

    > I know that dynamic SQL is frowned upon.
    That depends. I love (*) dynamic SQL for one thing:
    http://www.sqlusa.com/bestpractices/dynamicsql/
    Second, there are many things you cannot in static SQL:
    http://www.sqlusa.com/bestpractices2008/rebuild-all-indexes/
    * First choice is static SQL always.
    Kalman Toth Database & OLAP Architect
    SQL Server 2014 Database Design
    New Book / Kindle: Beginner Database Design & SQL Programming Using Microsoft SQL Server 2014

  • Is it possible to lock guides to each other? Or make selections based on guides??

    Hi,
    I am curious if there is a way to lock guides to one another.  By this I mean:  lets say I have a guide at 10px down and another at 20px.  I am looking for a way to lock them, so if I move the first guide down 5px the second guide will move with it and continue to maintain the 10px gap.
    Also I am wondering if there is a way to make selections based on guides.  For example, I want to make a selection that starts at the top guide and goes to the bottom guide.
    Thanks to anyone that can help!
    G

    There is no way to link guides directly. Here are some guide tips for you which may help…
    • Setting the ruler increment can be done by control clicking (yes control) on the rulers themselves,
    • Holding down the SHIFT key while dragging guide lines will snap those guides to ruler increments. So if you have pixels selected as the increment as in the tip above you can easily snap quides to 10 pixel steps. Where the guides will snap (how fine the increment) is dependant on how close you are zoomed.
    • As Christoph has said, you can snap to Guides - so in your example a 10 pixel marquee selection, definable in the marquee tool options bar (fixed size) can easily be snapped to a guide, and then another guide can be snapped to that. With the move tool active this is a very easy process

  • Dynamic row selection based on Page member selection in Planning web-form

    Hello experts
    I have requirement where, user dont want 10 webforms to enter 2 accounts line for various sparse members. Below is the dimension detail and web-form current design
    Account - Dense
    Period - Dense
    Year - Sparse
    Scenario - Sparse
    Version - Sparse
    Entity - Sparse
    Product - Sparse (600 level 0 members)
    Product dim has family1 as parent and 40 level 0 mem like that there are 10 family level 1 members, now to enter account member (only 2 member) for 6 years projection ( it means 12 periods and 6 years in column ) , i can build 10 web-forms with one web-form has one family level-0 mem in rows,
    however my question, is how can i achieve this in one web-form, instead of 10 web-forms for 400 products ?
    your help is greatly appreciated.
    Edited by: 859874 on Jul 18, 2012 8:58 PM

    Im not sure there is any simple way to get dynamic row selection based on what is selected in the page.
    If I were designing the form based on what you have stated, I would probably stick both Account and Year in the page, and the 400 products in rows. This would require the user to select the different combinations of Year / Account, but would mean only 12 columns (instead of 72).
    Alternatively you could stick Account in rows too - meaning 800 rows, but less combinations to select in Page....all depends what is deemed acceptable to the user.
    Probably other approaches that may be better than above (put Product in the Page for fun!!)
    Thanks
    JB

  • How to dynamic select based on runtime value ?

    how to dynamic select based on runtime value ?
    I want to write a select function, which do selecting based on parameters. eg,
    CREATE OR REPLACE FUNCTION myfunction
    (tableName VARCHAR2, pkName VARCHAR2, pkValue VARCHAR2, requestString VARCHAR2)
    RETURN VARCHAR2 AS
    BEGIN
    select requestString from tableName where pkName=pkValue;
    RETURN NULL;
    END;
    myfunction('users', 'user_id', '100', 'user_name'); it will select 'user_name' from table 'users' where 'user_id' = '100'.
    This way could save lots of coding. but it can't pass compiler. how to work out ?
    Thanks.

    While this may save code, if used frequently it will be ineffecient as all [explicative deleted]. The danger is that it would be used even for repeatable statements.
    This mode of operation ensures that every statement [calling the funciton] needs to be reparsed, which is extremely expensive in Oracle (in CPU cycles, recursive SQL and shared pool memory).
    Such reparsing is rarely a good thing for the environment ... it could easily lead to buying more CPU (bigger box) and therefore adding more Oracle license ... which could quickly exceed the typical developer's salary.
    However - if you really, really want to do this, look up 'execute immendiate' in the PL/SQL manuals.

  • Hyperion FR , Planning Details, Limit member selection based on access.

    Hi There
    I am working on a project
    Version 11.1.2.2, FR connected with "Planning Details""
    I want to limit POV "Entity" member selection based on access right and I don't want to set User POV one by one.
    For ex:
    US users don't need to see Canada users' entity.
    I am looking for a solution or workaround that can be easy to manage and save time.
    Highly appreciate and Thanks

    You can actually set the default values in jconsole. jconsole can be started with FRConfig.cmd (normally under C:\Oracle\Middleware\EPMSystem11R1\products\biplus\bin).
    Change the value of "com.hyperion.reporting.HRPrefs.filter_by_security" to true, this way, the the default values will be true for all users who haven't set it in user preference yet.
    This will list only the members which the users has access.
    I believe this is what you are looking for.
    Edited by: Krishna Kumar K P on Sep 14, 2012 9:50 AM

  • Apex 3.2 Tabular form - dynamic selection based on prev selection

    Hi guys,
    I am using apex 3.2. I am having difficulty in setting up a tabular form which provides an option to record information in other columns based on a value selected in the drop down.Here is an example
    I have a table product. All the products are added using a tabular form by selecting type from a drop down list.
    This allows the user to add multiple products without having to press save each time.
    e.g.
    product | type
    monopoly | game
    vase | home
    coffee | food
    cards | game
    Depending on the product type, I want the user to be able to multi-select other options using checkboxes based on the option selected.
    So for example if they add a product of type food, it should give additional options like beverage, cereal etc. If they select game, then they should get other options like for age_groups 10-12; 12-16; 18 and over;
    Is it posisble to do this on a tabular form in apex 3.2?
    If yes, please can someone help.
    Thanks
    Sam

    Closed

  • Inspection plan selection based on production workcenter for Inspection typ

    Dear QM Guru's,
    I have requirement of automatic inspection lot creation based on production work center.
    For example :- I have Inspection Plan A, Plan B and Plan C for Material XYZ. My requirement is that, when inspection lot created for material XYZ ,when we release production order (Early lot creation) , it should create inspection lot based on production work centers in the order. In this case, if production workcenter A is in the prodiction order, system automatically assigned inspection plan A, when workcenter B,it should choose inspection plan B and same for C workcenter.
    Can we have this set up in the system?
    Let me know if u need any other details.
    Thanks in advance.

    The workcenters in QM and PP don't have to be the same.  In the user exit your going to code in the logic you want to use to select the inspection plan.
    I suggested creating the workcenters the same and the code can use that info to match up the correct task list group to assign the inspection lot. But if that doesn't work pick something else.
    Your code can use any logic you want.  You can put a description in the short text if you want. 
    You can just have an understanding that task list group 10 is always used for production work center XYZ and task list group 20 is always used for production work center ABC and task list group  30 is always used for production work center 123.  In the user exit you check which production line and just change the group to 10, 20 or 30 then.
    I don't care what you pick or how you do it, neither does the function module.  I believe the function module will pass in the parameters of the task list it is planning to assign.  You then have the ability to use the code to pick a different one and pass back new parameters for the task list.
    Craig

  • Check box selection based on name inside a field

    I have a fillable PDF form
    the form has 2 check box selections.  M  or F   (male or female)
    i can get a field to populate with M or F or Male or Female but how can I get a check box to select M or F based on
    what comes into a field ?

    You can use the text-field's custom validation script to edit the check-box, for example:
    if (event.value=="Male") this.getField("CheckBoxMale").checkThisBox(0, true);
    else if (event.value=="Female") this.getField("CheckBoxFemale").checkThisBox(0, true);

  • Problem combining select, order by, rownum (top-N) and for update

    Hello,
    i have serious problems with this.
    -- drop table testtable;
    create table testTable (id number(10,0) primary key, usage number(10,10));
    -- delete from testtable;
    insert into testtable values (11, 0.5);
    insert into testtable values (10, 0.3);
    insert into testtable values (12, 0.3);
    insert into testtable values (9, 0.3);
    insert into testtable values (8, 0.9);
    insert into testtable values (3, 0.0);
    insert into testtable values (2, 0.02);
    insert into testtable values (1, 0.05);
    insert into testtable values (7, 0.7);
    insert into testtable values (6, 0.4);
    insert into testtable values (5, 0.2);
    insert into testtable values (4, 0.1);
    select * from testtable;
    -- without FOR UPDATE
    select * from (
    select tt.id id_, tt.*
    from testtable tt
    where tt.usage > 0.1
    order by tt.usage desc, tt.id desc
    where rownum <= 10;
    --> WORKS
    -- without ORDER BY
    select * from (
    select tt.id id_, tt.*
    from testtable tt
    where tt.usage > 0.1
    where rownum <= 10
    for update of id_;
    --> WORKS
    -- without WHERE ROWNUM <= 10
    select * from (
    select tt.id id_, tt.*
    from testtable tt
    where tt.usage > 0.1
    order by tt.usage desc, tt.id desc
    for update of id_;
    --> WORKS
    -- But what i need is this:
    select * from (
    select tt.id id_, tt.*
    from testtable tt
    where tt.usage > 0.1
    order by tt.usage desc, tt.id desc
    where rownum <= 10
    for update;
    --> ORA-02014: cannot select FOR UPDATE from view with DISTINCT, GROUP BY, etc., SQL State: 42000, Error Code: 2014
    select * from (
    select tt.id id_, tt.*
    from testtable tt
    where tt.usage > 0.1
    order by tt.usage desc, tt.id desc
    where rownum <= 10
    for update of id_;
    --> ORA-02014: cannot select FOR UPDATE from view with DISTINCT, GROUP BY, etc., SQL State: 42000, Error Code: 2014
    I have tried every single solution i could come up with.
    But nothing worked.
    My latest idea is to include a comment in the query and set up an ON SELECT trigger which evaluates the comment and enforeces the lock.
    But i'm not sure if this is even possible.
    I cannot split the statement into two because i need the lock immediately when the wanted rows are selected.
    One major criteria for the rows is the order by. Without it i get a random set of rows.
    And the rownum <= 10 is also needed because i don't want to lock the whole table but only the few needed rows.
    I tried row_number() over (order by ...) but this is considdered a window/group-function which disallows the for update as well as the order by.
    During these tests i noticed, that when using the row_number()-function the resultset is ordered automatically (without an additional order by clause).
    But this doesn't help anyway.
    I tried using piped functions to wrap the select to apply the rownum manually by cursor skip, but this doesn't work either. First of all i wasn't able to wrap the query the way i imagined and second the lock would be applied to the whole resultset anyway but only the reduced rows would be returned.
    I heared about LOCK-hints from other DBs, is there anything similar here?
    Any other solution??
    btw. it has to be high-performance after all.
    Greetings Finomosec;

    No, not perfect.
    This is the expected result (ordered by usage desc, id desc):
    ID     USAGE
    8     0.9
    7     0.7
    11     0.5
    6     0.4
    12     0.3
    10     0.3
    9     0.3
    5     0.2
    This ist the one produced by your statement:
    ID     USAGE
    5     0.2
    6     0.4
    7     0.7
    8     0.9
    9     0.3
    10     0.3
    11     0.5
    12     0.3
    Use limit 5 in your tests, and you will also notice that the following doesn't work either:
    select * from testtable ww where ww.id in
    select id from
    select tt.id, tt.usage
    from testtable tt
    where tt.usage > 0.1
    where rownum <= 5
    order by usage desc, id desc
    for update;
    It's because the order is not applied to the result.
    But the following modification works (at least principally):
    select * from testtable ww where ww.id in
    select id from
    select tt.id, tt.usage
    from testtable tt
    where tt.usage > 0.1
    order by usage desc, id desc
    where rownum <= 5
    order by usage desc, id desc
    for update;
    Thr problem here is:
    I need to expand the following Statement to the above form by (Java-) Code:
    -- statement-A
    select tt.id, tt.usage
    from testtable tt
    where tt.usage > 0.1
    order by usage desc, id desc;
    The main problem is:
    The order by clause needs to be duplicated.
    The problem here is, to identify it (if present) and NOT any order by in inner selects.
    I am using Hibernate and to implement this i have to modify the OracleDialect to solve this problem. I get the statement-A (see above) and have to apply the limit.
    Isn't there any other solution??
    Greetings Finomosec;

  • Infopackage Abap Routine (Selection based on other fields?)

    Dear Friends,
    I know that Abap routine is used in infopackage to select or restrict using complex data selection.
    My requirement is to restrict Material no field based on 4 other fields. Is that possible?
    Actual condition is  to load Material no only if other 4 fields combination is new.
    Pls help.
    Guru

    Hi,
    Yes you can do this at infoPackage level using the ABAP routine.
    First read the Active Table of the DSO into internal table and do a lookup for the required four fields combination.
    If these four field are new allow the material number.
    Refer the below link for more help.
    http://www.sdn.sap.com/irj/scn/index?rid=/library/uuid/a05ac9fa-f44c-2c10-dbb8-ef54c102707c
    Regards
    Manjula.B

  • Field Selection Based on Material Type

    Hello!!
    Can any one tell me how to make a single field mandatory in material master based on material type?
    I know we can use OMS9 to make it mandatory... the field i was looking is in a field selection group....when i make it mandatory i am actually making all the fields in the field selection group as mandatory...i dont want to do that...i just want to make only one field as mandatory.....
    If some one has any kind of training documents...could you please send it across?
    Thanks in advance.....

    Dear,
    Go through: http://help.sap.com/saphelp_45b/helpdata/en/08/6dec6eb435d1118b3f0060b03ca329/frameset.htm
    http://help.sap.com/saphelp_45b/helpdata/en/8e/204b6e5733d1118b3f0060b03ca329/frameset.htm
    Re: New Movement Type
    Define field in a particular movement type
    Regards,
    Syed Hussain.

  • Select and update rownum sender jdbc

    Dear all
    i am using PI 7.31 sender jdbc adapter.
    table(TB_AA)  has 10000 row with pi_stat = 'R'   and then  sender jdbc adapter tried  10 row  in using rownum  every  120 second and update same rownum
    but  result of select query and udpate query  were different.  not same record update for selecting data.
    co_cd,  memid  is PK.
    select co_cd , mem_id,  reg_n  FROM TB_AA  where PI_STAT = 'R' AND rownum <= 10
    update  TB_AA  set  PI_STAT = 'S', where  PI_STAT = 'R' and rownum <= 10
    query is wrong?  ,  what is correct update query with several PK ?

    Hi Arten Solohin.
    co_cd,  memid  is Primary Key.
    select co_cd , mem_id,  reg_n  FROM TB_AA  where PI_STAT = 'R' AND rownum <= 10
    update  TB_AA  set  PI_STAT = 'S', where  PI_STAT = 'R' and rownum <= 10
    could you make your query with above my query ?  because i am confusing ORDER BY <your unique id_field>   AND LINE_ID ....
    will be highly appreciated  in advance
    thanks you very much.

  • Selection Based on Radio buttons in SAP Query

    Hi All,
    I am new to SAP Query.
    I have added the radio buttons on the selection screen of my SAP query screen.
    Can anyone please tell me how to make the field selection in query based on the status of these radio buttons.
    Thanks And Regards,
    Rupesh

    HI
    you have to do this using modif id. here is a sample program to do this
    PARAMETERS show_all radiobutton  group g1 USER-COMMAND flag.
    PARAMETERS no_show radiobutton  group g1 default 'X'.
    SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME.
    PARAMETERS: p1(10) TYPE c,
                p2(10) TYPE c,
                p3(10) TYPE c.
    SELECTION-SCREEN END OF BLOCK b1.
    SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME.
    PARAMETERS: p4(10) TYPE c modif id bl2,
                p5(10) TYPE c modif id bl2,
                p6(10) TYPE c MODIF ID bl2.
      SELECTION-SCREEN END OF BLOCK b2.
    AT SELECTION-SCREEN OUTPUT.
      LOOP AT SCREEN.
        IF show_all <> 'X' AND
           screen-group1 = 'BL2'.
           screen-active = '0'.
        ENDIF.
        MODIFY SCREEN.
    endloop.
    reward if helpful
    Message was edited by: Harikishore Sreenivasulu

  • Limit member selection based on access in running Hyperion Financial Report

    Hi there
    I am wondering, is it possible to limit the member selection in a prompt box based on what access they have when running a Hyperion Financial Report?
    I know its possible to limit the user POV based on the members they have access to (in Preferences) but we have a reporting requirement on the page dimension to prompt the user for what cost centres they want to run the report for. When I used a prompt function the user gets to select any cost centre in the "choices" range regardless of whether they have access or not. We just want it to show what cost centres they have access to.
    Thanks

    If the datasource is ready only and not writeable for the users, then you can use MetaRead filters for cost centre, which will only show the hierarchies the users have access to.
    (You cannot mix Write and MetaRead filters in the same filter, it would be Write and Read).
    Let me know if that's an option.
    Cheers, Iain

Maybe you are looking for

  • Get information about business object from view implementation class

    Hi, i´d like to develop some button behavior in a view. How can i get the information of the related business object like the order or the position. I like to disable buttons if specific status are set. Bye Richard

  • PDF 'File Save' problem in Firefox

    Using Firefox browser, when I select a PDF file that opens in a new window [rather than a new tab], save it and close the window, the AcroRD32.exe process is not stopped.  If I then open another PDF file in a similar manner, it can not be saved.  Eac

  • Lower than expected sound output from A100

    Hi. I have recently bought a Satellite A100 PSAA9E and have been pretty disappointed with the low sound output from it. It's currently set to the highest volume level and is nowhere near the level I would expect. Is this normal for this machine? All

  • Why has my Preview stopped responding and won't open any files?

    Why has my Preview stopped responding and won't open any files? Each time I try to open Preview it just hangs and I have to close the Prog by "Force Quit"

  • HTMLDB v1.6 bug spreadsheet import wizard

    Hi HTMLDB Team, A major HTMLDB 1.6.1 bug found as follows: The problem found when importing data thru Spreadsheet wizard of Data workshop. Say, i have a table where with other fields the two more field added as created_by and created_date.A trigger i