Domanda

I'm trying to find the correct Oracle format mask to display numbers on an Apex page in a report in a certain way. Most of the times these numbers are integers but sometimes these numbers can be floating point numbers. Let's say I have the following three queries:

Query 1

SELECT TO_CHAR(1, '<Format Mask>', 'NLS_NUMERIC_CHARACTERS = '',.''') FROM DUAL;

Query 2

SELECT TO_CHAR(0.1, '<Format Mask>', 'NLS_NUMERIC_CHARACTERS = '',.''') FROM DUAL;

Query 3

SELECT TO_CHAR(0.01, '<Format Mask>', 'NLS_NUMERIC_CHARACTERS = '',.''') FROM DUAL;

Now I want to use one single format mask which will give me the following results:

Result 1

1

Result 2

0,1

Result 3

0,01

Can anyone provide me with the correct format mask to achieve this? I've tried a format mask like FM990D999 but it leaves me with a comma trailing the 1 in Query 1.

È stato utile?

Soluzione

There are ways to alter your column value in the query while still retaining (some) of the functionality in the report(s). However, having multiple such columns and multiple report you might find there is a lot of overhead for little gain.
Look at this post on the OTN forums: order by date in IR
The issue is much the same: the data in the column represents a date but is actually not a date. This post contains a solution to use in apex < 4.2.
From 4.2 onwards you have a better option called the HTML expression.
Again, linked from OTN: Re: Report formatting/sorting issue

Quoted from linked post, user fac586

Include both variance and abs(variance) in the query:

SELECT
        region,
        estimate,
        actual,
        (estimate - actual) AS variance,
        ABS(estimate - actual) AS abs_variance,
        (CASE 
          WHEN (estimate - actual)>=0 THEN 'green'
          WHEN (estimate - actual)<0 THEN 'red'
          ELSE NULL
        END) AS variance_color
from
        expenses

And the HTML Expression for the "variance" column is:

<span style="color: #VARIANCE_COLOR#; font-weight: bold;">#ABS_VARIANCE#</span>

Hide the #VARIANCE_COLOR# and #ABS_VARIANCE# columns.

#ABS_VARIANCE# is the value shown in the column, but the sort is performed in the underlying SQL using the original variance value.

This is much like Alex suggested but is a bit more work: formatting in the source, adding an html expression, hiding the other column.
I suppose it depends on how far you want to drive it. Why not just apply the format to the column through its attributes?
Also be aware it is possible to use string substitution syntax in those fields. You could have a couple application items containing format masks, and then reference the correct mask in the format mask field. Eg: Application item AI_FORMAT_MASK1 has a value FM9990D00.
In the format mask field you can then use &AI_FORMAT_MASK1.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top