How to use APEX checkbox group values in the where clause of a query - oracle

I'm using APEX 20.2.
I have a checkbox group with 3 different values:
The values checked in this group are used to filter a query and I'm not sure how to write the where clause
Here is what I have:
SELECT Null as link, PERSONNE_EN_CHARGE as label, count(*) as value
FROM FLYWAY_MEP_HISTORY
WHERE STATUT_MEP='SUCCESS'
AND (DATE_MEP BETWEEN to_date(:DATE_DEBUT,'DD/MM/YYYY') AND to_date(:DATE_FIN ,'DD/MM/YYYY')+1)
OR (:DATE_DEBUT is null and :DATE_FIN is null)
AND (UPPER(ENVIRONNEMENT) is null or UPPER(ENVIRONNEMENT) IN (:ENVIRONNEMENT))
GROUP BY PERSONNE_EN_CHARGE
ORDER BY 2;
the part I'm not sure of is this part:
UPPER(ENVIRONNEMENT) IN (:ENVIRONNEMENT))
How can I use the values of the checkbox group in the where clause?
If I debug the page I can see this in the devlopper console

When you select multiple values in Apex, they are separated by colon. So, if you split that value into rows, you can use it as a subquery. In your case:
...
or UPPER(ENVIRONNEMENT) IN
(select regexp_substr(:ENVIRONNEMENT, '[^:]+', 1, level)
from dual
connect by level <= regexp_count(:ENVIRONMENT, ':') + 1
)

Related

Issue in Jqgrid pagination in Oracle server

We have a code to sort data and paginate the same and render the data to a Jqgrid. The code works fine when it is connected to an SQL server. That is on paginating each page returns distinct data as expected. But on connecting to an oracle server after some point of time the duplicate data are rendered. Both Oracle and SQL server has same data. Parameters in the Jqgrid page and the number of pages are working as expected on the server-side. That is on paging the start point and chunk size is correctly transferred to the server-side. The duplicate values are observed after sorting columns that are of type varchar in the database but hold numeric also. The database status column holds values of 3 and A, after sorting with the status column the duplicate data when the paginating issue is observed. Duplicate data in the sense, that data on page 2 will be the same as data on page 3. Any help will be appreciated. Thanks in advance...
Query One:-
select * from ( select row_.*, rownum rownum_ from ( Select x,y,z,status FROM tablename c WHERE status IN('in condition seperated with status') ORDER BY status asc ) row_ where rownum <= 30 ) where rownum_ > 20;
Query Two:-
select * from ( select row_.*, rownum rownum_ from ( Select x,y,z,status FROM tablename c WHERE status IN('in condition seperated with status') ORDER BY status asc ) row_ where rownum <= 20 ) where rownum_ > 10;
Here the query 1 and 2 always return the same results.
Where two or more values in the column of your ORDER BY clause are the same, you must always provide another secondary column to rank. Otherwise, data return has only a probability of fetching correct result as we expect. The possibility of getting a correct answer will be same as rolling a dice. The secondary column must be unique for accurate results. While you might be able to assume that they will sort themselves based on order entered
select * from( select row_.*, rownum rownum_ from( Select x,y,z,status FROM tablename c WHERE status IN('in condition seperated with status') ORDER BY status,x asc ) row_ where rownum <= 30 ) where rownum_ > 20;
Hoping x is a unique value. DBMS_RANDOM.VALUE can also be used in case if is an oracle specific query other than adding extra order by clause

How to split a comma-separated value to columns using connect by

I have a column with less than <50 comma separated values. And the number of comma separated values in that particular column is not constant I would like to query this table with IN/AND/OR clause for these comma separated values:
So I would like to:
split these values into separate columns in the select query
Query for a person's market code with AND, OR and IN :
EUP and APCAC
APAC or EU Or CA
IN ( APAC,EU,LATIM)
I have to use this query in spring data jpa native query
I don't want to use as many substr.
I thought to accomplish this by using connect by with level would be useful after referring the following answers - ans1 and ans2
Usertable:
username
market_code
in_use
john
eup,apac,Latim
0
sebastin
apac,Latim
0
xavier
ca,apac,Latim
0
However the following only returns one row where I expected to have 3 rows :
select regexp_substr(market_code,'[^|]+', 1, level) from testautomadm.userpool
where AND USERNAME = 'john'
connect by regexp_substr('market_code', '[^|]+', 1, level)
is not null
Any help to solve this use case much appreciated.
Thank you!
You can use the multiset and hierarchy query as follows:
Select user_name,
listagg(market_code, ',') within group (order by pos) as market_code,
In_use
From
(Select user_name,
regexp_substr(market_code, '[^,]+',1, column_value) as market_code,
in_use,
column_value as pos
From t,
table(cast(multiset(
select level from dual
connect by level <= length (regexp_replace(t.market_code, '[^,]+')) + 1
) as sys.OdciNumberList)) levels) t
Where market_code in ('EUP','APCAC')
Group by user_name, in_use
Having count(distinct market_code) = 2
Above query shows the usage of AND as we have used count = 2 You can use count = 1 and respective market_code in IN for OR And IN query

How to get minimum unused number from a column in Oracle and Linq?

I have a column named voucher_number. The data in this column looks like
1, 2
I want a query (in oracle and linq as well) to return 0,3,4,5,6,7,8,9,10
Note: i am taking range (0 to 10 )as a parameter parameter from screen(aspx page)
You can use MINUS operator as following:
Select voucher_num from
(
(Select level - 1 as voucher_num from dual
Connect by level <= 11)
Minus
(Select voucher_number from your_table)
)
Order by voucher_num;
Cheers!!

How to user app_user in the where condition

using v('APP_USER') in where condition is returning to null records
select FULL_NAME, EMAIL_ADDRESS from headcount where EMAIL_ADDRESS = v('APP_USER')
There are 3 ways to get the value of APP_USER in an apex session. The preferred way is the bind variable (:APP_USER) but you can you also use the sys_context variable SYS_CONTEXT('APEX$SESSION','APP_USER') or the V function (V('APP_USER')). To prove that works I created a report with the following query:
WITH app_user_tab AS (SELECT 'bind var' as type, :APP_USER as username FROM DUAL
UNION
SELECT 'context',SYS_CONTEXT('APEX$SESSION','APP_USER') FROM DUAL
UNION
SELECT 'v', v('APP_USER') FROM DUAL)
SELECT * FROM app_user_tab
And i got 3 identical rows as expected.
Which leads me to believe your problem is not with the app user, but with the value in headcount.email_address. It could be:
case not matched.
leading/trailing control characters in the headcount.email_address column
you have to use bind variables in your sql.
V / NV functions are used in compiled code, such as views, packages, and procedures.
more info are here

Trying to create a "List of Values " including a table value and numbers below it

So basically say I have a table called "Device" and then one of the columns is "Quantity," what if I wanted to create a list of values that takes that number, say the quantity is 4, and the values are (quantity - 1) until !> 0, so in this case (4, 3, 2, 1)
I am using Oracle APEX and am assuming I need a dynamic LOV based on a sql query, but not sure how to get this. I've never used a for loop with PL/SQL
Thanks
You don't need loops for this.
select level
from dual
connect by level <= 4
order by level desc;
This should do it. Make sure that where I've put /* xxx */ you include a where clause that comes up with only 1 record. Most likely, you will use the ID of the Device table here.
SELECT ROWNUM display_value
, ROWNUM return_value
FROM DUAL
CONNECT BY ROWNUM <= (SELECT Quantity FROM Device WHERE /* xxx */)
ORDER BY ROWNUM DESC;

Resources