Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Query to find adjustment and add to minimum value

user12276240Nov 26 2009 — edited Dec 8 2009
Hi i need a query to perform the below operation
I have a table as shown below

invoice rec_no r_cost d_cost chg tax code
1 12345 114.35 100.30 1.00 1.00 234
2 12345 114.35 2.00 1.00 1.00 201
3 12345 114.35 14.00 1.00 1.00 600
4 23412 120.90 110.40 1.00 1.05 700
5 23412 120.90 12.50 1.00 1.05 900


From this table i need to find the adjustment for each rec_no as
(r_cost + chg +tax) -sum(d_cost)for rec_no=12345
(114.35 + 1.00+1.00) -(100.30+2.00+14.00)=0.05
This 0.05 should be added to the minimum(code) for the rec_no 12345.
so the d_cost of code, 201 with rec_no=12345 should be (2.00 + 0.05=2.05).

and,
(120.90 + 1.00+1.05) -(110.40+12.50)=0.05
This 0.05 should be added to the minimum(code) for the rec_no 23412.
so the d_cost of code, 700 with rec_no=23412 should be (110.40+ 0.05=110.45).

Kindly help me in writing a oracle query to perform the above operation.
This post has been answered by ravikumar.sv on Dec 1 2009
Jump to Answer

Comments

Billy Verreynne

Please ask your questions in the most appropriate forum.

Your question above has very little to do with Oracle Object features and technology - and is a question about the database (general use). In which case you should ask the question in

Tubby

SivaprasadS wrote:

Environment:

Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production

Question:

1. How to find when the given index is last used?

2. How to find if the given index is useful to keep it or not ? or find the useless indexes.

Scenario:

  The are indexes with name startining with  ‘IDX$$_ ‘  are exists on our production database.

  Usually, when we use the recommendations of DBMS_AUTO_SQLTUNE, by running a SQL tuning task and the recommendation may have been to implement an index , at which time
  Oracle may have used this prefix and created an index name with 'IDX$$_'

  We would like to know if these indexes are really needed or it can be dropped.

Sivaprasad.S

Altering Indexes

Cheers,

paul.jackson

The main approach is to turn on monitoring for that index, however you can also query the saved plans.

If you have the appropriate pack licensed, you can query dba_hist_sql_plan where object_name=<index_name>. This will show any plans that have used that index.

Another thing to keep in mind, if the indexes are large in size you can make them invisible. In case they are needed,you can alter them as visible rather than rebuilding.

Paul

Zlatko Sirotic

Maybe it's time to change name from Objects to (eg) Object-relational features.

Best regards

mtefft

Before concluding indexes are 'not used' you should also determine if they support any foreign-key, primary-key or unique constraints.

If they are unique indexes then presumably there is a business rule (a unique constraint) that they enforce. Dropping such indexes would introduce a functional change.

Indexes that correspond to foreign-key constraints may be more subtle. If Oracle is using them to valdiate foreign-key constraints (such as verifying that a row in a parent table has no related rows in a child table), this usage is not reflected in the plans. If you drop such an index, the enforcement would still occur but it may take much longer and introduce additional locking.

jgarry

A couple of other things to keep in mind:

Just because an index hasn't been used recently doesn't mean it isn't important.  One obvious consequence is an index used by a period-end batch, it's no fun to have people tapping their feet and watching over your shoulder at 7:30PM December 31st... there's nothing wrong with invisibility or creating such an index when needed, you just need to know ahead of time.

The simple existence of an index may influence optimizer decisions, affecting performance.

There are some interesting blogs and books about these topics, I'd say look at index used Richard Footes Oracle Blog

and Indexing | Oracle Scratchpad to start.

1 - 6
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Jan 5 2010
Added on Nov 26 2009
5 comments
1,070 views