Solved

Does the analytical function "RANK" work in Oracle Forms

Posted on 2008-06-16
5
1,487 Views
Last Modified: 2013-12-19
I have the following sql declared in a cursor.  The SQL runs fine in toad if I populate the variables but it won't compile in forms...

  CURSOR cAssetData (pRank IN NUMBER) IS
  SELECT asset_class_code,
         product_id,
         payment_method_code,
         model_code,
         manufacturer_code,
         year_of_manufacture,
         serial_number,
         location_code,
         asset_location_notes,
         asset_status_code
  FROM   (
         SELECT nvl(a.asset_class_code,'METER') asset_class_code,
            a.product_id,
            a.payment_method_code,
            a.model_code,
            a.manufacturer_code,
            a.year_of_manufacture,
            a.serial_number,
            lpad(a.location_code,2,0) location_code,
            a.asset_location_notes,
            nvl(a.asset_status_code,'LI') asset_status_code,
            RANK() OVER (ORDER BY a.effective_from_date DESC) ASSET_RANK
         FROM vw_meter_point mp, asset a
         WHERE mp.meter_point_reference = vMeterPointReference
         AND   mp.supply_start_date = (SELECT MAX(supply_start_date)
                                       FROM   VW_METER_POINT mp2
                                       WHERE  mp2.meter_point_reference = vMeterPointReference
                                       )
         AND a.meter_point_id = mp.meter_point_id
         )
  WHERE ASSET_RANK = pRank;


The compile error I get is...

Encountered the symbol "(" when expecting one of the following:
, from

Any help would be much appreciated.
0
Comment
Question by:bryanhale
  • 2
  • 2
5 Comments
 
LVL 74

Expert Comment

by:sdstuber
ID: 21795197
the forms and reports pl/sql engines are less robust than those in the database.

so, as a workaround...
wrap your query in a function that returns a pipelined collection or
a procedure or function that returns a reference cursor and compile your code on the server.
0
 
LVL 7

Expert Comment

by:Dr_Billy
ID: 21795530
Try this and see how it works
cAssetData (pRank IN NUMBER) IS
SELECT asset_class_code, 
       product_id, 
	   payment_method_code, 
	   model_code,
       manufacturer_code, 
	   year_of_manufacture, 
	   serial_number, 
	   location_code,
       asset_location_notes, 
	   asset_status_code
  FROM 
  (SELECT NVL (a.asset_class_code, 'METER') asset_class_code,
         a.product_id,
		 a.payment_method_code, 
		 a.model_code,
         a.manufacturer_code, 
		 a.year_of_manufacture, 
		 a.serial_number,
         LPAD (a.location_code, 2, 0) location_code,
         a.asset_location_notes,
         NVL (a.asset_status_code, 'LI') asset_status_code,
         RANK () OVER (ORDER BY a.effective_from_date DESC) asset_rank
    FROM asset a ) aa  , 
   (Select *
      from vw_meter_point	
    WHERE mp.meter_point_reference = vmeterpointreference
      ) bb
    WHERE aa.aset_rank = pRank
      AND aa.meter_point_id = bb.meter_point_id 
      AND bb.supply_start_date =
                     (SELECT MAX (supply_start_date)
                        FROM vw_meter_point mp2
                       WHERE mp2.meter_point_reference = vmeterpointreference);
	  
  	  

Open in new window

0
 

Author Comment

by:bryanhale
ID: 21796719
Unfortunately I do not really want to compile code on the server if I can avoid it.  I have many forms in this app and none of them do that so it will be inconsistent with the code.  I am sure there is a way of doing this.

I have tried out the code in the second response, I have fixed a couple of typos but am still getting an error as aa.meter_point_id doesn't exist, i.e. its not part of the aa select.  I wasn't sure exactly what you were getting at with this SQL so I will leave you to explain if thats okay?

Cheers for your responses anyway.

Bryan
0
 
LVL 7

Expert Comment

by:Dr_Billy
ID: 21799348
What i wanted you to do is to make the joins out of the From part instead of doing it inside the main From part , so you would have an a virtual cursor aa and another bb and you join them out of the FROM part of the main query ..... hope that explains what your question !!
0
 

Accepted Solution

by:
bryanhale earned 0 total points
ID: 21803156
Unfortunately this doesn't work as it is ranking every single asset, not just the assets for that meter point.  Also the SQL takes quite a while to run, probably because there are over 3 million asset records.

In the end I have just selected all the assets for the meter point and ordered by date desc.  I have then used a variable to rank them in the cursor.  i.e. I know the first loop of the cursor I am looking at the first record (i.e. rank 1) and the second loop the second record etc.  I just then add one to the variable each time.  If its rank 1 I am after I just exit the cursor after the first loop.

Thanks for all your help, very annoying that it doesn't look like you can use rank in forms.

0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to free up undo space? 3 50
PL SQL Search Across Columns 4 53
Email query results in HTML 6 31
Procedure syntax 5 40
How to Create User-Defined Aggregates in Oracle Before we begin creating these things, what are user-defined aggregates?  They are a feature introduced in Oracle 9i that allows a developer to create his or her own functions like "SUM", "AVG", and…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question