Oracle Apex Interactive report formatting and sorting - oracle

I have an Interactive report with floats and I want to sort the values in the correct way like:
8.00
9.00
80.00
90.00
In addition I want to show only two decimal places.
By default Apex displays this format:
How the achieve the correct formatting?
Edit:
The Data type of the column was not numeric but Varchar. After chasnging the type to number all formatting were as expected.

Lets say your IR has the following columns:
ID
Amount
Order by
Set the order by statement:
Click on the IR
Find the Source attribute on the right
Click on Order By and set the value to (choose one):
AMOUNT DESC
AMOUNT ASC
Format
The format should be set on column level on the left screen find the AMOUNT column under the IR. Now on the right you should find an attribute called Format Mask (under Appearance).
Set the value to: FM9999999.90 (choose one predefined)
SQL
Or just use an SQL query:
select ID,
TO_CHAR(AMOUNT, 'FM9999999.90') AMOUNT,
from TEST_TABLE
order by AMOUNT DESC

You can supply a format mask on the column definition.
The LOV next to the setting gives some samples
999G999G999G999G990D00
Sorting will be as expected if this table's column is numeric.

In Interactive report: Actions > Data > Sort, select column and set Ascending Direction;
In Page Designer: Choose your column and set Format Mask in Appearance section, for example: 99.99.

Related

Google Sheets Query - use a reference cell to select which columns to select in a query

I would like for a Google Sheets Query to choose which columns to select based on a cell reference. "select X" for example where the column header equals a cell that I reference. This is different from selecting which rows of a column to display. I want the Colx to be based on a cell reference.
Specifically, the data has different column headers with dates. I want the query to select the column that matches a particular date or any of the headers I may have in a drop down menu.
I used this format but it did not work
=query('Schedules'!A:N,"select A,B,C,D,E,K,H,J,L,M, '"&A2&"' WHERE N=1 and K !='HR(PD)' ORDER BY B,K",1)
This is the cell reference to the column I am looking for: '"&A2&"'
in A2 I have the letter of the column I want to use
Your current formula maybe a bit spotty with the quotes placement. You can see a working sample here:
=query(A:D,"Select A,"&F1&" Where A is not null")
based on header match
=query({A:D},"Select Col1, Col"&xmatch(F1,A1:D1)&" Where Col1 is not null")

Oracle APEX grid displays only date without time

I have a field in the database that contains date and time - DATE type in the database. When I run the query in Toad, I can see data and time, but when I pull up the data in the APEX report, only date shows up, no time. How can I ensure the time comes up as well?
You can set "Format Mask" column attribute in the Page Designer.
Go to Page Designer, find your report region, open list of columns, find your column and set "Format Mask" e.g. to yyyy-mm-dd hh24:mi:ss.
Another option is to change the SQL query used for the report, make explicit conversion to_char for the desired column.

##### appears instead of actual values in sql table

i used
[column sal format A10;
set linesize 1500;]
to set width for the column sal and mgr. after that when i view the table the values in mgr and sal columns appears as ######.
now how to get the actual values??
You are using an invalid format model for a number column. The valid elements are listed in the documentation. SQL*Plus doesn't know what you mean, so it seems to be defaulting to the same behaviour it has if a number won't fit in a valid number format: "If a value cannot fit in the column, SQL*Plus displays pound signs (#) instead of the number."
You would only use the charcater column formatting like A10 if the result returned by the query was already a string, e.g. if you did to_char(sal, '999G999G999') as sal; but even then the maximum length is already set by the format model (to 12 in that case, to allow the +/- sign).
You probably don't need to format those columns at all, but if you are retrieving them as numbers and want to add formatting you need to use an appropriate model, e.g.
column salary format 999G999G999

How do I correctly filter on numeric columns with custom format in Oracle APEX?

In our APEX reports, we use custom number formats to round numeric values to a given (user-defined precision). E.g. given this data:
create table round_test(pk number not null primary key, value number);
insert into round_test(pk, value) values (1, 0.11);
insert into round_test(pk, value) values (2, 0.19);
insert into round_test(pk, value) values (3, 0.20);
insert into round_test(pk, value) values (4, 0.21);
insert into round_test(pk, value) values (5, 0.23);
insert into round_test(pk, value) values (7, 0.28);
I've created an interactive report to display the VALUE column with format 999D9 (for illustration purposes, I've added an ORIGINAL_VALUE column that displays the data without a number format, i.e. with full precision - see screenshot below).
Now if I click the column header to filter by this column, I get duplicate values (e.g. 0.2 appears four times - once for 0.19, 0.20, 0.23 and 0.28):
That's bad enough, but if I click one of these values, APEX filters by the exact value instead of the rounded one:
How can I
get rid of the duplicates in the drop-down
force APEX to filter by the rounded value
Note: Creating a view with the rounded values and using that in the report definition is not a viable approach, since our reports include a custom export function that allows the users to export the data with full precision.
UPDATE
The SQL query for the report is quite simple:
SELECT
pk,
value,
value AS original_value
FROM round_test
The behaviour is the same in APEX 4.2 (which we currently use) and APEX 5.0 (which I used at http://apex.oracle.com to create the example).
To eliminate duplicates on the List of values filter:
First you need to create a LOV on Application -> Shared Components -> Other Components -> List of Values
With this sql query:
select distinct to_char(value,'999.9') d, round(value) r
FROM round_test order by 1 asc
Then on Report Atributes edit the column that contains the 'value' value, and in the List of Values Section specify on 'Column Filter Type': Use Named List of Values to Filter Exact Match and then on 'Named List of Values', select the one you created earlier.
To filter by the rounded value:
Create the report but instead of applying the format mask as you did (this maintains the actual value despite the format applied on the view) format the value on the query like this:
SELECT
pk,
to_char(value,'999.9') value,
value AS original_value_
FROM round_test
I think that will cover your needs.
Here's a working example
The ideal behaviour would be to have a single report column for value. Clicking on the header would give the standard options, including a filter which would display (and allow searching on) rounded decimal numbers. Unfortunately Apex doesn't let you do that. The values that appear in the filter are determined using the distinct values selected in the initial report query; subsequent formatting in the report's column definition only affects how values are displayed, not the actual values, hence the apparent duplicates in the filter list.
I think the essence of your problem is that without doing some heavy customisation of the interactive report filter (good luck to you if you go that route), I think you'll have to accept having two columns for value, one containing the actual value, and one containing the rounded or otherwise formatted value, to be used for filtering.
As suggested elsewhere, you could create the new column in the SQL for each of your reports:
SELECT
pk,
value,
to_char(value, 'fm999D9') AS formatted_value
FROM round_test
Alternatively, if your users are willing and able, you could show them how to create a computed column from the Actions button:
Whichever way the formatted_value column is created, it should be hidden in order to stop it messing up the export. Filtering would then have to be done from the Actions button:

How MAX of a concatenated column in oracle works?

In Oracle, while trying to concatenate two columns of both Number type and then trying to take MAX of it, I am having a question.
i.e column A column B of Number data type,
Select MAX(A||B) from table
Table data
A B
20150501 95906
20150501 161938
when I’m running the query Select MAX(A||B) from table
O/P - 2015050195906
Ideally 20150501161938 should be the output????
I am trying to format column B like TO_CHAR(B,'FM000000') and execute i'm getting the expected output.
Select MAX(A || TO_CHAR(B,'FM000000')) FROM table
O/P - 2015011161938
Why is 2015050195906 is considered as MAX in first case.
Presumably, column A is a date and column B is a time.
If that's true, treat them as such:
select max(to_date(to_char(a)||to_char(b,'FM000000'),'YYYYMMDDHH24MISS')) from your_table;
That will add a leading space for the time component (if necessary) then concatenate the columns into a string, which is then passed to the to_date function, and then the max function will treat as a DATE datatype, which is presumably what you want.
PS: The real solution here, is to fix your data model. Don't store dates and times as numbers. In addition to sorting issues like this, the optimizer can get confused. (If you store a date as a number, how can the optimizer know that '20141231' will immediately be followed by '20150101'?)
You should convert to number;
select MAX(TO_NUMBER(A||B)) from table
Concatenation will result in a character/text output. As such, it sorts alphabetically, so 9 appears after 16.
In the second case, you are specifiying a format to pad the number to six digits. That works well, because 095906 will now appear before 161938.

Resources