Reg: filtering table nested

Hi Experts,

I have a table_week, whose structure is:

create table table_week)

filter_no,

d_mon char (1),

d_tue char (1),

d_wed char (1),

d_thu char (1),

d_fri char (1),

d_sat char (1),

d_sun char (1)

);

"For every FILTER_NO, it stores a 'Y' or ' n ', in the rest of the columns i.e. D_ * D_MON, D_TUE, etc.

Now, I need to fill out another nested table that contains just a few days that were marked as 'Y '.

Let's say, for FILTER_NO = 99, table record looks like: 99 O N O N O N N

Output - A nested table whose value ('Monday', 'Wednesday', 'Friday')

declare

V_1 varchar2 (20);

V_2 varchar2 (20);

V_3 varchar2 (20);

v_4 varchar2 (20);

VARCHAR2 (20) v_5.

v_6 varchar2 (20);

v_7 varchar2 (20);

type nt_type is table of the varchar2 (20);

NT nt_type;

NT1 nt_type: = nt_type();

Start

Select

Decode (d_mon, 'Y', 'Monday', 'x'),

Decode (d_tue, 'Y', 'Tuesday', 'x'),

Decode (d_wed, 'Y', 'Wednesday', 'x'),

Decode (d_thu, 'Y', 'Thursday', 'x'),

Decode (d_fri, 'Y', 'Friday', 'x'),

Decode (d_sat, 'Y', 'Saturday', 'x'),

Decode (d_sun, 'Y', 'Sunday', 'x')

in v_1, v_2, v_3, v_4, v_5, v_6, v_7

of table_week

where filter_no = 99; -/ / Some filter no.

NT: = nt_type (v_1, v_2, v_3, v_4, v_5, v_6, v_7);

because me in 1.nt.count

loop


. . .


end loop;

end;

Thank you and best regards,

-Nordine

(on Oracle 11.2.0.4.0)

SQL> declare
  2
  3    type    nt_type is table of varchar2(20);
  4    my_nt   nt_type;
  5
  6  begin
  7
  8    select day_name
  9    bulk collect into my_nt
 10    from table_week
 11         unpivot (
 12           day_flag for day_name in (
 13                          d_mon as 'Monday'
 14                        , d_tue as 'Tuesday'
 15                        , d_wed as 'Wednesday'
 16                        , d_thu as 'Thursday'
 17                        , d_fri as 'Friday'
 18                        , d_sat as 'Saturday'
 19                        , d_sun as 'Sunday'
 20                        )
 21         )
 22    where filter_no = 99
 23    and day_flag = 'Y';
 24
 25    for i in 1 .. my_nt.count loop
 26      dbms_output.put_line(my_nt(i));
 27    end loop;
 28
 29  end;
 30  /

Monday
Wednesday
Friday

PL/SQL procedure successfully completed.

Tags: Database

Similar Questions

  • Table nested @ schema - level how to extract the first clue?

    Hello

    My version of oracle database: 11g

    I present to you the code here and here are the steps by which I created a table and theres a regular column to the number, but the 2nd column is a nested table.

    (1) create or replace type s_def_NT_DepEmployees is table of the varchar2 (100);

    2)

    create the table employees_NT_test

    (number of department_id

    c_of_s_def_NT_DepEmployees s_def_NT_DepEmployees)

    nested as NTs_c_of_s_def_NT_DepEmployees table c_of_s_def_NT_DepEmployees store

    (3) now, I inserted 2 records:

    insert into employees_NT_test values (1, s_def_NT_DepEmployees ('Rahul', 'Myra'));

    insert into employees_NT_test values (2, s_def_NT_DepEmployees ('Rashi', 'Gaurav'));

    (4) now get me this sql allows employees of department_id: 1

    Select column_value

    table (select c_of_s_def_NT_DepEmployees in the employees_NT_test where department_id = 1);

    Output:

    Rahul

    Myra

    Now my question: I want to just choose the first clue: IE: rahul (and not myra) and it should be compatible such that if I select the two departments I should get my output like:

    Department_id | employees

    1                    | Rahul

    2                    | Rashi

    PS: I am looking for a sql query, I hope I presented my question clearly, if there are doubts please let me know.

    Thanks in advance

    Rahul

    Now my question: I want to just choose the first clue: IE: rahul(and not myra) and should be consistent

    You can only do in a deterministic manner, given the current design.

    Unlike PL/SQL, SQL has no way to access the items in the collection of their indices.

    We can think about using ROWNUM (or ROW_NUMBER) in a subquery, but the SCOREBOARD operator and later join operations do not guarantee that the order will remain the same in the different calls.

    You must redefine the collection 's_def_NT_DepEmployees' as an array of objects, and this object would include an index attribute explicitly on which you can filter.

    The alternative is to create a function that takes the collection and the index for the arguments and returns the element at index - but even in this case I'm not sure that oracle could rebuild deterministically collection either.

    Why use a table nested at all?

  • Record table Nested sorting

    Hello

    Can you help me to sort (based on join date) below table nested using the TABLE function?

    declare
    type is rendered
    (emp_id char (20),
    date of join_d);
    type emp_tbl_type is table of SheikYerbouti;

    non_sorted emp_tbl_type;
    asc_sorted emp_tbl_type;
    Start
    -create sample data

    non_sorted (1) .emp_id: = '1';
    non_sorted (1) .join_d: = sysdate + 5;
    non_sorted (2) .emp_id: = '2';
    non_sorted (2) .join_d: = sysdate + 1;
    non_sorted (3) .emp_id: = '3';
    non_sorted (3) .join_d: = sysdate + 7;
    non_sorted (4) .emp_id: = '4';
    non_sorted (4) .join_d: = sysdate + 7;

    for me in non_sorted.first... loop of non_sorted. Last

    dbms_output.put_line ('Emp ID :'|| non_sorted (i) .emp_id |) ' Date :'|| non_sorted (i) .join_d);
    end loop;

    Select emp_id, join_d
    LOOSE COLLECTION asc_sorted
    table (cast (non_sorted AS emp_tbl_type))
    order of join_d;
    -can you sort these data and move it to asc_sorted

    because me in 1... loop asc_sorted. Count

    dbms_output.put_line ('Emp ID :'|| asc_sorted (i) .emp_id |) ' Date :'|| asc_sorted (i) .join_d);
    end loop;


    end;

    Thank you!

    Thanks I fixed the issue after reading the oracle documentation.

    declare

    non_sorted emp_tbl_type: = emp_tbl_type();
    asc_sorted emp_tbl_type: = emp_tbl_type();

    / * cursor asc_cur is
    Select emp_id, join_d
    table (CAST (non_sorted AS emp_tbl_type))
    order of join_d; */

    Start
    -create sample data
    non_sorted.extend;
    non_sorted (1): = emp_rec('1',sysdate+5);
    non_sorted.extend;
    non_sorted (2): = emp_rec('2',sysdate+1);
    non_sorted.extend;
    non_sorted (3): = emp_rec('3',sysdate+7);
    non_sorted.extend;
    non_sorted (4): = emp_rec('4',sysdate+3);

    for me in non_sorted.first... loop of non_sorted. Last

    dbms_output.put_line ('Emp ID :'|| non_sorted (i) .emp_id |) ' Date :'|| non_sorted (i) .join_d);
    end loop;

    dbms_output.put_line ('* UNSORTED data ');

    Select emp_rec (emp_id, join_d)
    bulk collect into asc_sorted
    table (CAST (non_sorted AS emp_tbl_type))
    order of join_d;

    dbms_output.put_line ('* UNSORTED data ');
    because me in 1... loop asc_sorted. Count

    dbms_output.put_line ('Emp ID :'|| asc_sorted (i) .emp_id |) ' Date :'|| asc_sorted (i) .join_d);
    end loop;

    end;

    THX

  • Bulk collect into a Table nested with Extend

    Hi all
    I want to get all the columns of the table emp and dept. So I use bulk collect into the concept of nested table.

    *) I wrote the function in three different ways. EX: 1 and 2 (DM_NESTTAB_BULKCOLLECT_1 & DM_NESTTAB_BULKCOLLECT_2) does not give the desired result.
    *) It only gives the columns of the EMP table. That means it takes DEPT & columns of the EMP table, but it only gives columns of table EMP.
    ) I think, there is something problem with nested table Extend.
    ) I want to know infested.
    Can we use bulk collect into a table nested with extend?
    If it is yes then fix the below codes (EX: 1 & EX: 2) and can you explain me please?


    Codes are given below *.

    CREATE OR REPLACE TYPE NEST_TAB IS TABLE OF THE VARCHAR2 (1000);

    EX: 1:
    ----
    -Bulk collect into a Table nested with Extend-
    CREATE or replace FUNCTION DM_NESTTAB_BULKCOLLECT_1
    RETURN NEST_TAB
    AS
    l_nesttab NEST_TAB: = NEST_TAB();
    BEGIN
    FOR tab_rec IN (SELECT table_name
    From user_tables
    WHERE table_name IN ('EMP', 'Department')) LOOP
    l_nesttab.extend;

    SELECT column_name
    bulk collect INTO l_nesttab
    Of user_tab_columns
    WHERE table_name = tab_rec.table_name
    ORDER BY column_id;
    END LOOP;

    RETURN l_nesttab;
    EXCEPTION
    WHILE OTHERS THEN
    LIFT;
    END DM_NESTTAB_BULKCOLLECT_1;

    SELECT *.
    TABLE (DM_NESTTAB_BULKCOLLECT_1);

    OUTPUT:
    -------
    EMPNO
    ENAME
    JOB
    MGR
    HIREDATE
    SAL
    COMM
    DEPTNO

    * Only the EMP table columns are there in the nested table.
    -----------------------------------------------------------------------------------------------------

    EX: 2:
    -----
    -Bulk collect in the nested with Extend based on County - Table
    CREATE or replace FUNCTION DM_NESTTAB_BULKCOLLECT_2
    RETURN NEST_TAB
    AS
    l_nesttab NEST_TAB: = NEST_TAB();
    v_col_cnt NUMBER;
    BEGIN
    FOR tab_rec IN (SELECT table_name
    From user_tables
    WHERE table_name IN ('EMP', 'Department')) LOOP
    SELECT MAX (column_id)
    IN v_col_cnt
    Of user_tab_columns
    WHERE table_name = tab_rec.table_name;

    l_nesttab. Extend (v_col_cnt);

    SELECT column_name
    bulk collect INTO l_nesttab
    Of user_tab_columns
    WHERE table_name = tab_rec.table_name
    ORDER BY column_id;
    END LOOP;

    RETURN l_nesttab;
    EXCEPTION
    WHILE OTHERS THEN
    LIFT;
    END DM_NESTTAB_BULKCOLLECT_2;

    SELECT *.
    TABLE (DM_NESTTAB_BULKCOLLECT_2);

    OUTPUT:
    -------
    EMPNO
    ENAME
    JOB
    MGR
    HIREDATE
    SAL
    COMM
    DEPTNO

    * Only the EMP table columns are there in the nested table.
    -------------------------------------------------------------------------------------------

    EX: 3:
    -----

    -Collect in bulk in a nested Table to expand aid for loop.
    CREATE or replace FUNCTION DM_NESTTAB_BULKCOLLECT_3
    RETURN NEST_TAB
    AS
    l_nesttab NEST_TAB: = NEST_TAB();
    TYPE local_nest_tab
    THE VARCHAR2 ARRAY (1000);
    l_localnesttab LOCAL_NEST_TAB: = LOCAL_NEST_TAB();
    NUMBER x: = 1;
    BEGIN
    FOR tab_rec IN (SELECT table_name
    From user_tables
    WHERE table_name IN ('EMP', 'Department')) LOOP
    SELECT column_name
    bulk collect INTO l_localnesttab
    Of user_tab_columns
    WHERE table_name = tab_rec.table_name
    ORDER BY column_id;

    BECAUSE me IN 1.l_localnesttab. COUNTING LOOP
    l_nesttab.extend;

    L_NESTTAB (x): = L_LOCALNESTTAB (i);

    x: = x + 1;
    END LOOP;
    END LOOP;

    RETURN l_nesttab;
    EXCEPTION
    WHILE OTHERS THEN
    LIFT;
    END DM_NESTTAB_BULKCOLLECT_3;

    SELECT *.
    TABLE (DM_NESTTAB_BULKCOLLECT_3);

    OUTPUT:
    ------
    DEPTNO
    DNAME
    LOC
    EMPNO
    ENAME
    JOB
    MGR
    HIREDATE
    SAL
    COMM
    DEPTNO

    * Now, I got the desired result set. DEP. and columns of the Emp Table are in the nested Table.




    Thank you
    Ann

    COLLECTION BULK cannot add values to an existing collection. It can only crush.

  • help join you a table nested with ordinary table

    IM creating a nested table object prtcnpt_info codelist. In a block anonymous im saying t_code as type nested table codelist.
    Now when I try to join the table nested to ordinary table oracle DB and I get the error: PL/SQL: ORA-00904: "COLUMN_VALUE": invalid identifier.
    Please help me on this and provide link tutorial about this concepts... Here is the code I wrote

    -Start code.
    create or replace type prtcnpt_info as an object (identification number
    , name varchar2 (200)
    (, code varchar2 (30));


    create type codelist is the prtcnpt_info table;


    declare
    t_code codelist.
    Start

    Select prtcnpt_info (b.pid, b.name, pt.code) in bulk collect into t_code
    party pt
    mc_code b
    where pt.cd in ("AAA", "BBB")
    and pt.ptype_id = b.pt_type_id;


    INSERT INTO table (ID
    RUN_ID
    DATA
    P_ID
    )
    SELECT id
    run_id
    data
    prtct.id-> 1
    IN table_2 t2
    , (by selecting column_value in table (t_code)) prtct
    WHERE prtct.id = t2. P_ID; -> 2

    end;

    -End code;
    also of the anonymous block
    1 = > is this right until you get the id value (b.pid) of the tablet_code nested as prtct alias?
    2 = > is this right until you reach the nested with ordinary table table? I want to join the id column in the tables.

    Published by: 914912 on April 30, 2012 02:11

    Write the insert like this and try

    insert into table
    (
           id
         , run_id
         , data
         , p_id
    )
     select id,
         run_id,
         data,
         prtct.id
       from table_2 t2
         table(t_code) prtct
      where prtct.id = t2.p_id;
    
  • Assistance in creation of objects Table nested in a column

    Hi all

    In our project requirement, we are supposed to create a table1 consisting of such object1 of the column and Object1 has a nested object (object2) as one of the column.

    We are able to create the table (table-name is op_sam) for object1

    create or replace type testobj1 as an object (number of c1, c2 number);
    create or replace type t_testobj in the testobj1 table;

    create table op_sam (obj_id varchar2 (100), workobj t_testobj)
    store workobj table nested as nested_tab back as a value;

    We strive to store op_sam as an object in an another table prepop

    We have created the object for the op_sam

    create or replace type op_sam_obj as an object (obj_id varchar2 (100), workobj t_testobj);
    create or replace type t_op_sam_obj in the op_sam_obj table;



    We gave the following script to create the table with the column as t_op_sam_obj

    create table prepop (ob_id varchar2 (20), t_op_sam_obj object2)
    nested table object2 store like nested_tab1 back as a value;


    ORA-22913: must specify the name of the table for the nested table column or attribute · nested tables ·

    could you please suggest me to fix this?

    Hello

    Each object of type table needs a nested table.
    Subject: object2 has a nested table object: workobj
    Then, who also has a nested table clause.

    CREATE
         TABLE prepop
         (
              ob_id VARCHAR2(20)
         , object2 t_op_sam_obj
         )
         nested TABLE object2 store AS nested_tab1
         (
              nested TABLE workobj store AS nested_tab2
         )
            return as value
    ;
    

    This will create 3 tables:
    nested_tab2 as an embedded table
    nested_tab1 as an embedded table
    prepop

    Kind regards

    Peter

  • EDM campaign... tables nested?

    Hello wonderful people.

    Wondering if anyone could help me with this little doozy...

    one of my clients wants to do an EDM for them. I did like they ask (they wanted as jpg)
    and their it staff have rewritten for me as follows:

    "Most browsers are able to solve problems with these bays, but e-mail clients cope so well." To remedy this, it may be preferable to use tables nested, instead of spanning columns and different lines. for example. "make every line contains a single < td > element and when several are required and then creating a new nested table.

    Here is a screenshot of how it will look like. Is this good? I would have thought the hotspots on the web address, Twitter and Facebook logos could have sufficed.

    Picture 13.png

    The nested tables the way forward for such things?

    Cheers!

    Michael

    Hi Michael, yes you are right the nested tables are the way to go if she'll send using e-mail clients.

    There are a few things to take note however:

    • Use hotspots with care, gmail can not detect hot spots that mean the redirect url does not work... Yahoo, hotmail, and outlook work very well
    • When the code using nested table there is a few rules to follow, such as use inline css, nested tables, no divs, no background image ( is fine but not the background css and html selector)
    • So in your design, I can see the baby with the background images and text... propably will not work unless u export all in one picture.
    • It is important to note images will leave a white space between the two for hotmail user, so be sure to add to the css

    style = "" display: block; "." You can google for more info...

    • An other things is that you need to know how your customers send email Ferragamo, as the use of this software?... for outlook 2003 is more stable, outlook 2007 and especially will probably screw up your layout. If your client uses the third-party e-mail provider then it should be fine...

    and the list continues... I know html email is annoying

  • I can't move a table nested in CS4

    I use Dreamweaver CS4 and I'm trying to move a table nested, either by dragging or by using the arrows, but it does not move. It's very frustrating... Please help...? !

    Thanks in advance!

    Add the following links to your Favorites. You will refer to them often.

    HTML

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

    http://w3schools.com/html/default.asp

    http://www.HtmlDog.com/guides/

    http://www.htmlcodetutorial.com/

    http://alistapart.com/topics/code/

    CSS

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

    http://w3schools.com/CSS/default.asp

    http://www.Projectseven.com/Tutorials/index.htm

    http://www.westciv.com/

    http://www.TJKDesign.com/articles/one_html_markup_many_css_layouts.asp

    Web Design / Dreamweaver

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

    Community standards Web MX Lesson Plan series
    http://www.communitymx.com/abstract.cfm?cid=3D074

    Tables to CSS Web Design part 1-
    http://www.Adobe.com/devnet/Dreamweaver/articles/table_to_css_pt1.html

    Tables to CSS Web Design part 2-
    http://www.Adobe.com/devnet/Dreamweaver/articles/table_to_css_pt2.html

    Holding a model of fireworks to a CSS-based layout in DW
    http://www.Adobe.com/devnet/Fireworks/articles/web_standards_layouts_pt1.html

    Divisions of absolute positioning or DW 'Layers '.
    http://apptools.com/examples/pagelayout101.php http://apptools.com/examples/pagelayout101.php

    Nancy O.
    ALT-Web Design & Publishing
    Web | Graphics | Print | Media specialists
    www.Alt-Web.com/
    www.Twitter.com/ALTWEB
    www.Alt-Web.com/blogspot.com

  • Helps the createRow() in a filtered Table

    Hello, I have a page with top and Center jspx. At the top of my page, I have selectOneChoice with my master table primary keys.
    At the Center, I have a detail table of adf.
    By changing the value of selectonechoice, I use this selectonechoice value to filter the contents of my table adf with the following code:
        public void teste(ValueChangeEvent valueChangeEvent) {
            BindingContext ctx1 = BindingContext.getCurrent();
            
            DCDataControl dc =
                ctx1.findDataControl("AppModuleSGPUDataControl");
            
            ApplicationModule service = (ApplicationModule)dc.getDataProvider();
            
            ApplicationModule am =
                service.findApplicationModule("AppModuleSGPU");
      
            ViewObject vo = am.findViewObject("TTpNivelIcpEnViewUp1");
            
            vo.setWhereClause("TTpNivelIcpEn.CODIGO_TB_PARAMETRO = '" +
                               valueChangeEvent.getNewValue() + "'");
            vo.executeQuery();      
         }
    So far so good, now I have also just below this table, a button to insert a line in this table with the following measures:
        public String cilNovoIcp_action() {
              BindingContext ctx1 = BindingContext.getCurrent();
              
              DCDataControl dc =
                   ctx1.findDataControl("AppModuleSGPUDataControl");
              
              ApplicationModule service = (ApplicationModule)dc.getDataProvider();
              
              ApplicationModule am =
                   service.findApplicationModule("AppModuleSGPU");
              
              ViewObject vo = am.findViewObject("TTpNivelIcpEnViewUp1");
              
              vo.createRow().setAttribute("CodigoTbParametro", "1");
         }
    But this only works when there is no filter to the table, does anyone know how to create a line in the filtered tables?

    My version of JDeveloper is 11.1.1.3.0.

    Hello

    VR;

    BindingContext bctx = BindingContext.getCurrentInstance ();
    BindingContainer links = bctx.getCurrentBindingEntry () (BindingContainer)
    DCIteratorBinding dcIterator = (DCIteratorBinding) bindings.get("IteratorBindingName");
    Line rw = dcIteratorBinding.getRowSetIterator () .createRow ();
    rw.setNewRowState (Row.STATUS_INITIALIZED);
    Insert a row of the iterator
    dcIteratorBinding.getRowSetIterator () .insertRow (rw).
    make new line current
    dcIteratorBinding.setCurrentRowWithKey (rw.getKey () .toStringFormat (true));

    Frank

  • On the Table nested

    Hi all

    Why the following SQLs are unable to work? He told me that:

    ERROR on line 1:
    ORA-02320: failure in the creation of the table of storage for the nested table column
    ACCESS_G
    ORA-22913: must specify the name of the table for the nested table column or attribute

    SQL:

    CREATE or REPLACE TYPE el_type () AS OBJECT
    ip_address VARCHAR2 (16));
    /

    CREATE or REPLACE TYPE el_tab_type AS TABLE OF THE el_type;
    /

    CREATE or REPLACE TYPE re_type () AS OBJECT
    re_name VARCHAR2 (16).
    el_g el_tab_type);
    /

    CREATE or REPLACE TYPE re_tab_type AS TABLE OF THE re_type;
    /

    CREATE TABLE actual_info)
    profile_name VARCHAR2 (16).
    access_g re_tab_type)
    TABLESPACE DBdata
    NESTED TABLE access_g STORE AS access_tab;
    /

    You have a table nested within a nested table, so you must specify the storage
    for both tables nested.
    Tom tells how do:
    http://asktom.Oracle.com/pls/asktom/f?p=100:11:0:P11_QUESTION_ID:2969385152046

    URS

  • Nested table and tables nested inside (CREATE TABLE)

    Hi all

    I have a problem of creation of a table with some types defined by the user at several levels (and therefore the nested tables).

    All first of all objects:
    type top_object is object (
        text_top varchar2(100),
        table_a a_object_tbl,
        table_b b_object_tbl
    );
    
    type a_object_tbl is table of a_object;
    type a_object is object (
      text_a varchar2(100)
    );
    
    type b_object_tbl is table of b_object;
    type b_object is object (
      text_b varchar2(100),
      table_c c_object_tbl,
      table_d d_object_tbl
    );
    
    type c_object_tbl is table of c_object;
    type c_object is object (
      text_c varchar2(100)
    );
    
    type d_object_tbl is table of d_object;
    type d_object is object (
      text_d varchar2(100)
    );
    Shortly: the SUPERIOR object contains tables A and B. B includes tables C and D.


    Well, now I want to create a table that contains the TOP level object.
    My attempt:
    create table multilevel_table (
      some_value varchar2(100),
      data top_object
    )
    NESTED TABLE top_object.table_a STORE AS data1,
    NESTED TABLE top_object.table_b STORE AS data2
    (NESTED TABLE table_c STORE AS data3,
    NESTED TABLE table_c STORE AS data4);
    Of course, this does not (otherwise I would not have asked you ;)). If I jump the 'second level', so just deleting table_b top_object and, therefore, the "inner nested table' it works.
    But on this scenario more complex I don't know the right way or the syntax.

    I would be grateful if I get any help or suggestion on your part!

    + 1 for recommendation of Hoek of simply not using TABLEs IMBRIQUEES for persistent structures.

    But:

    create table multilevel_table (
      some_value varchar2(100),
      data top_object
    )
    NESTED TABLE data.table_a STORE AS data1,
    NESTED TABLE data.table_b STORE AS data2
    (NESTED TABLE table_c STORE AS data3,
     NESTED TABLE table_d STORE AS data4) ;
    
  • Filtering table using Multi Select choice

    Hello gurus,

    I want to filter a table column that is inspired by LOV using list Multi choice to select the filter option.

    Can I filter the table by using the only choice by following below tutorial in the ADF Code corner:

    016 how to customize the filter ADF Faces Table

    Someone can provide any link or guide to implement Multi Select choice filtering list in the tables.


    Thank you
    Buxant

    Hello

    will tomorrow publish sample 98 ADF Code corner: http://www.oracle.com/technetwork/developer-tools/adf/learnmore/index-101235.html#CodeCornerSamples

    Frank

  • How to create a foreign key constraint on a table nested column

    Dear Experts,
    I create 2 tables using the object type. the VESSEL_PARAM table contains the list of the parameters allowed.
    The table VESSEL_TYPE containe single item we list some parameters.

    On this table, I love the column VESSEL_PARAM table VESSEL_PARAM to check if the settings are and the reference value is allowed.
    How to create a foreign key?
    Here my script that generates this runtime error: 00904. 00000 - '% s: invalid identifier' on this line

    ALTER TABLE VESSEL_PARAM_TAB ADD CONSTRAINT FK_VESSEL_TYPE FOREIGN KEY (NAME, DATA_VALUE)
    REFERENCES VESSEL_PARAM (PARAM_NAME, LIST_PARAM_VALUE. DATA_VALUE)
    CREATE OR REPLACE TYPE OBJ_PARAM_VALUE AS OBJECT 
    ( 
      DATA_VALUE  VARCHAR2(20)
     ,DESCRIPTION VARCHAR2(125)
    ) NOT FINAL;
    /
    
    CREATE OR REPLACE TYPE LIST_PARAM_VALUE AS TABLE OF OBJ_PARAM_VALUE;
    /
    
    -- derive object subtype from object supertype
    CREATE OR REPLACE TYPE OBJ_PARAM_NAME UNDER OBJ_PARAM_VALUE (
      NAME VARCHAR2(30)
    )NOT FINAL;
    /
    
    CREATE OR REPLACE TYPE LIST_PARAM_NAME AS TABLE OF OBJ_PARAM_NAME;
    /
    
    Prompt create table VESSEL_PARAM;
    CREATE TABLE VESSEL_PARAM (
       PARAM_NAME   VARCHAR2(20) NOT NULL
      ,PARAM_DESC   VARCHAR2(125)
      ,PARAM_VALUE  LIST_PARAM_VALUE
      ,CONSTRAINT PK_VESSEL_PARAM PRIMARY KEY (PARAM_NAME)
    ) 
    NESTED TABLE PARAM_VALUE STORE AS PARAM_VALUE_TAB
    TABLESPACE CMS_ADMDATA;
    /
    ALTER TABLE PARAM_VALUE_TAB ADD CONSTRAINT UN_PARAM_VALUE_TAB UNIQUE (DATA_VALUE);
    /
    SHOW ERROR;
    
    Prompt create table CMS_ADM.VESSEL_TYPE;
    CREATE TABLE CMS_ADM.VESSEL_TYPE (
      VESSEL_TYPE  VARCHAR2(20) NOT NULL
     ,VESSEL_DESC  VARCHAR2(125)
     ,VESSEL_PARAM LIST_PARAM_NAME
     ,CONSTRAINT PK_VESSEL_TYPE PRIMARY KEY (VESSEL_TYPE)
    -- ,CONSTRAINT FK_VESSEL_TYPE FOREIGN KEY (VESSEL_PARAM) 
    --        REFERENCES VESSEL_PARAM (PARAM_NAME)
    ) 
    NESTED TABLE VESSEL_PARAM STORE AS VESSEL_PARAM_TAB
    TABLESPACE CMS_ADMDATA;
    /
    ALTER TABLE VESSEL_PARAM_TAB ADD CONSTRAINT UN_VESSEL_PARAM_TAB UNIQUE (NAME);
    ALTER TABLE VESSEL_PARAM_TAB ADD CONSTRAINT FK_VESSEL_TYPE FOREIGN KEY (NAME,DATA_VALUE) 
            REFERENCES VESSEL_PARAM (PARAM_NAME,LIST_PARAM_VALUE.DATA_VALUE)
    /
    SHOW ERROR;
    Thank you

    Salvatore

    Could you please indicate your answer as correct if you judge them correct.

    Best regards

    Mohamed Houri

  • How to reference a column internal table nested - without a name?

    Hi guys, I have a question about nested tables - Ive searched around and cannot find an answer.

    Here is my sample code:
    CREATE OR REPLACE TYPE scotttype AS table of number;
    
    create table scott1 (col_a varchar2(10), col_b scotttype) nested table col_b store as col_b
    
    insert into scott1 values ('onetwo',scotttype(1,2))
    
    insert into scott1 values ('threefour',scotttype(3,4))
    
    select t1.col_a, column_value col_b
    from scott1 t1, TABLE(t1.col_b) t2
    
    insert into table(select s.col_b FROM scott1 s WHERE s.col_a = 'onetwo')
    values (5);
    OK, so that sounds great.

    If I want to do an update or delete however, how can I make reference to col_b that the nested table doesn't have a column name?
    That is to say:

    update table(select col_b from scott1 where col_a = 'onetwo') col_b
    set col_b.XXXXX = 6
    where col_b.XXXXX = 5
    will then not work what should I put instead of the XXXXX?


    I'm sure its simple but I can't!

    Thank you all
    SQL> select t1.col_a, column_value col_b
      2  from scott1 t1, TABLE(t1.col_b) t2;
    
    COL_A           COL_B
    ---------- ----------
    onetwo              1
    onetwo              2
    threefour           3
    threefour           4
    onetwo              5
    
    SQL> commit;
    
    Commit complete.
    
    SQL> update table(select col_b c1 from scott1 where col_a = 'onetwo') t1
      2  set column_value = 6
      3  where column_value= 5;
    
    1 row updated.
    
    SQL> commit;
    
    Commit complete.
    
    SQL>  select t1.col_a, column_value col_b
      2   from scott1 t1, TABLE(t1.col_b) t2;
    
    COL_A           COL_B
    ---------- ----------
    onetwo              1
    onetwo              2
    threefour           3
    threefour           4
    onetwo              6
    
    SQL> 
    
  • SQL Developer 2.1 (filtered) tables

    Just downloaded SQL Developer 2.1 and try to use it. Have been using SQL Developer 1.2. Looks like a major difference - the most immediate is the tables (filtered) to jump on me. I looked at http://www.oracle.com/technology/products/database/sql_developer/files/NewFeatureList21.htm and nothing comes to mind of what he meant.

    So, that means Tables (filtered) mean? That means the green round thing on the procedures and functions mean?

    Can someone point me to documentation / white paper any?

    Thank you

    -andy-

    Right-click on the node and you will see "apply the filter...". ». Inside of this dialog box, you get a 'Help' button which leads you directly to the help topic.
    As the Green thing, it is probably a bug in the Green Lady, which means that you have this code compiled for debugging.

    Have fun
    K.

Maybe you are looking for