How to merge elements of two tables (defined as local types)

Hello

How can he get the elements in array 'a' and 'b' in table 'c '. I could write a loop, but I don't know if there is a smarter option:

DECLARE
  TYPE t IS TABLE OF NUMBER;
  a t;
  b t;
  c t;
BEGIN
  a := t(1,2,3);
  b := t(3,4,5);
  c := ...  -- c {1, 2, 3, 3, 4, 5}     
END;

I could use something like that, but I prefer to define the type of table in a package:

CREATE OR REPLACE TYPE t AS TABLE OF NUMBER;

SELECT a MULTISET UNION b INTO c FROM dual;


Thanks in advance

Try this:

DECLARE

TYPE T IS TABLE OF NUMBER;

A T;

b T;

c T;

BEGIN

A: = T (1,2,3);

b: = T (3,4,5);

--c: =...--c {1, 2, 3, 3, 4, 5}

c: = A MULTISET UNION B;

END;

/

Tags: Database

Similar Questions

  • How to match columns from two tables with

    Hello:
    I have two tables as below:

    Table1::(Base Table)
    Country | Prefix | Prefix_Length
    Travel | 001 | 3
    CountryB. 0012 | 4
    PaysC | 00443 | 5
    CountryD | 0091 | 4

    :(Detail Table) table2
    The population | Area | Prefix
    500 | AreaA | 0015921
    1000 | AreaB | 00122
    400. AreaC. 00443743
    300. ALIS | 0091333
    100. AreaA | 001

    I need to match these two tables with prefix columns (whose length is not fixed in the two tables: but it starts with 00 in the two tables). Two different countries the prefix may be similar up to a certain length. Thus, Prefix_Length can be used to determine (exactly) how much time should be taken in the search of Table2.

    Output:
    Country | Prefix | Area | Population
    Travel | 001 | AreaA | 600
    CountryB. 0012 | AreaB | 1000
    PaysC | 00443 | AreaC. 400
    CountryD | 0091 | ALIS | 300

    Please help me with your valuable comments.

    -Tender

    Try this

    with base_table as (
                        select 'CountryA' country,'001' prefix,3 prefix_length from dual union all
                        select 'CountryB','0012',4 from dual union all
                        select 'CountryC','00443',5 from dual union all
                        select 'CountryD','0091',4 from dual
                       ),
       detail_table as (
                        select 10 no_of_call,'0015921' prefix from dual union all
                        select 3,'00122' from dual union all
                        select 50,'00443743' from dual union all
                      select 50,'00443643' from dual union all
                        select 300,'0091333' from dual union all
                        select 60,'001' from dual
                       ) 
    
    SELECT  country,
            prefix,sum(no_of_call)
       FROM (
             select  country,
            b.prefix,no_of_call,
            decode(no_of_call,lead(no_of_call,1,0) over(partition by no_of_call order by b.prefix,no_of_call),'y','n') y_or_no
      from  base_table b,
            detail_table d
      where b.prefix = substr(d.prefix,1,prefix_length))
      where y_or_no !='y'
      group by  country,
            prefix
      order by country,
            prefix;
    

    Published by: Vi on 20 February 2012 01:07

  • How the sum of these two tables?

    Hello

    I have two tables

    DESC ACTIVITE_EXCEP_FAITE

    NUMBER OF FICHE_ID

    NUMBER OF SERVICES_ID

    NUMBER OF ACTIVITES_EXCEPTIONNELLES_ID

    NUMBER OF TIME

    NUMBER OF ACTIVITE_EXCEP_FAITE_ID

    DESC ACTIVITE_FAITE

    NUMBER OF FICHE_ID

    NUMBER OF ACTIVITES_ID

    NUMBER OF SECTEURS_ID

    LENGTH NUMBER (8.2)

    NUMBER OF ACTIVITE_FAITE_ID

    NUMBER OF TYPE_ACTIVITE_ID

    I want to add the column to the DURATION of the two tables when they get the same FICHE_ID. FICHE_ID is not a join field.

    I've tried this application, but it gives result when two recordings of the two table share the same number FICHE_ID.

    SELECT AF. FICHE_ID, SUM (NVL (AF. LENGTH, 0)) + SUM (NVL (AEF. LENGTH, 0))

    OF AF, ACTIVITE_EXCEP_FAITE AEF ACTIVITE_FAITE

    WHERE AF. FICHE_ID = AEF. FICHE_ID

    GROUP BY AF. FICHE_ID;

    Can you help me write this selection?

    Thank you very much for your help!

    Like this?

    select nvl(af.fiche_id, aef.fiche_id) fiche_id
         , sum(nvl(af.duree,0)) + sum(nvl(aef.duree,0)) duree
      from activite_faite af
      full join
           activite_excep_faite aef
        on af.fiche_id = aef.fiche_id
     group by nvl(af.fiche_id, aef.fiche_id);
    
  • How to MERGE when the target table contains invisible columns?

    Oracle running on Oracle Linux 6.4 12.1.0.2.0 database:

    During his studies of FUSION with invisible columns, I discovered that invisible columns in the target table cannot be read. Workaround seems to be

    MERGE INTO (SELECT <column list> FROM <target table>) AS <alias>
    

    However, the documentation does not seem to allow this. Here are the details.

    Test data

    > CREATE TABLE t_target(
      k1 NUMBER PRIMARY KEY,
      c1 NUMBER,
      i1 NUMBER invisible
    )
    
    table T_TARGET created.
    
    > INSERT INTO t_target (k1,c1,i1)
    SELECT 2, 2, 2 FROM dual
    UNION ALL
    SELECT 3, 3, 3 FROM dual
    UNION ALL
    SELECT 4, 4, 4 FROM dual
    
    3 rows inserted.
    
    > CREATE TABLE t_source(
      k1 NUMBER PRIMARY KEY,
      c1 NUMBER,
      i1 NUMBER invisible
    )
    table T_SOURCE created.
    
    > INSERT INTO t_source (k1,c1,i1)
    SELECT 1, 1, 1 FROM dual
    UNION ALL
    SELECT 2, 2, 9999 FROM dual
    UNION ALL
    SELECT 3, 3, 3 FROM dual
    
    3 rows inserted.
    

    First try

    Please note that I have a WHERE clause in the WHEN MATCHED clause. Its purpose is to avoid the update of a row when data are already correct. The WHERE clause is trying to read the invisible column of the target table.

    > MERGE INTO t_target o
    USING (
      SELECT k1, c1, i1 FROM t_source
    ) n
    ON (o.k1 = n.k1)
    WHEN MATCHED THEN UPDATE SET
      c1=n.c1, i1=n.i1
      WHERE 1 IN (
        decode(o.c1,n.c1,0,1),
        decode(o.i1,n.i1,0,1)
      )
    WHEN NOT MATCHED THEN INSERT
      (k1, c1, i1)
      VALUES(n.k1, n.c1, n.i1)
    ...
    Error at Command Line : 10 Column : 12
    Error report -
    SQL Error: ORA-00904: "O"."I1": invalid identifier
    

    As you can see, I put a subquery after the USING clause so that 'n.i1' would be 'visible', but this is not enough since the 'I1' column in the target table is always invisible.

    Second test

    > MERGE INTO (
      SELECT k1, c1, i1 FROM t_target
    ) o
    USING (
      SELECT k1, c1, i1 FROM t_source
    ) n
    ON (o.k1 = n.k1)
    WHEN MATCHED THEN UPDATE SET
      c1=n.c1, i1=n.i1
      WHERE 1 IN (
        decode(o.c1,n.c1,0,1),
        decode(o.i1,n.i1,0,1)
      )
    WHEN NOT MATCHED THEN INSERT
      (k1, c1, i1)
      VALUES(n.k1, n.c1, n.i1)
    
    2 rows merged.
    

    Here I used a subquery in the INTO clause thus, and it worked.

    Unfortunately, this does not seem to be admitted in the documentation: IN fact refers to a table or a view as schema objects.

    Description of merge.gif follows

    My question is:

    How can I refer to invisible columns in the target table without creating a new object? My workaround using a subquery solution seems to work very well, but can I recommend if it is not documented?

    Can I replace a "inline view" for a view and still be supported?

    During his studies of FUSION with invisible columns, I discovered that invisible columns in the target table cannot be read. Workaround seems to be

    However, the documentation does not seem to allow this. Here are the details.

    Here I used a subquery in the INTO clause thus, and it worked.

    Unfortunately, this does not seem to be admitted in the documentation: IN fact refers to a table or a view as schema objects.

    My question is:

    How can I refer to invisible columns in the target table without creating a new object? My workaround using a subquery solution seems to work very well, but can I recommend if it is not documented?

    Can I replace a "inline view" for a view and still be supported?

    But the documentation DO ALLOWS not only! You use a view - a view online and those that can be changed in a MERGE statement.

    All versions of the doc for FUSION since 9i specifically say this:

    INTO clause

    Use the INTO target clause to specify the table or view you are updating or inserting into. To merge the data in a view, the view must be updated. Please refer to the "Notes on the editable views" for more information.

    Here are the links for the doc. 9i, 10g, 11g and c 12, ALL OF THEM (the last three), except 9i have this EXACT clause above.

    SQL statements: INDICATED to ROLLBACK FALLS, 15 of 19

    http://docs.Oracle.com/CD/B19306_01/server.102/b14200/statements_9016.htm

    http://docs.Oracle.com/CD/B28359_01/server.111/b28286/statements_9016.htm

    https://docs.Oracle.com/database/121/SQLRF/statements_9016.htm

    9i doc does not have this specific quote in the INTO clause section, but it doesn't have that quote a little later:

    Limitation of the update of a view
    • You cannot specify DEFAULT when refreshing a view.
    • You cannot update a column referenced in the ON condition clause.
    merge_insert_clause

    The merge_insert_clause specifies the values to insert into the column of the target table, if the condition of the ON clause is false. If the insert clause is executed, then all insert triggers defined on the target table are activated.

    Restrictions on the merger in a view

    You cannot specify DEFAULT when refreshing a view.

    If your "workaround" isn't really a workaround solution. You SHOULD use an inline view if you need to reference a column "invisible" in the target table, since otherwise, these columns are INVISIBLE!

    My workaround using a subquery solution seems to work very well, but can I recommend if it is not documented?

    You can recomment it because IT IS documented.

  • How to extract elements from two different descriptors-point?

    Hi all

    I have a requirement for all elements of trade based on a property in the trade section and order status should be presented.

    Status of the order is in order and trade item to the article of commerce property.

    is it possible to ask about two descriptors of the order of the day, if possible, please provide a solution as soon as POSSIBLE.

    Thanks in advance

    You only need commerceItems based on a trade item property and a property of the order. as referential point trade point has the associated command point reference thats why it is feasible with the POOR. You should search the descriptor CommerceItem point OrderRepository. Your POOR query would be like yourcustomProperty is equivalent to "xyz" AND Decree. Status equals "SUBJECT"

  • How to merge data from the table with a single line

    Hello

    I have three tables subscription_type, the address and the person. Here are the details of the table

    Person Subscription_type Address                                           

    Person_Id AdressType_id Address_id

    Person_name Description Address_type_id

    Person_id

    Address details


    There are three types of different address - home, postal and previous.

    Each person can have these three different addresses.

    I want to create a view that displays all addresses of three of each person in the table of the person in a single line.

    Any help please

    In your example, there are 2 rows of columns street1, TOWN, SUBURB etc for a single person. To convert this into a single line, with the new columns we could simply use CASES or DECODE in the select as the SQL below. To understand why consolidation function THAT MAX is used - remove the MAX and GROUP BY in SQL keyword and try.

    Select full_name

    , max (case when description = "Home" then end street1) Home_Street

    , max (case when description = "Home" then end suburb) home_suburb

    , max (case when description = end of the "Home" then City) home_city

    , max (case when description = "Home" then postal code end) home_postcode

    , max (case when description = "Home" then end state_name) home_state

    , max (case when description = 'Postal' then end street1) Postal_Street

    , max (case when description = 'Postal' and then end of suburb) Postal_suburb

    , max (case when description = 'Postal' then the city) Postal_city

    , max (case when description = 'Postal' and then end of CP) Postal_postcode

    , max (case when description = 'Postal' then state_name end) Postal_state

    , max (case when description = "Back" then end street1) Prev_Street

    , max (case when description = "Back" then end suburb) Prev_suburb

    , max (case when description = "Back" then city end) Prev_city

    , max (case when description = "Back" then postal code end) Prev_postcode

    address a

    S State

    No p

    Subscription_type att

    where a.person_id = p.person_id

    and a.state_id = s.state_id

    and a.address_type_id = att.address_type_id

    Full_name group

  • How can I update by program table combo box control type def?

    I use LV 8.6.1 and I am trying to create a table control panel object in which the user can select an item to list box for each element of the array.  I also have to periodically update the list of values.  Currently, I have configured the drop-down list box (selection of Automation sequence - see attached) as a type non-stricte def so I can write news channels to the list values when I need to.  But I can't seem to find a way to get the table (list of batches - see rasthaus) fill the new value drop-down list box.

    Automation box refelcts the new string sequence selection that I add programmatically, but the combo boxes in the batch list table control do not have the new channel.

    Anyone have any ideas?

    I have attached the screenshot of the drop-down list and table controls.

    Thank you

    Dan

    I considered that mention strings and values have a property that cannot be stored in a typedef, but when I tried it out, it seemed that it was.  So I just did not comment on that.  Maybe the strings and values may be among the typedef, maybe not.  The values of the controls certainly cannot.  Strings and values can be in kind of a gray area.  But you can certainly expect changes to a control to automatically update another control, because they are typedefs.  You cannot change the typedefs during execution.

    Let's put another example that has nothing to do with the values.  You have a regular typedef of a digital.  It is saved with the text in red in scientific notation.  You place two instances of this on your drawing.  You can programmatically change each other colors or other digital formats.  A change does not affect the other.  If it's a strict typedef, you would be locked in the way in which it was saved and could not change it programmatically.

    Take a look at this.  If you cannot programmatically, to update your channel list and values for a single combobox (a scalar string) you will be able to put up-to-date for when the combobox control is the data type for a table.  Simply get a reference to the element of the array.  It does not use typedefs anyway.

  • With the last update, I am unable to merge cells in a table and Ive tried Split and Live view.

    With the last update, I am unable to merge cells in a table and Ive tried Split and viewing live, all the tutorial and manuals say to do in Design view, which is no longer available.  How to merge cells in a table now?

    To get the fashion Design back in a checkerboard to fluid...

    Close all other files, open the fluid grid css and add the X below:

    /*

    Properties Grid Dreamweaver fluid

    ----------------------------------

    DW-num-CLO-mobile: X 4;

    DW-num-CLO-Tablet: 8;

    DW-num-OCOL-Office: 12;

    DW-gutter-percentage: 25;

    =====================================

    Then save and close the file.

    DW restart and you should have mode Design from here out on all files using this fluid grid .css file.

  • Does anyone know how to merge two workseets number for printing?

    How can I combine two spreadsheets in numbers for printing?

    Hi jj,

    I assume that you mean that you have a single document, which contains two worksheets, and that each sheet contains one table (only?).

    What do you mean by "merge two (booklets)?

    You mean you wan to place Tables of two leaves on a single sheet (this sheet would contain then both tables).

    Or do you mean you want to place all data on the two tables into a single table on one sheet?

    Or do you mean something different to both of these descriptions?

    Kind regards

    Barry

  • Merge two tables to a view

    I have two tables I have merged into a single view.
    All rows from both tables to merge into a single view.

    Not table 1 no criteria:
    MATERIAL     PLANT     QUANTITY     UNIT     POSTING_DATE
    Table 2 criteria:
    MATERIAL     PLANT     SALES_QUANTITY     UNIT     POSTING_DATE     RECORD_TYPE
    Where RECORD_TYPE IN('O','U')
    The view should look like this:
    MATERIAL     PLANT     QUANTITY     UNIT     POSTING_DATE
    I'm not going anywhere, what should I do?

    Hello

    Maybe you want something like this:

    CREATE OR REPLACE VIEW  table_1_and_ou_from_2
    AS
         --
    SELECT     material, plant,       quantity, unit, posting_date
    FROM     table1
         --
    UNION ALL
            --
    SELECT     material, plant, sales_quantity, unit, posting_date
    FROM     table2
    WHERE     record_type     IN ('O', 'U')
    ;
    

    The columns in the view will have the same names that the columns of the 1st branch of the UNION, then the 3rd column will be called quantity, not sales_quantity.

    I hope that answers your question.
    Otherwise, then, as mentioned above, post a small example data (CREATE TABLE and only relevant columns, INSERT statements) for all of the tables involved and also publish outcomes from these data (that is, the content of the view).
    Explain, using specific examples, how you get these results from these data.
    Always say what version of Oracle you are using (for example, 11.2.0.2.0).
    See the FAQ forum {message identifier: = 9360002}

  • How to merge 3 different tables using ADF BC?

    Hello

    I have 3 tables (i.e. employee location, Dept)

    First of all I must merge employee and Dept as "* EmployeeDept *" table with the primary key (EmployeeID) and then I should merge "* EmployeeDept *" with Dept table with the primary key (DeptID) from the Dept table.»»
    I tried "* ViewLink *"I am however able to merge two tables (employee and Dept) as "EmployeeDept", no idea how to merge the third table (Dept) with her. "

    Help, please.

    Thanks in advance

    Either by the method described by Shay or build you a new vo, select expert mode for the query and write the select statement. In this case, the data cannot be modified.

    Timo

  • How to use a table defined in the main Script block in an InlineCode Block of a DataGridColumn ComboBox itemRenderer?

    Hello

    How can I use a table defined in the main Script block in an InlineCode Block of a DataGridColumn ComboBox itemRenderer?

    Thanks for any help!

    Martin West

    I hope my problem with the Code:

    < fx:Script >

                <! [CDATA]

    private var myArrayOut: Array =new Array (' one of ','out two', "three out");

    < / fx:Script >

    ...

    DataGrid...
    < mx:DataGridColumn headerText = "MyColumn" dataField = "MyColumn" rendererIsEditor = "true".
    < mx:itemRenderer >
    < fx:Component >
    < mx:ComboBox creationComplete = "init ()" >
    < fx:Script >
    <! [CDATA]
    private var myArrayIn: Array = new Array ('one', 'two', 'three');

    private function init (): void {}

    this.dataProvider = myArrayIn; / / How can I use myArrayOut here?
    }
    []] >
    < / fx:Script >
    < / mx:ComboBox >
    < / fx:Component >
    < / mx:itemRenderer >
    < / mx:DataGridColumn >

    Hello

    outerDocument is a link to external data and functions.

    If you need

    outerDocument.myArrayOut.

  • When you configure synchronization how sync manages information on two computers? It merges the information?

    When you configure synchronization how sync manages information on two computers? It merges the information?

    Hello!

    Yes, how Sync is that it brings together all the bookmarks and pushes them to all your devices. Same thing with the story.

    You will lose all the information in one of your computers.

  • Merge two tables 2D?

    Hello

    I have a question about the merger of the two 2D arrays. I have a program that generates two tables different interms of binary digits (attached file) and I wanted to arrange them as below.

    The first generation of table: 1110

    1101

    1011

    0111

    Second generated table: 0001

    0010

    0100

    1000

    Output should be: 1110

    0001

    1101

    0010

    1011

    0100

    0111

    1000

    Thank you.

    Hello

    Order the attached VI

    Kind regards

    Amine31

    (Give congratulations to good answers and Mark as a Solution If your problem is resolved)

  • Need some tips to merge the two table-manipulation functions

    Hi guys!

    Thanks to Johnsold, Helmut O'Brian and Jcarmody, who helped me through a string function complicated (for me, the noob of LV), I got away with my project and I'm very close to its end.

    As I've described it here I wanted to explore an array of words combined with-, i.e. C1 - C10. Help, when I arrived, I was able to do. I also learned a few things and was able to do the following:

    Original array: new table:

    R1                                                       R1

    R2                                                       R2

    C1-C3                                                  C1

    K1                                                       C2

    C3

    K1

    I have this:

    Original array: new table:

    R1                                                       R1

    R2,R4,R7                                             R2

    C1                                                       R4

    K1                                                       R7

    C1

    K1

    I was also able to combine these two functions

    Now, back to my problem.

    Until now, it was just a 1 d array that I worked with. In fact, it's a 2D array, I read a. CSV file:

    As you can see there are a few places where things is combined with either - or by commas. I need to widen the first column as described above and as resolved in the thread I mentioned. Fact! No problem. I extracted the first column in table 1 d. Then expand it. Now, I need to replace in the original array and also expand all.

    It should then look like this:

    Then I only need to copy the position of the R6 line and paste it in the empty fields:

    I enclose below two screws. Start by opening the main.vi. Then copy.vi. I tried to describe the problem here too. You can see what I've accomplished and what is missing.

    Tasks:

    1. replace the column expanded in the original array and expand all.

    2 copy the needed lines.

    In the main.vi, I do the 1 d expansion, but I have the problem with the expansion of table 2D. In copy.vi, I managed to copy the lines. If this part is done.

    Basically, I need some advice on enlargement that I do and how do I get the 2D table also expanded. Because I have not much experience, I feel more comfortable working with 1 d arrays. But I can't seem to get any further with this 1 d-> expansion 2D.

    I also really can't seem to find a smart way to implement my function of copy-line-in the main.vi.

    P.S the joint screws are manufactured in LV2010.

    Fortunately, I can attend some courses of basic home OR here in Norway, but so far, I'm still learning and I think that sometimes, I try to do things that are way out of my League

    I don't know what I did but it works now

    Thanks for the help, same!

    You are even welcome!

    Have attached the file if anyone wants to see what I did.

Maybe you are looking for