How to insert multiple values from checkbox group in oracle Apex? - oracle

I have an order table(id_order,id_category) and category table(id_category,description).
How can I insert to an order, more than 1 type of category in oracle Apex app?

One option is to use a shuttle item; it'll let you easily move desired categories from its left to right side. The result is a semi-colon separated list of values. For example, if you chose categories 1, 5 and 7, result is 1;5;7 so - in order to insert them properly into the order table, you'll first have to split them to rows.
How? Use apex_string.split:
SQL> select * from table(apex_string.split('1;5;7', ';'));
COLUMN_VALUE
--------------------------------------------------------------------------------
1
5
7
SQL>
All rows would share the same order_id, I presume (a sequence might be a good choice for its value).

Related

Does ordered hint in oracle also decides the order of rows in which they are fetched?

I read that 'The ORDERED hint causes Oracle to join tables in the order in which they appear in the FROM clause.'
But does it also fetch the rows in specific order?
For example: If I have ordered hint on column emp_code which has values as 'A','B' and 'C'[lets consider that more than 2 tables are joined to get emp_code ].
Will the output always have the specific order of rows? For example will 'A' always be the first row and 'C' be the last? does it decides the order of rows? and if yes then how?
No. The only thing that controls the order of rows in the final result set is the use of the ORDER BY clause in the SELECT statement. Hints are to influence the access plan chosen by the optimizer, not ordering of the result set.
select emp_id,
emp_name
from emp
order by emp_id -- <this is the only thing that controls the order of rows in the result set
;

How to check a checkbox in Apex 18 when its value is present in other table

I have a checkbox with list of values from table a. I need them to be checked if are present in a column of table b. Do you have any ready solution please colleagues ?
Thx
Adam
See this similar question for some background info.
When you're working with a multi-value checkbox item, you want your Source Query to select a colon-delimited list of the values that you want to be checked in your checkbox. (This is true for multi-value Application Express page items in general.) E.g.
select listagg(my_column, ':') within group (order by my_column)
from TableB
where my_column is the name of the column in TableB that your values are stored in.
If you have a lot of values in TableB (enough that the listagg() above returns more than 4000 characters), you'll need a fancier query, but for most cases it'll work fine.

first row VS Next row VS rownum

Those 3 queries return the same result set but use 2 different technics. Is there an advantage using one over the other? The plan and the execution time are in the same cost range.
Select *
from user_tab_columns
order by data_length desc,table_name, column_name
fetch first 5 rows only
Select *
from user_tab_columns
order by data_length desc,table_name, column_name
fetch next 5 rows only
select *
from (
Select *
from user_tab_columns
order by data_length desc,table_name, column_name
)
where rownum <=5
The keywords first and next as used in the fetch clause are perfect substitutes for each other, they can be used interchangeably - this is stated clearly in the documentation. So you really only have two queries there, not three. (The first two are really identical.)
The first query is easier to write and maintain than the last query. On the other hand, it is only available in Oracle 12.1 and later versions; in Oracle 11.2 and earlier, the only option is your last query.
The fetch clause is more flexible, for example it allows you to specify with ties (to include more than 5 rows if rows with rownum 4, 5, 6 and 7 are tied on the order by criteria, for example).

How to arrange data in SQL?

I am using Oracle SQL Plus.
Please refer to screenshot for reference.
After deletion of data of column sno=4, I want the output of sno to be displayed in serial order ie 1,2,3,4 instead of 1,2,3,5.
Please suggest the SQL query to achieve same.
try:
select ROWNUM as SNO, NAME,DOJ from company order by SNO
If you want the numbering to be persistent, you will need to update the SNO for all the remaining records in the table.
What you have done, by deleting the row is say that "row number 4 no longer exists". If you want to shuffle the remaining rows up, you will need to perform the following:
DELETE FROM company WHERE name='Flipkart';
UPDATE company SET sno=sno-1 WHERE sno>=4;
An alternative, if you don't want to alter the contents of the table itself.. But you want it to display correctly (specifically for this example)
SELECT
CASE
WHEN sno <= 4 THEN sno
ELSE sno-1
END AS sno,
name,
doj
FROM company
ORDER BY sno;

Oracle random row from table

I found this solution for selecting a random row from a table in Oracle. Actually sorting rows in a random manner, but you can fetch only the first row for a random result.
SELECT *
FROM table
ORDER BY dbms_random.value;
I just don't understand how it works. After ORDER BY it should be a column used for sorting. I see that "dbms_random.value" returns a value lower than zero. This behavior can be explained or is just like that?
Thanks
you could also think of it like this:
SELECT col1, col2, dbms_random.value
FROM table
ORDER BY 3
In this example the number 3 = the third column
When you order by dbms_random.value, Oracle orders by the expression, not for a column.For every record Oracle calculate a random number, and then order by this number.
In a similar way, is like this:
select * from emp order by upper(ename);
You have an order by based on a function.

Resources