I want to add an option for the user when creating the report to select the columns that the report will show. See the attached image below on how it is suppose to look.
Is there a way to do that?
I don't know about the parameter dialog, but assuming that your column names are in an array.
You can have an SQL query with all possible column names
(probably you should use special comments to mark the beginning and end of the select list).
E.g.
select
'X' as dummy
-- BEGIN COLS
, column1
, column2
...
-- END COLS
from ...
where ...
order by ...
Then, in the beforeOpen event of the query, you can access and modify the query with this.queryText (IIRC) and remove all those lines ("," + columnname) in the marked part for which columnname is not contained in the array.
Related
how can I change direction of LOV using set_item_property ?
I want to change the direction based on a parameter value , if set_item_property is not available do you have any suggestions ?
use an 'ORDER BY' clause at the end of the query. using either ASC for ascending data 'ABCD' or DESC for descending order 'ZYX' e.g.
SELECT *
FROM table
ORDER BY parameter ASC
OR
SELECT *
FROM table
ORDER BY parameter DESC
If you mean ordering of the listed values in ascending or descending manner by the word direction, you can manage it through use of Set_Lov_Property.
You should be calling the existing LOV from a text field(call tf1).
Add a check box item (call cb1) next to tf1.
Forms creates a Record Group as LOV being created with the same name as default(call 'mylov01'). Assume this Record Group has a select statement having order by col0 asc clause.
Manually create an extra Record Group with name mylov01_desc having order by col0 desc clause.
Add a KEY-CLRBLK trigger to that field with the code
declare
v_lov varchar2(50) := 'mylov01';
v_grn varchar2(50);
begin
if Checkbox_Checked('cb1') then
v_grn := v_lov||'_desc';
else
v_grn := v_lov;
end if;
Set_Lov_Property( v_lov, group_name, v_grn );
list_values;
end;
Invoke the LOV by pressing F7 whenever the cursor is in tf1.
The list would return rows in descending order for col0 column provided that cb1 is checked, otherwise would be in ascending order.
P.S. KEY-LISTVAL is the default trigger to invoke a LOV, and fired through Ctrl+L key combination. I prefer disabling this default behaviour by adding KEY-LISTVAL trigger for tf1 with a code null; in it in order to invoke the LOV from pressing the single key F7 only.
pl SQL code segment
SELECT Xmlserialize(DOCUMENT
XMLELEMENT("intrastat",
XMLAGG(
Xmlforest(ENVELOPE_ID AS "envID",
XMLFOREST(DATE_ AS "date",TIME_ AS "Time")AS "Date
time", PARTY_ID AS "pid",PARTY_NAME AS "pname",
XMLFOREST(Xmlelement("RC",REGION_CODE) AS RC,Xmlelement("TCPCODE",MODE_OF_TRANSPORT_CODE) AS TCPCODE) AS "item")
)))
FROM INTRASTAT_XML_TEMPLATE_LINE_TMP
part of actual output that make the trouble
<item><RC><RC>as</RC></RC><TCPCODE><TCPCODE>22</TCPCODE></TCPCODE></item>
what i want to get
<item><RC>ads</RC><TCPCODE>22</TCPCODE></item>
Your current plsql code segment :
XMLFOREST(Xmlelement("RC",REGION_CODE) AS RC,Xmlelement("TCPCODE",MODE_OF_TRANSPORT_CODE) AS TCPCODE) AS "item")
And as we have used aliases in here, we are getting multiple tags - One for alias, and one for the first parameter of XMLELEMENT function.
Now, since you just want an element - item, with two tags - RC (holding data of REGION_CODE field) and TCPCODE (holding data of MODE_OF_TRANSPORT_CODE field),
in my opinion, this should suffice your requirement:
Xmlelement("item", XMLFOREST(REGION_CODE "RC", MODE_OF_TRANSPORT_CODE "TCPCODE")
~Kuntal
with data(rc, tcpcode) as (select 'ads', 22 from dual)
select xmlelement("item", xmlforest(rc, tcpcode)) from data;
XMLELEMENT("ITEM",XMLFOREST(RC,TCPCODE))
--------------------------------------------------------------------------------
<item><RC>ads</RC><TCPCODE>22</TCPCODE></item>
I am currently using apex 19.1. I have this problem where I can't (or don't know how to) select certain columns from checkbox meaning I have this checkbox
which gives me the ability to check the columns names I want to use that output (:P3_COLUMN) from the check box to select a specific columns in a table. My solution was :
select :P3_COLUMN
from INPUT_TABLE$
I also tried :
select case :P3_COLUMN when 'currency' then currency when 'nationality' then nationality end as test from input_table
which gave me this output
and
DECLARE
str varchar2(100);
BEGIN
str := 'select ' || replace(:P3_COLUMN, ':', ',') || ' from input_table';
execute immediate str;
END;
which gave me this error
I don't know what to do, any help will be really appreciated.
Here's a walkthrough (my page is #51). Suppose that we want to display some column from Scott's DEPT table.
create a region whose type is classic report
create a page item (let's call it P51_COLS which is a select list item; its source is a query which looks like this:
select column_name d,
column_name r
from user_Tab_columns
where table_name = 'DEPT'
Page action on selection should be "Submit page"
region's source should be a PL/SQL function body that returns a SQL query and look like this:
return 'select case when :P51_COLS = ''DEPTNO'' then to_char(deptno )
when :P51_COLS = ''DNAME'' then dname
when :P51_COLS = ''LOC'' then loc
end as result
from dept';
Its "Page items to submit" should be set to P51_COLS
That's it ... run the page; select any column from the select list item and the result should be displayed.
Yes, I know - the query itself looks stupid as you have to name all cases. For some reason, Apex expects literally return 'select ...' statement. Concatenation, replace function, ... won't work. Perhaps someone knows why or - even better - can demonstrate how to workaround it. Meanwhile, try what's been written above.
first option use server side condition on the columns.
second option use dynamic sql> create function returns sql statement> call the function in your region source.
A weird request maybe but. My boss wants me to create an admin version of a page we have that displays data from an oracle query in a table.
The admin page, instead of displaying the data (query returns 1 row), needs to return the table name and column name
Ex: Instead of:
Name Initial
==================
Bob A
I want:
Name Initial
============================
Users.FirstName Users.MiddleInitial
I realize I can do this in code but would rather just modify the query to return the data I want so I can leave the report generation code mostly alone.
I don't want to do it in a stored procedure.
So when I spit out the data in the report using something like:
blah blah = MyDataRow("FirstName")
I can leave that as is but instead of it displaying "BOB" it would display "Users.FirstName"
And I want to do the query using select * if possible instead of listing all the columns
So for each of the columns I am querying in the * , I want to get (instead of the column value) the tablename.ColumnName or tablename|columnName
hope you are following- I am confusing myself...
pseudo:
select tablename + '.' + Columnname as WhateverTheColumnNameIs
from Table1
left join Table2 on whatever...
Join Table_Names on blah blah
Whew- after writing all this I think I will just do it on the code side.
But if you are up for it maybe a fun challenge
Oracle does not provide an authentic way(there is no pseudocolumn) to get the column name of a table as a result of a query against that table. But you might consider these two approaches:
Extract column name from an xmltype, formed by passing cursor expression(your query) in the xmltable() function:
-- your table
with t1(first_name, middle_name) as(
select 1,2 from dual
), -- your query
t2 as(
select * -- col1 as "t1.col1"
--, col2 as "t1.col2"
--, col3 as "t1.col3"
from hr.t1
)
select *
from ( select q.object_value.getrootelement() as col_name
, rownum as rn
from xmltable('//*'
passing xmltype(cursor(select * from t2 where rownum = 1))
) q
where q.object_value.getrootelement() not in ('ROWSET', 'ROW')
)
pivot(
max(col_name) for rn in (1 as "name", 2 as "initial")
)
Result:
name initial
--------------- ---------------
FIRST_NAME MIDDLE_NAME
Note: In order for column names to be prefixed with table name, you need to list them
explicitly in the select list of a query and supply an alias, manually.
PL/SQL approach. Starting from Oracle 11g you could use dbms_sql() package and describe_columns() procedure specifically to get the name of columns in the cursor(your select).
This might be what you are looking for, try selecting from system views USER_TAB_COLS or ALL_TAB_COLS.
I have T-SQL query that joins multiple tables. I am using that in SSRS as Dataset query. I am only selecting two columns, ID and Names. I have three records with same "ID" values but three different "Names" values. In SSRS, I am getting the first "Names" value and I need to concatonate all three values with same ID and have it in one cell on a table.
How would I go about doing that?
I am using lookup to combine cube + sql
Pulling ID straight from a table but using Case statement for Names to define alias.
You can accomplish this in TSQL either using PIVOT to get them as separate columns which you can then combine in the report cell, or you can use one of these concatenation methods to get all the names in one column.
For example, you can do this:
SELECT SomeTableA.Id,
STUFF(
(SELECT ',' + SomeTableB.Names AS [text()]
FROM SomeTable SomeTableB
WHERE SomeTableB.Id = SomeTableA.Id
FOR XML PATH('')), 1, 1, '' )
AS ConcatenatedNames
FROM SomeTable SomeTableA
INNER JOIN AnotherTable
ON SomeTableA.Id = AnotherTable.SomeId
...