Search code examples
sqloracle-databaseuser-defined-types

Why multiset union is not working when I'm trying to concatenate a null with some number in plsql?


So i have two nested tables and i want to make a new one with the elements from both of them but the first nested table have an null value and the second one an number and i want the result to be the number in the second one but he print the null value. It is possible to make a union between a null and an number with multiset union ?


Solution

  • To answer your question, yes, it is possible to "make a union between a null and an number with multiset union". But what you end up with is **two entries in the nested table:

    SQL> update test 
      2  set marks = numberlist(null) multiset union all numberlist(42) 
      3  where id_std = 1 
      4 /
    SQL> select id_std 
      2       , t2.column_value as mark 
      3  from test t1 
      4     , table(t1.marks) t2 
      5  /
    
    ID_STD  MARK
    ------  ----
         1
         1    42
    
    SQL>
    

    I suspect this affect is actually what you're complaining about. However, the null mark is still a valid entry. If you want to overwrite it you need to provide different logic.