When running report from forms (11g) get the error: REP-0788: Warning: The value of restricted LOV parameter is not among the selectable values - oracle

The parameter p_type is the LOV based on the select:
Select p_type
from parameter_types
where table_name = 'X'
and column_name = 'Y'
UNION
Select '-All-'
from dual;
Also the
1)Restrict List to Predermined Values is checked and
2) Hide First Column is unchecked.
3) initial value not given
I tried by setting up the into initial value to 'ALL'
Please help/suggest to debug this

It seems that you set parameter's initial value to something that LoV query doesn't return.
For example, suppose that you used Scott's DEPT table and set LoV to return this:
SQL> select dname from dept order by dname;
DNAME
--------------
ACCOUNTING
OPERATIONS
RESEARCH
SALES
Setting initial value to e.g. FINANCIALS would cause that error because FINANCIALS doesn't exist among selectable values (ACCOUNTING, OPERATIONS, RESEARCH, SALES).
What to do? Remove initial value, or set it to one of valid values.

Related

How to delete multiple rows using shuttle page item in Oracle Apex?

My requirement is that users must be able to select from a shuttle page item the employee numbers that they need to delete from a table. In the back end I have a plsql code that is supposed to delete the selected employee numbers as follows:
BEGIN
delete from employees where empno in (:P7_EMPLOYEE_NUMBER);
END;
Additionally I will have more logic in the code to do other stuff, however I am not able to delete multiple rows, if I select 1 employee number in the shuttle item, I am able to delete the record successfully, when I try to delete more than one record I keep getting the following error:
Ajax call returned server error ORA-01722: invalid number for Execute Server-Side Code
I changed the code to:
BEGIN
delete from employees where empno in (to_number(:P7_EMPLOYEE_NUMBER));
END;
and I keep getting the same error message.
How can I make this work?
The API APEX_STRING has a number of utility functions to deal with multi-value page items (select lists, checkbox, shuttles). To convert a colon separated list to an array, use APEX_STRING.SPLIT.
DELETE
FROM
employees
WHERE empno IN
(SELECT column_value
FROM table(apex_string.split(: P7_EMPLOYEE_NUMBER,':'))
);
A shuttle item contains colon-separated values, which means that you have to split it to rows, e.g.
delete from employees
where empno in (select regexp_substr(:P7_EMPLOYEE_NUMBER, '[^:]+', 1, level)
from dual
connect by level <= regexp_count(:P7_EMPLOYEE_NUMBER, ':') + 1
);
The APEX engine will always submit multi-values items as a single colon-delimited string, for example: 1:2:3:4
You need to split the string into multiple values so that you can process them.
There are multiple ways to do this:
Using an the APEX_STRING.SPLIT or the APEX_STRING.SPLIT_NUMBERS API in a subquery
delete from employees
where empno in (select column_value
from apex_string.split_numbers(:P7_EMPLOYEE_NUMBER, ':'));
Using the APEX_STRING API with the MEMBER OF function
delete from employees
where empno member of apex_string.split_numbers(:P7_EMPLOYEE_NUMBER, ':');
Note that the member of needs to have the same type. In this case empno is a number so you must use the split_numbers API.
Using a regular expression to split the values
delete from employees
where empno in (select regexp_substr(:P7_EMPLOYEE_NUMBER, '[^:]+', 1, level)
from dual
connect by level <= regexp_count(:P7_EMPLOYEE_NUMBER, ':') + 1
);
I prefer using option 2 as it's less code and easier to read.

How to create and use a multi-select list in APEX ORACLE?

I have a table called Employees with Employee_id and Employee_Name columns. Now i want to create a page with Checkbox in-front of every Employee Name, select the ones that are needed, store them into a temporary table and use them for further operations. The problem i am facing is to how to create that multi select list and store the select values in thee table. Is there an Item for multi select? If not, how should i do it?
There's the Shuttle item. On the left side, you'd display list of all employees. Item buttons allow you to move all (or only some of them) to the right side of the item. Once you submit the page, list of employee IDs is stored into a table column in a form of colon-separated values, for example
6547:8879:5587:9987
This is a simple way of doing that. However, once you have to actually do something with those values, you have to split them to rows. Not a problem, though. Here's a query:
SQL> with emps (shuttle_item) as
2 (select '6547:8879:5587:9987' from dual)
3 select regexp_substr(shuttle_item, '[^:]+', 1, level) one_item
4 from emps
5 connect by level <= regexp_count(shuttle_item, ':') + 1;
ONE_ITEM
---------------------------------------------------------------------
6547
8879
5587
9987
SQL>
Or, you could create a tabular form which also displays all employees and has checkboxes at the beginning of every line. You'd then create a process which - in a loop - stores selected values into a temporary table you mentioned. For example:
-- F01 = row selector. If you check 1st and 3rd row, f01.count = 2 (2 rows checked)
-- f01(1) = 1 (row #1), f01(2) = 3 (row #3)
-- F02 = EMP_ID. f02(1) = EMP_ID that belongs to employee in 1st row,
-- f02(3) = EMP_ID that belongs to emplyee in 3rd row
declare
l_id number;
begin
for j in 1 .. apex_application.g_f01.count
loop
l_id := apex_application.g_f02(apex_application.g_f01(j));
insert into temp_table (emp_id) values (l_id);
end loop;
end;
There is an option for creating multi select list in oracle apex 5.1.
Create a pageItem of type: 'select list'.
Make the 'Allow multi
selection' to 'Yes'.
Write the SQL query for your select list under
the 'List of Values' attribute.
Then the select list will be
displayed based on our query.
Query format is:
select [displayValue],
[returnValue]
from ...
where ...
order by ...
Now once you select multiple value from select list(using ctrl+click), these are stored as ':' separated values in the select list page item.
I've created a video some times ago that covers your problem. It's a step by step tutorial how to create checkboxes and process them.
Video is available here:
https://www.youtube.com/watch?v=T-LXRMWQbPk
Regards
If the list is too big, I recommend to use the Popup LOV item with the Multiple Values switch activated instead the Select list or the Shuttle, because it has an internal search field for the objects list, doing way easier for the user to find the target values. Also, just as the Select List or Shuttle item, you can set a Separator character for the selected fields.

How to select multiple column names (not values) in a table when column value is specified-Oracle

I have a table which has around 30 columns.Out of 30 columns i need to retrieve around 25 column names where value is set to some specified value(say 1).
I am not able to find a way to do this.Will multiple if statement work as below
select if columnname1='1' then 'columnname1' else null
if columnname2='1' then 'columnname2' else null from table.
In case the value is not set to 1, i don't want to retrieve the column names.
The below query can give me the column names but i can't specify the value with below query
select DISTINCT COLUMN_NAME from ALL_TAB_COLUMNS where TABLE_NAME='table_name'.
Does this work for you?
SELECT COLUMN_NAME
from ALL_TAB_COLUMNS
where TABLE_NAME='TABLE_NAME'
AND INSTR(column_name,'1') >0

PLSQL - Parameter cursor with different return

I know the title is saying nothing... but the argument is a little "complex" to explain in a single row.
All the code i'm writing is just an example, my current code is from other table etc, but the behaviour is the same.
i have defined a cursor like this:
CURSOR emp_cur (l_type)
IS
with emp_general AS (select *
from emp
where type = l_type),
emp_active AS (select *
from emp_geral
where status = ACTIVE_STATUS),
emp_inactive AS (select *
from emp_general
where status = INACTIVE_STATUS)
select distinct name, department
from emp_active
minus
select distinct name, department
from emp_inactive;
This cursor take a parameter for filter emp type and make a minus to fetch ACTIVE - INACTIVE emp.
This cursor return name and department.
Now have to declare different cursor with different "select" statemant, for example:
select location
from emp_active
select location
from emp_active
I would like to dont duplicate my cursor just to change the select. There is a way to do this and avoid code duplication (withuout using DynamicSQL - Difficult to debug in production enviroment)?
You could create two Global temporary tables explicitly once(not on the fly):
emp_active_gtt
emp_inactive_gtt
Such that, each temp table will have the entire result set of active and inactive records respectively.
For example, in the code you would do:
insert into emp_active_gtt
select *
from ....
where status ='ACTIVE'
Similarly, for inactive records:
insert into emp_inactive_gtt
select *
from ....
where status ='INACTIVE'
You could now use the two tables in the scope of the session anywhere to get the required rows.
Read more about GTT in the documentation here https://docs.oracle.com/database/121/SQLRF/statements_7002.htm#i2153132

Oracle identity column and insert into select

Oracle 12 introduced nice feature (which should have been there long ago btw!) - identity columns. So here's a script:
CREATE TABLE test (
a INTEGER GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
b VARCHAR2(10)
);
-- Ok
INSERT INTO test (b) VALUES ('x');
-- Ok
INSERT INTO test (b)
SELECT 'y' FROM dual;
-- Fails
INSERT INTO test (b)
SELECT 'z' FROM dual UNION ALL SELECT 'zz' FROM DUAL;
First two inserts run without issues providing values for 'a' of 1 and 2. But the third one fails with ORA-01400: cannot insert NULL into ("DEV"."TEST"."A"). Why did this happen? A bug? Nothing like this is mentioned in the documentation part about identity column restrictions. Or am I just doing something wrong?
I believe the below query works, i havent tested!
INSERT INTO Test (b)
SELECT * FROM
(
SELECT 'z' FROM dual
UNION ALL
SELECT 'zz' FROM dual
);
Not sure, if it helps you any way.
For, GENERATED ALWAYS AS IDENTITY Oracle internally uses a Sequence only. And the options on general Sequence applies on this as well.
NEXTVAL is used to fetch the next available sequence, and obviously it is a pseudocolumn.
The below is from Oracle
You cannot use CURRVAL and NEXTVAL in the following constructs:
A subquery in a DELETE, SELECT, or UPDATE statement
A query of a view or of a materialized view
A SELECT statement with the DISTINCT operator
A SELECT statement with a GROUP BY clause or ORDER BY clause
A SELECT statement that is combined with another SELECT statement with the UNION, INTERSECT, or MINUS set operator
The WHERE clause of a SELECT statement
DEFAULT value of a column in a CREATE TABLE or ALTER TABLE statement
The condition of a CHECK constraint
The subquery and SET operations rule above should answer your Question.
And for the reason for NULL, when pseudocolumn(eg. NEXTVAL) is used with a SET operation or any other rules mentioned above, the output is NULL, as Oracle couldnt extract them in effect with combining multiple selects.
Let us see the below query,
select rownum from dual
union all
select rownum from dual
the result is
ROWNUM
1
1

Resources