exec dbms_random.seed(0);

create table 
as
select rownum ȣ
     , 'Ŭ ' || dbms_random.string('u', 8) 
     , round(dbms_random.value(1000, 100000), -3) 
     , dbms_random.string('l', 10) 
     , dbms_random.string('u', 10) ǻ
     , lpad(mod(rownum, 10), 4, '0') || dbms_random.string('l', 4) ISBN
from   dual
connect by level <= 99989
;

insert into 
select 99990 ȣ
     , 'Ŭ  ȭ  ع 01' 
     , round(dbms_random.value(1000, 100000), -3) 
     , dbms_random.string('l', 10) 
     , dbms_random.string('u', 10) ǻ
     , lpad(mod(rownum, 10), 4, '0') || dbms_random.string('l', 4) ISBN
from   dual
;

insert into 
select 99990+rownum ȣ
     , 'Ŭ  ȭ  ع ' || lpad(rownum, 2, '0') 
     , round(dbms_random.value(1000, 100000), -3) 
     , dbms_random.string('l', 10) 
     , dbms_random.string('u', 10) ǻ
     , lpad(mod(rownum, 10), 4, '0') || dbms_random.string('l', 4) ISBN
from   dual
connect by level <= 10
;

create index ø_idx on ();

exec dbms_stats.gather_table_stats(user, '', no_invalidate=>false);

column last_book_nm new_value last_book_nm;
column last_rid  new_value    last_rid;

select *
from(
  select  last_book_nm, rowid last_rid from 
  order by  desc, rowid desc
)  
where rownum <= 11
;


variable book_nm varchar2(100);
variable last_book_nm varchar2(100);
variable last_rid varchar2(20);

begin
  :book_nm	:= 'Ŭ';
  :last_book_nm	:= '&last_book_nm';
  :last_rid	:= '&last_rid';
end;
/

print :last_book_nm;
print :last_rid;

select *
from (
  select rownum rnum, ȣ, , , , ǻ, isbn
  from (
    select ȣ, , , , ǻ, isbn
    from   
    where   like :book_nm || '%'
    order by 
  )
  where rownum <= 100
)
where rnum >= 91  --> 10  
;

column  format a10;
column ǻ format a10;
column isbn format a10;
column  format a40;

select *
from (
    select /*+ index( ø_idx) */
           rowid rid, ȣ, , , , ǻ, isbn
    from   
    where   like :book_nm || '%'
    and     = :last_book_nm    --   µ  
    and    rowid  > :last_rid        --   µ   rowid
    union all
    select /*+ index( ø_idx) */
           rowid rid, ȣ, , , , ǻ, isbn
    from   
    where   like :book_nm || '%'
    and     > :last_book_nm    --   µ  
)
where   rownum <= 10
;

select *
from (
    select /*+ index( ø_idx) */
           rowid rid, ȣ, , , , ǻ, isbn
    from   
    where   like :book_nm || '%'
    and     = :last_book_nm    --   µ  
    and    rowid  > :last_rid        --   µ   rowid
    union all
    select /*+ index( ø_idx) */
           rowid rid, ȣ, , , , ǻ, isbn
    from   
    where  rtrim() like :book_nm || '%'
    and     > :last_book_nm    --   µ  
)
where   rownum <= 10
;

select /*+ index( ø_idx) use_concat ordered_predicates */
       rowid rid, ȣ, , , , ǻ, isbn
from   
where   like :book_nm || '%'
and  (( > :last_book_nm) 
       or
      ( = :last_book_nm and rowid > :last_rid) )
and    rownum <= 10
;

select /*+ index( ø_idx) */   
       rowid rid, ȣ, , , , ǻ, isbn
from   
where   like :book_nm || '%'
and     >= :last_book_nm
and    lpad(, 50) || rowid > lpad(:last_book_nm, 50) || :last_rid
and    rownum <= 10
;


select greatest('AAAH+WAAJAAAHxTAA9', 'AAAH+WAAJAAAHxTAA+') from dual;

select greatest( chartorowid('AAAH+WAAJAAAHxTAA9')
               , chartorowid('AAAH+WAAJAAAHxTAA+') ) from dual;


