简体   繁体   English

Oracle Apex - 逗号分隔LOV

[英]Oracle Apex - Comma Separated LOV

I'm using Oracle Apex 4,2. 我正在使用Oracle Apex 4,2。 I have a table with a column in it called 'versions'. 我有一个表中有一个名为'versions'的列。 In the 'versions' column for each row there is a list of values that are separated by commas eg '1,2,3,4'. 在每行的“版本”列中,有一个由逗号分隔的值列表,例如“1,2,3,4”。
I'm trying to create a Select List whose list of values will be each of the values that are separated by commas for one of the rows. 我正在尝试创建一个选择列表,其值列表将是其中一行以逗号分隔的每个值。 What would the SQL query for this be? SQL查询会是什么?

Example: 例:

Table Name: Products 表名:产品

Name     | Versions
--------------------
myProd1  | 1,2,3
myProd2  | a,b,c

Desired output: 期望的输出:
Two Select Lists. 两个选择列表。
The first one is obvious, I just select the name column from the products table. 第一个是显而易见的,我只是从products表中选择name列。 This way the user can select whatever product they want. 这样,用户可以选择他们想要的任何产品。 The second one is the one I'm not sure about. 第二个是我不确定的。 Let's say the user has select 'myProd1' from the first Select List. 假设用户已从第一个选择列表中选择“myProd1”。 Then the second select should contain the following list of values for the user to select from: '1.0', '1.1' or '1.2'. 然后第二个选择应包含以下值列表供用户选择:'1.0','1.1'或'1.2'。

After reading your latest comments I understand that what you want is not an LOV but rather list item. 阅读完最新评论后,我明白你想要的不是一个LOV,而是一个列表项。 Although it can be an LOV too. 虽然它也可以是LOV。 The first list item/lov will have all products only that user selects from it, eg Prod1, Prod2, Prod3... The second list item will have all versions converted from comma separated values as in your example to table as in my examples below. 第一个列表项/ lov将只包含用户从中选择的所有产品,例如Prod1,Prod2,Prod3 ......第二个列表项将使用逗号分隔值转换所有版本,如下例所示。 。 Because in my understanding user may pick only a single value per product from this list. 因为在我的理解中,用户可以从该列表中仅为每个产品选择一个值。 Single product may have many values, eg Prod1 has values 1,2,3, 4. But user needs to select only one. 单个产品可能有许多值,例如Prod1的值为1,2,3,4。但用户只需选择一个。 Correct? 正确? This is why you need to convert comma values to table. 这就是您需要将逗号值转换为表的原因。 The first query select is smth lk this: 第一个查询选择是smth lk这个:

SELECT prod_id
  FROM your_prod_table
 /

 id      
 --------
 myProd1 
 myProd2 
 .....

The second query should select all versions where product_id is in your_prod_table: 第二个查询应该选择product_id在your_prod_table中的所有版本:

 SELECT version FROM your_versions_table
   WHERE prod_id IN (SELECT prod_id FROM your_prod_table)
 /

 Versions
 --------
 1,2,3,4   -- myProd1 values
 a,b,c,d   -- myProd2 values
 .....

The above will return all versions for the product, eg all values for myProd1 etc... 以上将返回产品的所有版本,例如myProd1等的所有值...

Use my examples converting comma sep. 使用我的示例转换逗号sep。 values to table. 表的值。 Replace harcoded '1,2,3,4' with your value column from your table. 将harcoded'1,2,3,4'替换为您表中的值列。 Replace dual with your table name 将dual替换为您的表名

If you need products and versions in a single query and single result then simply join/outer join (left, right join) both tables. 如果您需要单个查询中的产品和版本以及单个结果,则只需加入/外连接(左,右连接)两个表。

SELECT p.prod_id, v.version 
  FROM your_prod_table     p
     , your_versions_table v
  WHERE p.prod_id = v.prod_id
 /

In this case you will get smth lk this in output: 在这种情况下,您将在输出中获得smth lk:

 id      |  Values
 ------------------
 myProd1 | 1,2,3,4
 myProd2 | a,b,c,d

If you convert comma to table in above query then you will get this - all in one list or LOV: 如果你在上面的查询中将逗号转换为表格,那么你将得到这个 - 所有在一个列表或LOV中:

 id      |  Values
 ------------------
 myProd1 | 1
 myProd1 | 2
 myProd1 | 3
 myProd1 | 4
 myProd2 | a
 myProd2 | b
 myProd2 | c
 myProd2 | d

I hope this helps. 我希望这有帮助。 Again, you may use LOV or list values if available in APEX. 同样,如果在APEX中可用,您可以使用LOV或列表值。 Two separate list of values - one for products other for versions - make more sense to me. 两个单独的值列表 - 一个用于其他版本的产品 - 对我来说更有意义。 In case of list items you will need two separate queries as above and it will be easier to do comma to table conversion for values/versions only. 对于列表项,您将需要两个单独的查询,如上所述,只有值/版本的表转换更容易。 But is is up to you. 但是取决于你。

Comma to table examples: 逗号到表示例:

-- Comma to table - regexp_count --
SELECT trim(regexp_substr('1,2,3,4', '[^,]+', 1, LEVEL)) str_2_tab
  FROM dual
 CONNECT BY LEVEL <= regexp_count('1,2,3,4', ',')+1
/

-- Comma to table - Length -
SELECT trim(regexp_substr('1,2,3,4', '[^,]+', 1, LEVEL)) token
  FROM dual
CONNECT BY LEVEL <= length('1,2,3,4') - length(REPLACE('1,2,3,4', ',', ''))+1
/

-- Comma to table - instr --
SELECT trim(regexp_substr('1,2,3,4', '[^,]+', 1, LEVEL)) str_2_tab
  FROM dual
 CONNECT BY LEVEL <= instr('1,2,3,4', ',', 1, LEVEL - 1)
/

The output of all that above is the same: 以上所有内容的输出是相同的:

STR_2_TAB
----------
1
2
3
4

Comma to table - PL/SQL-APEX example. 表格的逗号 - PL / SQL-APEX示例。 For LOV you need SQL not PL/SQL. 对于LOV,您需要SQL而不是PL / SQL。

DECLARE
  v_array apex_application_global.vc_arr2;
  v_string varchar2(2000);
BEGIN
-- Convert delimited string to array
   v_array:= apex_util.string_to_table('alpha,beta,gamma,delta', ',');

  FOR i in 1..v_array.count LOOP
    dbms_output.put_line('Array: '||v_array(i));
  END LOOP;

 -- Convert array to delimited string
  v_string:= apex_util.table_to_string(v_array,'|');
  dbms_output.put_line('String: '||v_string);
END;
/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM