How to select individual fields defined in a data type?

Hello

I used SQL in the database, but I'm new to most of the features of Oracle. I was reading the book Oracle SQL * more: definitive guide and came across the following tables defined as stated:

SQL > describe employees

< pre >
Name Null? Type
----------------------------------------- -------- ----------------------------

NUMBER OF EMPLOYE_ID
EMPLOYEE EMPLOYEE_TYPE
< / pre >

The employee field is a structured type named 'EMPLOYEE_TYPE' defined as

< pre >
SQL > describe employee_type

Name Null? Type
----------------------------------------- -------- ----------------------------

EMPLOYEE_NAME VARCHAR2 (40)
DATE OF EMPLOYEE_HIRE_DATE
EMPLOYEE_SALARY NUMBER (9.2)
< / pre >

I wanted to select just the employee_name and tried what is obvious

Select employee.employee_name employees;

also tried

Select employee_type.employee_name employees;

but none worked. I tried every variation I could think of, searched an answer using google, still do not find the answer.

I'd greatly appreciate to have the answer. It is probably simple, but really, it escapes me at the moment.

Thank you very much for your help,

John.

Published by: user2652839 on July 8, 2010 14:38

You must use the function TREAT

SQL> create or replace
  2  type EMPLOYEE_TYPE
  3  as object (EMPLOYEE_NAME VARCHAR2(40),
  4  EMPLOYEE_HIRE_DATE DATE,
  5  EMPLOYEE_SALARY NUMBER(9,2)
  6  );
  7  /

Type created.

SQL> create table employees(EMPLOYEE_ID NUMBER,EMPLOYEE EMPLOYEE_TYPE)
  2  /

Table created.

SQL> insert into employees
  2  select empno,EMPLOYEE_TYPE(ename,hiredate,sal) from emp
  3  /

14 rows created.

SQL> select employee.employee_name from employees;
select employee.employee_name from employees
       *
ERROR at line 1:
ORA-00904: "EMPLOYEE"."EMPLOYEE_NAME": invalid identifier

SQL> select treat(employee as EMPLOYEE_TYPE).employee_name from employees;

TREAT(EMPLOYEEASEMPLOYEE_TYPE).EMPLOYEE_
----------------------------------------
SMITH
ALLEN
WARD
JONES
MARTIN
BLAKE
CLARK
SCOTT

TREAT(EMPLOYEEASEMPLOYEE_TYPE).EMPLOYEE_
----------------------------------------
KING
TURNER
ADAMS
JAMES
FORD
MILLER

14 rows selected.

SQL> 

SY.

Tags: Database

Similar Questions

  • How to count the fields with the bit data type

    Hi friends,
    I'm stuck in this report.
    My responses as it looks.

    region... offices... groups1... work2.
    A..........a1............. 0..........1
    A..........a2............. 1..........1
    A..........a3............. 0..........0
    B..........a1............. 1..........1
    B..........a3............. 0..........0

    Here 0 and 1 are values of bit (true and false)
    I need to create a report that matter works if the value is true (1)
    as...
    Region... total_Work1... total_work2
    A................... 1.............2
    B................... 1.............1

    and
    Offices... Total_work1... Total_work2
    a1............... 1.....................2
    a2............... 1.....................1
    a3.............. 0......................0

    Please help me calculate this total when core values are few.

    Thanks in advance

    Hi Toony,

    This is caused by internal database storage, a true is stored in the form of-1. Just take the integer ABS (absolute).

    concerning
    John
    http://obiee101.blogspot.com/

  • How can I dynamically select the shared Variable API programming data type?

    I am trying to create a configuration of open connections of variable shared using the programming API. It seems to me that the cleanest way to do would be to put one "open and check" routine in a loop, then call it for each variable in the library.

    The question that I am running is that I have different types of data in my library (to help a server Modbus i/o and data types 'boolean' and 'single' in my library.) How can I dynamically select the data type of the shared variable API?

    See the attached snipit.

    Thank you

    What I ended up doing was doing a Subvi to open, read, write, and close each data type, I use the packaged in 4 polymorphic SubVIs (polymorphic Open, read, etc...)

    Now all I have to do I drop in the polymorphic Subvi and it switches automatically to the appropriate data type

  • How the default display is defined when retrieving data with excel.

    Is someone can please tell me how the default display is planned while recovering data using excel add-in I have 7 dimensions, 3 4 dense sparse, whenever I connect to essbase server and retrieve the data is indicated in the top level. Where to set this point of view, we can change it. Sorry if I asked something stupid.

    Thank you.

    Not a silly question at all, but there is nothing you can do about it. The Excel Add-In to this view by default, and there is no way to specify otherwise. You could keep a sheet of 'model' and copy these selections to each recovery again, but it would be a little awkward.

    You will probably get enough fast to type in your favorite settings by default, unless your plan contains difficult to remember or very long names and aliases. :)

  • Where to define new custom data types?

    Hello

    In the past (TS 3.5) I created our own range of custom type file that has been used

    to store the new data types and then referred the case to other colleagues. The file would be

    stored in the ...\Program Files\...\User area.

    My question arose because we now use the TS 4.1/4.2, which is no longer a separate

    Directories of NOR and user in \Program Files.

    Because now I want to change an existing custom data type, I find that our range of custom type has

    fallen by the way side, forgotten.

    Even though I can see the custom data definitions within the sequence of type files that use

    custom data types, which means that I can edit them locally, I intend to return to

    a range of custom type, i.e. comprehensive definition.

    What is the relationship between the definitions in a range of custom type and custom data

    definitions of type of a file of sequence?

    When a palette to update file a file of sequence?, who takes over in the event of conflicts?

    is a really necessary sequence files palette file if they are separated by using the same custom data type

    can update the other? What is good practice when defining custom types of data?

    Thank you

    Gary.

    Hey guys,.

    This is a very interesting thread, and I've got everything right, in heart, with advice given so far. I just wanted to offer some additional tips on the conflicts of kind - with more response, the initial question concerning the definition of what is priority in case of conflict.

    It is important to note that TestStand uses type names and version numbers to identify the different types. It is also important to note that when you use a definition of type of customers within a sequence, the sequence (.seq) file containing the sequence will keep a copy of the type definition. This greatly facilitates distributed sequence files. However, it also opens the door to potential conflicts type.

    TestStand allows only one type of unique name to be loaded into memory at any given time, so that it uses the number of versions of the type to try to resolve these conflicts automatically. For example, TestStand can be configured to load any type is the largest version number (note that this can be changed via the tab Preferences dialog box Options of Station).

    All this information and more are found in the following tutorials...

    Conflicts and TestStand Type Versioning

    How to make a Type of custom step?

    Thanks for your time. I hope this has been helpful!

  • How to insert the value of a LONG data type?

    Hi all

    Developers what to change the type of data in the PRODUCTS table.

    PRODUCT
    ======
    ID number (10) not null,
    NAME varchar2 (50) not null,
    DESCR varchar2 (250) not null


    They want the DESCR to change datataype at LENGTH

    So I got back it up first:

    create the table product_bak in select * from product;
    remove the product;
    change the product table change (descr, null);
    Edit the product table change (long descr);
    Insert into select product * from product_bak;

    ORA - 997 - illegal use of LONG data type


    How can I recover my data?


    Thank you very much.

    Use TO_LOB to convert long on the CLOB type, then use TO_CHAR to convert CLOB VARCHAR2.

  • selection column of the table xml data type

    Hello.
    I tried the following example with xml as column name data type
    create table emp_detail( empno number,ename varchar2(32),empdetails sys.xmltype)
    
    Insert into EMP_DETAIL
       (EMPNO, ENAME, EMPDETAILS)
     Values
       (1, 'satya', XMLTYPE('<NAME>
      <FIRSTNAME>SATYA</FIRSTNAME>
      <LASTNAME>SREE</LASTNAME>
      <LOC>SECBAD</LOC>
    </NAME>
    '));
    Insert into EMP_DETAIL
       (EMPNO, ENAME, EMPDETAILS)
     Values
       (2, 'jo', XMLTYPE('<NAME>
      <FIRSTNAME>JO</FIRSTNAME>
      <LASTNAME>REDDY</LASTNAME>
      <LOC>MYPR</LOC>
    </NAME>
    '));
    So, after that I tried this query to retrieve the State of an attribute data.
    SELECT a.empdetails.extract('//NAME/text()').getStringVal() AS "Table Name"
    FROM   emp_detail a
    WHERE  a.empdetails.existsNode('/NAME')  = 1;
    But those who above indicates no record...
    Why?


    Thank you
    SQL>  SELECT a.empdetails.extract('//NAME/FIRSTNAME/text()').getStringVal() AS "first_name",
      2     a.empdetails.extract('//NAME/LASTNAME/text()').getStringVal() AS "last_name",
      3     a.empdetails.extract('//NAME/LOC/text()').getStringVal() AS "loc"
      4     FROM emp_detail a
      5    WHERE a.empdetails.existsNode('/NAME')  = 1;
    
    first_name           last_name            loc
    -------------------- -------------------- --------------------
    SATYA                SREE                 SECBAD
    JO                   REDDY                MYPR
    
  • How to select metadata fields to display in the list of the metadata Panel?

    Is the any way to select the metadata fields that are displayed in the list in the metadata pane to the right in the library module and the card module?

    You can use The Preset editor of metadata-Viewer plugin to set up your own Viewer presets.  If you are technical interested, you can download the free Lightroom SDK and configure new presets manually using a text editor - it is quite well researched but tedious.

  • How to activate a field read-only for data entry.

    Dear all,

    In fact, I'm bring a form simply queries the table of database data and shows it. It presents the data in readonly textfields.

    There is a button that can create a new line. The problem is when the system is to create the line he is creating the messagefield readoly.

    In order to overcome the situation that I wrote the code below

    mainVO.last () .setAttribute ("IsTextReadable", Boolean.TRUE); To make the last row entrable for the user.

    But the system gives the error when the user is pressing the button create

    Details of the exception.

    oracle.apps.fnd.framework.OAException: oracle.jbo.NoDefException: Houston-25058:

    IsTextReadable of the type definition of that attribute is not found in XxphccamsfdbmstdtlrVO1

    Could you please suggest me how to make the textfield readonly can be changed dynamically.

    Concerning

    Rajat

    Dear Stephanie,

    Thanks for your reply. I solved the problem and it was pretty simple.

    I created a transient in the VO and attached attribute the transitional attribute to the property read-only from the field using SPEL (${oa.) XxamsfdbdtlrVO1.Viewenb}).

    Select the line that you want to update and run it.

    row.setAttribute ("Viewenb", Boolean.TRUE);

    Concerning

    Rajat

  • How to join two fields with slightly different data

    I have two columns, I need joined, both keep the columns of numeric data, but are of type varchar2 (6). The problem is that one of the columns keeps leading zeros to ensure that all 6 characters are used, but not the other. And columns preserve leading zeros may vary how many zeros are in the number-based computing.

    For example, the column with zeros can contain the number 4200, which would mean that he would remain with 2 zeros as 004200. Or it could contain 320, which means that he would remain with 3 zeros as 000320.

    The other column that does not have leading zeros not only keeps the number, so, in the example above, it would keep 4200 and 320 respectively.

    Can someone help on how to join these columns so that they match? I guess I have to delete the zeros in one or add zeros in the other? I tried to use the trunc with zeros on the ground, but it did not work...

    The following sql code:

    M06.mbr06_prv_id has no zeros, prv647.provider_id zeros. See bold below...

    SELECT
    M06.mbr06_prv_id,
    prv647.Site_ID
    Of
    Odw.mbr06_mbr_elig m06
    JOIN THE
    Odw.prv647_prov_exp prv647
    WE
    M06.mbr06_prv_id = prv647.provider_id
    WHERE
    M06.mbr06_subs_id = "999999999 '

    BTW, I have no control on how this data is represented in a table... !

    Hello

    user12296489 wrote:
    ... I guess I have to delete the zeros in one or add zeros in the other?

    Yes, this is how I see.
    LTRIM removes given characters from the beginning of a string. LPAD adds characters at the beginning of a string. I would use LTRIM in this case, because if you use LTRIM, you probably need to handle a single column. If you use LPAD, you have to play with the two columns, as one of them still has the extra 0, and it sometimes needs them.

    I tried to use the trunc with zeros on the ground, but it did not work...

    TRUNC is working on the kinds or DATEs; you have VARCHAR2s. You can convert them to numbers, but then you risk of errors to cause bad data (and it linked to the wrong data).
    >

    The following sql code:

    M06.mbr06_prv_id has no zeros, prv647.provider_id zeros. See bold below...

    SELECT
    M06.mbr06_prv_id,
    prv647.Site_ID
    Of
    Odw.mbr06_mbr_elig m06
    JOIN THE
    Odw.prv647_prov_exp prv647
    WE
    M06.mbr06_prv_id = prv647.provider_id
    WHERE
    M06.mbr06_subs_id = "999999999 '

    If you are certain that m06.mbr06_prv_id never has extra characters, whereas the join condition can be

    ON   m06.mbr06_prv_id   = LTRIM ( prv647.provider_id
                                      , '0'
                           )
    

    If this isn't the case, CUT then the two columns.

    BTW, I have no control on how this data is represented in a table... !

    Report a bad design is for people who don't have not this control. Numbers are the number of columns, not VARCHAR2. If the ID really needs to be strings, they should be validated and standardized once, when they are placed in the table, no more, and more, in all queries that use these columns.

    I hope that answers your question.
    If not, post a small example of data (CREATE TABLE and only relevant columns, INSERT statements) for all tables and also post the results desired from these data.
    Explain, using specific examples, how you get these results from these data.
    Always tell what version of Oracle you are using.

  • How to select the group header with detailed data in a SQL

    Dear Sir

    I wish I had a little help from you. My goal is to create a view where the data should be in the appropriate format. In this format, I want to have for each header of a group.

    I have 3 tables that they ar connected to the other (representing hierarchical data where financial plan breaks in different groups).

    CRM_PLAN
    CRM_PLAN_ID
    DATE
    AMOUNT

    CRM_PLAN_PE
    CRM_PLAN_PE_ID
    TITLE
    AMOUNT
    CRM_PLAN_ID (REF CRM_PLAN key. CRM_PLAN_ID)

    CRM_PLAN_MONTH
    CRM_PLAN_MONTH_ID
    YEAR
    MONTH
    AMOUNT
    CRM_PLAN_PE_ID (foreign key to CRM_PLAN_PE. CRM_PLAN_PE_ID)

    Data looks like:

    CRM_PLAN
    CRM_PLAN_ID | DATE | AMOUNT
    1. 01.01.2012. 500
    2. 01.02.2012 | 200

    CRM_PLAN_PE
    CRM_PLAN_PE_ID | TITLE | AMOUNT | CRM_PLAN_ID
    1. Organization 1. 100. 1
    2. Organization 2. 400. 1
    5: 3 organization | 200 | 2


    CRM_PLAN_MONTH
    CRM_PLAN_MONTH_ID | YEAR | MONTH | AMOUNT | CRM_PLAN_PE_ID
    1. 2012 | 1. 60. 1
    2. 2012 | 2. 40. 1
    5: 2012 | 1. 350. 2
    4. 2012 | 2. 50. 2
    3: 2012 | 1. 200 | 3


    I would like to than the view that returns data as:

    MONTH | AMOUNT
    Organization 1. null
    1. 60
    2. 40
    Organization 2. null
    1. 350
    2. 50
    3 organization | null
    1. 200

    The main question is hot to write a sql as source for display to insert before each group a line with the value of the title of the table CRM_PLAN_PE column. Is it still possible? Perhaps you could suggest another method.

    Notice will be used in the form of oracle where will be possible to change the data - I will make the necessary arrangements by trigger INSTEAD of.

    Kind regards
    Igor

    Published by: user5528050 on 29.11.2012 02:23

    Published by: user5528050 on 29.11.2012 02:24

    Published by: user5528050 on 29.11.2012 02:25

    Hi, Igor,.

    In this case, I think ROLLUP is a little simpeler GROUPING SETS, but you could do it anyway:

    SELECT       CASE
               WHEN  GROUPING (tab2.id) = 0
               THEN  TO_CHAR (tab2.id)
               ELSE  tab1.title
           END               AS col_1
    ,       SUM (tab2.amount)     AS col_2
    FROM       tab1
    JOIN       tab2     ON  tab1.id     = tab2.tab1_id
    GROUP BY  tab1.title
    ,            ROLLUP (tab2.id)
    ORDER BY  tab1.title
    ,         GROUPING (tab2.id)     DESC
    ,            tab2.id
    ;
    

    If tab2.id cannot be NULL, you can use

    NVL ( TO_CHAR (tab2.id)
        , tab1.title
        )
    

    instead of the CASE expression and simplify the ORDER BY clause to

    ORDER BY  tab1.title
    ,            tab2.id            NULLS FIRST          
    
  • Help needed to extract the pipe-delimited fields in a CLOB data type

    Hello

    I had a table with clob field as indicated below.
    CREATE TABLE TRANSACTION_INFO
    (
      TRASACTION_ID  CLOB,
      LOG_ID  NUMBER
    )
    
    Insert into TRANSACTION_INFO
       (TRASACTION_ID, LOG_ID)
     Values
       ('354502002020910|000000610214609663||09/27/09 08:02:37|RNEW|DC25|MOTOROLA|8802939198', 123);
    Insert into TRANSACTION_INFO
       (TRASACTION_ID, LOG_ID)
     Values
       ('354599892020910|000000610214609663||09/27/10 08:12:47|SOLD|DC23||8802939198', 456);
    COMMIT;
    As you can see the field Clob is a pipe delimited data. Now I'm able to extract the first two fields using the below querry. But it may be the right solution as
    SUBSTRING function fails if there is lack of character in all fields.
    Also when there is a null value in all the areas, how can I be able to get as a null value? Basically, I want to get the values in a defined way.

    How can we achieve this?
    Select Substr (TRASACTION_ID, 1, Instr (TRASACTION_ID, '|')-1) field1,
            Substr (TRASACTION_ID, 17, Instr (TRASACTION_ID, '|')+2) field2               
      From TRANSACTION_INFO;
      
    
    output should be like as shown
    
       FIELD1          FIELD2          FEILD3                 FEILD4
      
    354502002020910     000000610214609663                  09/27/09 08:02:37
    354599892020910     000000610214609663                  09/27/10 08:12:47
    Thank you
    Rede
    SQL> with transaction_info (trasaction_id, log_id)
         as (
     select '354502002020910|000000610214609663||09/27/09 08:02:37|RNEW|DC25|MOTOROLA|8802939198', 123 from dual union all
     select '354599892020910|||000000610214609663||09/27/10 08:12:47|SOLD|DC23||8802939198', 456 from dual union all
     select '|000000610214609663||09/27/10 08:12:47|SOLD|DC23||8802939198', 456 from dual
    )
    --
    --
    select trim(regexp_substr (trasaction_id, '[^|]+', 1, 1)) f1,
           trim(regexp_substr (trasaction_id, '[^|]+', 1, 2)) f2,
           trim(regexp_substr (trasaction_id, '[^|]+', 1, 3)) f3,
           trim(regexp_substr (trasaction_id, '[^|]+', 1, 4)) f4,
           trim(regexp_substr (trasaction_id, '[^|]+', 1, 5)) f5
      from (select regexp_replace(replace (trasaction_id, '|', '| '),'^\|', ' |') trasaction_id from transaction_info)
    /
    F1                   F2                   F3                   F4                   F5
    -------------------- -------------------- -------------------- -------------------- --------------------
    354502002020910      000000610214609663                        09/27/09 08:02:37    RNEW
    354599892020910                                                000000610214609663
                         000000610214609663                        09/27/10 08:12:47    SOLD                
    
    3 rows selected.
    
  • How to make a LIKE on a long data type

    I need to search through all the triggers those that contain the string MYSTRING in their own bodies.
    Unlike the table USER_SOURCE procedures and packages where it is possible to run a

    Select distinct name from user_source where upper (text) like '% % MYSTRING ";

    How can I make the same trigger where the body of trigger is a LONG type? I can't run a upper (trigger_body) like '% % MYSTRING "; on USER_TRIGGERS, so how can I do?

    Thank you!

    I have done a few times and generally what I do is create a temporary table by using CREATE TABLE AS... SELECT, and then in the source table. I'll convert the LONG column a CLOB column in the process that you can do your search string on it. Once I'm done, I drop my table.

    I hope this helps!

  • How to display the image of wamp if data type I use is blob?

    Please help me with the problem of wamp if image display is of blob data type. Thank you

    Do not store images in the database. Store the names of image files in the database and place the images in a folder.

  • How to select "Effects &gt; &gt; multiply" setting?

    Dear friend,

    How to select "Effects > > multiply" defined in javascript? I place the screenshot below;

    Eff.png

    Please suggest friends,

    Thanks in advance

    KS

    Try this:

    currLineTxFrm.transparencySettings.blendingSettings.blendMode = BlendMode.MULTIPLY;
    

Maybe you are looking for