Jump to content

Recommended Posts

Hey guys. Not a massive expert when it comes to Oracle and I'm stuck with some pagination type problems. I've got a procedure setup that I can pass in "pStart" and "pLength" to appear to act like MySQL's LIMIT clause. This is the actual select statement I'm using (I've left out the surrounding procedure related stuff):

 

select p.insight_prod_cd as sku, pa.attr_val as cnet_desc
  from prods p, prod_attrs pa
  where p.prod_id = pa.prod_id
  and pa.cat_attrs_id = A.CUSTOMCAT
  and pa.num_attr_val = 3
  and rownum >= pStart
  and rownum <= (pStart + pLength);

 

Without the last 2 lines this works perfect, however as I mentioned I want to paginate the results. If I provide pStart as 0 and pLength as 10 (or any number > 1 really), it works. However if pStart is > 1 it returns nothing. I've looked around on the net and noticed this isn't how to achieve pagination and that 'rownum' doesn't work like that, but I'm stuck trying to apply some of the other methods I've read about (like this for example) to my query.

 

I've noticed online tutorials on PL/SQL tend to assume you know a fair bit about the language already, and I'm still a little hazy with quite a few areas. Could anybody offer any advise or help for me to paginate this query?

 

Thanks in advance.

 

Adam

Link to comment
https://forums.phpfreaks.com/topic/181850-solved-oracle-pagination/
Share on other sites

Managed to get it working in the end :D

 

Solution for anyone it would benefit:

 

  select * from (
    select
      p.insight_prod_cd as sku,
      ped.product_data.GetProductName(p.insight_prod_cd) as product_name,
      ped.product_data.getAttribValue(p.prod_id, A.CNETDESCRIPTION) as cnet_desc,
      row_number() over (order by p.insight_prod_cd) rn
    from prods p, prod_attrs pa
    where p.prod_id = pa.prod_id
    and pa.cat_attrs_id = A.CUSTOMCAT
    and pa.num_attr_val = 3
  )
  where rn between pStart and (pStart+pLength)
  order by rn;

 

I've made some changes to the main select query as well in case anyone noticed it's different.

 

Thanks anyway!

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.