Classic report dynamic heading in APEX 5.1 - oracle

I have a classic report driven by a SQL query.
How can I dynamically set column headings, based on the value of another column?
For example, my SQL returns columns A, B, VERSION. I'd like the classic report column heading for SQL column A to be 'Foo' if VERSION is 1, but 'Bar' if VERSION is 2.

I don't know what you meant by saying that the query is constrained by primary key.
Anyway, here's a suggestion which might (or might not) help.
Based on sample SCOTT schema, I created a simple classic report as
select e.ename, e.job
from emp e
where e.deptno = :P42_DEPTNO
I also created a P42_DEPTNO item which - kind of - constrains the result to just one department. For example, if you enter 10 into P42_DEPTNO, you'll get employees that work in the ACCOUNTING department.
Furthermore, I created a hidden item P42_DNAME whose souce is a SQL query
select dname
from dept
where deptno = :P42_DEPTNO
and it returns department name for the P42_DEPTNO value. Its "Used" property is set to "Always, replacing any existing value in session state". This item (P42_DNAME) will be used as a custom heading for the ENAME column returned by the report.
In order to do that, open ENAME column's properties and put this into the "Name" property: &P42_DNAME. (literally ampersand + item name + dot - don't forget the trailing dot!).
That's all;
run the report
enter 10 into P42_DEPTNO item
press ENTER key
report will display employees that work in department 10, and ENAME column's heading will be ACCOUNTING

Related

Error with a user defined report in Oracel SQL Developer - Missing IN or OUT parameter at index:: 1

I have created a user defined report within Oracle SQL Developer, with a bind variable.
The report consists of a master_report (style is table), child_report_a containing with a style of 'table' and child_report_b which is the same query, but with the style of 'script'.
I am able to select a cell/row of my master report, and child_report_a data changes accordingly (ie, it returns the cells of the same date I selected.
However, when I try to view this in child_report_b (With the 'script' style) it errors with "Missing IN or OUT parameter at index:: 1".
So the setup is:
tablea
id_pk (number)
name_pk (varchar2)
1
Jack
2
John
3
Amy
tableb
id_fk (number)
start_time(timestamp(6))
1
01-JAN-23 12.00.00.123000000
2
01-JAN-23 13.00.00.123000000
3
02-JAN-23 14.05.00.123000000
User Defined Report:
master_report (Style=Table):
SELECT * FROM tablea
child_report_a (Style=Table) & child_report_b (Style=Script):
SELECT * FROM tablea a INNER JOIN tableb b ON b.id_fk = a.id_pk WHERE trunc(start_time) = trunc(to_timestamp(:STARTTIME)
Any help is appreciated.
EDIT: Included better example of setup.
My goal is to be able to select a row from the master_report, and the child_report_b would return all results which match the date (as currently happens in child_report_a) in the script format.
Welcome to StackOverflow!
The reporting feature is one of my favorites in SQL Developer, so I will try to get you started.
We can't technically answer your question without a fair bit of guessing. We know what's happening on one side of the JOIN, you have a timestamp that you're using TRUNC on.
But we can't tell what is on the other side of the equality predicate in your JOIN.
Here's a working example, see if this helps you.
Parent Query
select trunc(systimestamp) A
from dual
Child Query
select object_name, object_type, last_ddl_time
from user_objects where :A > (trunc(systimestamp) - 30)
And the report -
To debug your report, substitute the bind :STARTTIME with a literal value that is equivalent to what your parent query would return. If that works, so should your report.
Disclaimer: I work for Oracle and am a product manager for SQL Developer.

Oracle Apex 20.1 Cascading LOV not working correctly

I am using apex 20.1 and try to implement the new cascading lovs option. However it is not working as per expectation.
Can you suggest where am I going wrong.
I have 2 items in my region:
:P5_ASSIGNED_DEPT - Assigned department for each employee
:P5_PERSON_NAME - Name of employee
I want the name of employees to populate as per assigned dept in table.
If assigned_Dept is FINANCE, only employees with assigned dept as finance should populate in :P5_PERSON_NAME.
I made these changes:
But despite selecting finance, i am getting names of all employess irrespective of dept.
What more changes are needed?
I presume that query you used for P5_PERSON_NAME doesn't contain P5_ASSIGNED_DEPT. Apex can't automagically add WHERE clause to your query, you have to do it yourself.
So: P5_PERSON_NAME's LoV query should look like this:
select e.ename as display_value,
e.id as return_value
from emp e
where e.dept_id = :P5_ASSIGNED_DEPT

Cascading LOVS - default values

I have two cascading LOVs. After changing value of my first LOV in second LOV appropriate values are populated.
First LOV:
name - P2_DEPTNO
select dname, deptno
from dept
order by 1;
Second LOV:
name - P2_EMPNO
select ename, empno
from emp
where deptno = :P2_DEPTNO;
cascading LOV parent - P2_DEPTNO
What should I add to set default value of second LOV (first row from query) after changing first LOV value?
Make sure you have Display Null Value set to No and it should use the first value in the list. (Although I am not sure what it will do with Popup LOV).
Finally, I got the correct answer on the Oracle community forum.
This is possible in only one case, because I'm more familiar with this type of issue in my project.
We need to change the second item type i,e "Empno" item type from Pop-up LOV to Select-List.
Also make null setting changes as per given below :
On DEMO works proper.
Please note that this will CAN NOT be achieved with item type as POP-UP LOV directly using simple step. To make this work using you need to work on POP-UP LOV we need so much custom changes, like DYnamic Actions , JS Code, Asynchronous calls to DB.
Source - https://community.oracle.com/thread/4048009
Author - EnigmaCoder

Need Column name where I know the database and table names

I know the database and table name and need to find a column name. Example as in emp table; I know data 7369 and table name as emp, and I need to get the column name as empno. My table has hundreds of columns and it is getting difficult to search each column name.
You don't have any choice but to search in every column. Please note though that this value could, potentially, appear in multiple columns and/or multiple times in a single column. There's no way to restrict how often it appears across an entire table.
This is the point of a database; everything stored in a column and, most importantly, that column has meaning. If you disassociate the data stored in a column from a meaning then you will have to search everything.
Two steps, not using cursors or complex pl/sql, only SQL Plus.
Produce your search queries:
select select '||
COLUMN_NAME ||
',count(*) from emp where ' ||
column_name || ' = 7369 group by '||
COLUMN_NAME || ';'
from cols
where table_name = 'EMP';
EG:
--------------------------------------------------------------------------------------
select SECOND,count(*) from TESTER where SECOND = 7369 group by SECOND;
(in my env, Second was a column in table TESTER)
Capture the output, clean up the headers and the like, and run it.
It will return every column that matches, along with a count of how many rows matched.

Oracle Apex 4.2 interactive report with lookup tables

I have created a table Called NAMES inside that I have a column called Status.
On STATUS, I created a lookup table and this created a new table called Status_lookup Which has 2 column (STATUS_ID and Status)
So the NAMES table column changed to STATUS_ID
when I do interactive reports, the data do come through from STATUS_ID which is number, I need the text that is stored in the Status.
Could some please explain how I do this. This I thought would be pretty easy but I can't see how to do it.
I am not Newbie to Oracle applications so a step by step would be helpful
Example: select * from emp
I want DEPTNO to display the DNAME which can be found in DEPT
What I usually do is:
Go to "Shared Components > Lists of Values", and create a new one from scratch, type dynamic.
I'm calling my LOV "DEPARTMENTS", and it has this SQL:
select dname d, deptno r
from dept
order by 1
To then map this to the column in the IR, go to the page with the IR and edit it. Go to the report attributes. From there you can see the columns in the IR and edit their attributes by clicking the pencil icon.
In the column attributes you can then change the display type of the column. Set it to "Display as Text (based on LOV, escape special characters)".
Then go to the "List of Values" section, and select the LOV from the "Named List of Values" select list. (In my example this is "DEPARTMENTS").
Apex will then map the values in the IR sql to that of the display value of the LOV.
Alternatively, you could of course also just change the SQL of the report to map a display value, for example:
SELECT empno, ename, depto, (select dname from dept where deptno = e.deptno) dname
from emp

Resources