Learn how to a build a cloud-first strategyRegister Now

x
Solved

# Formula SQL/Pl

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

LVL 18

Accepted Solution

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

ID: 20061025
probably you need RATIO_TO_REPORT function

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

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