Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Formula SQL/Pl

Posted on 2007-10-11
2
Medium Priority
?
389 Views
Last Modified: 2013-12-07
Hi,
I have not written a formula in Oracle -SQL/Pl could you give me the syntax.
Field 1 / Field 2 = % of Errors
0
Comment
Question by:syhctl
2 Comments
 
LVL 18

Accepted Solution

by:
rbrooker earned 2000 total points
ID: 20060663
declare
  v_percent_errors number;
begin
  select round((field_1/ field_2)*100,2)
  into v_percent_errors
  from my_table
  where rownum = 1;

  dbms_output.put_line( 'Error percentage : ' || v_error_percent );
end;

will that do you?  it is an anonymous plsql block that works out the error percentage for the first record in my_table.

good luck :)
0
 
LVL 9

Expert Comment

by:konektor
ID: 20061025
probably you need RATIO_TO_REPORT function
http://download-uk.oracle.com/docs/cd/B19306_01/server.102/b14223/analysis.htm#i1006928

Example 21-13 RATIO_TO_REPORT

To calculate RATIO_TO_REPORT of sales for each channel, you might use the following syntax:

SELECT ch.channel_desc, TO_CHAR(SUM(amount_sold),'9,999,999') AS SALES,
     TO_CHAR(SUM(SUM(amount_sold)) OVER (), '9,999,999') AS TOTAL_SALES,
     TO_CHAR(RATIO_TO_REPORT(SUM(amount_sold)) OVER (), '9.999')
     AS RATIO_TO_REPORT
FROM sales s, channels ch
WHERE s.channel_id=ch.channel_id  AND s.time_id=to_DATE('11-OCT-2000')
GROUP BY ch.channel_desc;

CHANNEL_DESC         SALES      TOTAL_SALE RATIO_
-------------------- ---------- ---------- ------
Direct Sales             14,447     23,183   .623
Internet                    345     23,183   .015
Partners                  8,391     23,183   .362
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Working with Network Access Control Lists in Oracle 11g (part 2) Part 1: http://www.e-e.com/A_8429.html Previously, I introduced the basics of network ACL's including how to create, delete and modify entries to allow and deny access.  For many…
Note: this article covers simple compression. Oracle introduced in version 11g release 2 a new feature called Advanced Compression which is not covered here. General principle of Oracle compression Oracle compression is a way of reducing the d…
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Suggested Courses
Course of the Month21 days, 1 hour left to enroll

810 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