Oracle LIMIT and 1000 column restriction

前端 未结 3 1524
天命终不由人
天命终不由人 2021-01-14 15:53

I have a SQL query that looks like this:

SELECT foo \"c0\",
       bar \"c1\",
       baz \"c2\",
       ...
FROM   some_table
WHERE  ...

I

相关标签:
3条回答
  • 2021-01-14 16:38

    Is the problem pagination or just returning the first 10 rows? If it is the latter, you can do:

    SELECT foo "c0",
           bar "c1",
           baz "c2",
           ...
    FROM   some_table
    WHERE  ... and
           rownum <= 10
    
    0 讨论(0)
  • 2021-01-14 16:39

    you cant have a view with 1000+ columns, so cheat a little.

    select *
      from foo f, foo2 f2
     where (f.rowid, f2.rowid) in (select r, r2
                                     from (select r, r2, rownum rn
                                             from (select /*+ first_rows */ f.rowid r, f2.rowid r2
                                                     from foo f, foo2 f2
                                                    where f.c1 = f2.a1 
                                                      and f.c2 = '1'
                                                    order by f.c1))
                                    where rn >= AAA
                                      and rownum <= BBB)
    
    
    order by whatever;
    

    now put any where clauses in the innermost bit (eg i put f.c1 = '1').

    BBB = pagesize. AAA = start point

    0 讨论(0)
  • 2021-01-14 16:41

    Okay, this will perform worse than what you were planning, but my point is that you could try pagination this way:

    WITH CTE AS
    (
        ... original SQL goes here ...
    )
    
    SELECT A.*
    FROM CTE A
    INNER JOIN (SELECT  YourKey,
                        ROW_NUMBER() OVER (ORDER BY ...) rnum
                FROM CTE) B
    ON A.YourKey = B.YourKey
    WHERE rnum BETWEEN 1 AND 10;
    
    0 讨论(0)
提交回复
热议问题