SQL to convert a row with 4 columns, 4 rows by 4 columns

With the help of Frank Kulash yesterday (https://community.oracle.com/thread/3810284)

I can now use UNPIVOT start with this:

with tbl_data AS  
 (select 'N' argument1, 'Y' argument2, NULL argument3, 'Y' argument4 from dual)  
select * from tbl_data;  


ARGUMENT1 ARGUMENT2 ARGUMENT3 ARGUMENT4  
--------- --------- --------- ---------  
N         Y                   Y   

And eventually conversion of a single line of output to 4 rows and 2 columns via:

with tbl_data AS
 (select 'N' argument1, 'Y' argument2, NULL argument3, 'Y' argument4 from dual)
    SELECT  *
    FROM    tbl_data
    UNPIVOT INCLUDE NULLS
            (    col_heading
            FOR  col_name  IN ( argument1
                              , argument2
                              , argument3
                              , argument4
                              )
            );

    COL_NAME  COL_HEADING
    --------- -----------
    ARGUMENT1 N
    ARGUMENT2 Y
    ARGUMENT3
    ARGUMENT4 Y

I was wondering if there are sort of Frank solution can be modified to include the 2 columns (for example, COL_SEQ and COL_PROMPT) with them, hard coded values for example, '1' for the SEQ and 'TEST' for the GUEST, as I have the solution to a Frank's UNION with another query that returns the 4 columns.

i.e. the performance:

COL_NAME  COL_HEADING COL_SEQ     COL_PROMPT
--------- ----------- ----------- -----------
ARGUMENT1 N           1           TEST
ARGUMENT2 Y           1           TEST
ARGUMENT3             1           TEST
ARGUMENT4 Y           1           TEST

Thank you

Hello

969483 wrote:

With the help of Frank Kulash yesterday (https://community.oracle.com/thread/3810284)

I can now use UNPIVOT start with this:

  1. with tbl_data AS
  2. (select "n" argument1, argument2 'Y', NULL argument3, 'Y' double argument4)
  3. Select * from tbl_data;
  4. ARGUMENT1 ARGUMENT2, ARGUMENT3 ARGUMENT4
  5. --------- --------- --------- ---------
  6. N         Y                   Y

And eventually conversion of a single line of output to 4 rows and 2 columns via:

  1. with tbl_data AS
  2. (select "n" argument1, argument2 'Y', NULL argument3, 'Y' double argument4)
  3. SELECT *.
  4. OF tbl_data
  5. MUST INCLUDE NULL VALUES
  6. (col_heading
  7. FOR column-name IN (argument1
  8. argument2
  9. argument3
  10. argument4
  11. )
  12. );
  13. COLUMN COL_HEADING
  14. --------- -----------
  15. ARGUMENT1 N
  16. ARGUMENT2 Y
  17. ARGUMENT3
  18. ARGUMENT4 Y

I was wondering if there are sort of Frank solution can be modified to include the 2 columns (for example, COL_SEQ and COL_PROMPT) with them, hard coded values for example, '1' for the SEQ and 'TEST' for the GUEST, as I have the solution to a Frank's UNION with another query that returns the 4 columns.

i.e. the performance:

  1. COLUMN COL_HEADING COL_SEQ COL_PROMPT
  2. --------- ----------- ----------- -----------
  3. ARGUMENT1 N 1 TEST
  4. ARGUMENT2 Y 1 TEST
  5. ARGUMENT3 1 TEST
  6. ARGUMENT4 Y 1 TEST

Thank you

Of course, you can include constants hardcoded in any set of results; just put constants in the SELECT clause and assign aliases for columns.

Don't forget, I havef you need anything in the more SELECT clause *, then * must be qualified with a table name or alias, so that in this case, you can do something like:

SELECT d. *.

1 AS col_seq

'TEST' AS col_prompt

OF tbl_data

MUST INCLUDE NULL VALUES

(col_heading

FOR column-name IN (argument1

argument2

argument3

argument4

)

d

;

Tags: Database

Similar Questions

  • SQL to convert a row with 4 columns to 4 rows with 1 column

    Sorry, I know this question has been asked hundreds of times before!

    This is my starting SQL:

    set linesize 500
    
    with tbl_data AS
     (select 'N' argument1, 'Y' argument2, NULL argument3, 'Y' argument4 from dual)
    select * from tbl_data;
    
    
    ARGUMENT1 ARGUMENT2 ARGUMENT3 ARGUMENT4
    --------- --------- --------- ---------
    N         Y                   Y        
    

    Is it possible to enter the data in this format:

                    COL_HEADING
    ARGUMENT1       N
    ARGUMENT2       Y
    ARGUMENT3       
    ARGUMENT4       Y
    

    I have read comments UNPIVOT but can't really work on the syntax to get a single line with 4 columns to appear as 4 rows with 1 column.

    Sorry - I realize that I'm probably be lazy and stupid.

    Any advice much appreciated, thank you.

    Hello

    Here's a way to do it with UNPIVOT:

    SELECT *.

    OF tbl_data

    MUST INCLUDE NULL VALUES

    (col_heading

    FOR column-name IN (argument1

    argument2

    argument3

    argument4

    )

    )

    ;

    Output:

    COLUMN COL_HEADING

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

    ARGUMENT1 N

    ARGUMENT2 Y

    ARGUMENT3

    ARGUMENT4 Y

  • Is there a way to convert 8 rows by 2 columns of 2 rows of 8 columns?

    I tried, but came to a stop...

    How can I convert 8 rows by 2 columns of 2 rows of 8 columns?

    as shown in the attached vi

    Thank you very much...

    JohnMc19 wrote:

    Hi Diego2000,

    Tried using the conversion table 2D function found in the functions Array palette, it's what you're asking.

    Kind regards

    No, for the necessary transformation reshaping table is required, not transpose.

    Compare:

    Andrey.

  • Conversion of several lines (with 1 column) to 1 row of concatenated values

    Hi experts,

    We have a table with a column:

    Column1
    A
    B
    C
    D

    and we want to get:

    Column1
    A, B, C, D

    Any help please?

    Thank you!

    Hello

    This is called the aggregation of the chain and this page:
    http://www.Oracle-base.com/articles/10G/StringAggregationTechniques.php
    shows several ways to do so.

    Which way is best for you? It depends on your version of Oracle and exactly to your needs (for example, if the items in the list should be in order or not).
    If you use Oracle 11.2, then new LISTAGG built-in function is probably what you want.

    Published by: Frank Kulash, April 12, 2011 13:01

  • Oracle 11.2 - perform parallel DML on a table that is not partitioned with LOB column

    Hello

    Since I wanted to demonstrate the new enhancements of Oracle 12 c on SECUREFICHIERS, I tried to use PDML declarations on a table that is not partitioned with LOB column, in Oracle 11 g and Oracle 12 c releases. The Oracle 11.2 SECUREFICHIERS and large objects Developer Guide January 2013 said clearly:

    Parallel execution of the following DML operations on tables with LOB columns is supported. These operations performed in parallel run only mode when it is run on a partitioned table. The DML statements on tables not partitioned with LOB columns continue to run in serial execution mode.

    • INSERT SELECT AS
    • CREATE TABLE AS SELECT
    • DELETE
    • UPDATE
    • MERGE (conditionally UPDATE and INSERT)
    • Multi-table INSERT

    So, I created and filled a simple table with a BLOB column:

    SQL> CREATE TABLE T1 (A BLOB);
    Table created.
    

    Then, I tried to see the execution of a parallel ABOLITION plan:

    SQL> EXPLAIN PLAN FOR
      2  delete /*+parallel (t1,8) */ from t1;
    
    Explained.
    

    SQL> select * from table(dbms_xplan.display);
    
    PLAN_TABLE_OUTPUT
    --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    Plan hash value: 3718066193
    
    -------------------------------------------------------------------------------------------------------
    | Id  | Operation             | Name     | Rows  | Cost (%CPU)| Time     |    TQ  |IN-OUT| PQ Distrib |
    -------------------------------------------------------------------------------------------------------
    |   0 | DELETE STATEMENT      |          |  2048 |     2   (0)| 00:00:01 |        |      |            |
    |   1 |  DELETE               | T1       |       |            |          |        |      |            |
    |   2 |   PX COORDINATOR      |          |       |            |          |        |      |            |
    |   3 |    PX SEND QC (RANDOM)| :TQ10000 |  2048 |     2   (0)| 00:00:01 |  Q1,00 | P->S | QC (RAND)  |
    |   4 |     PX BLOCK ITERATOR |          |  2048 |     2   (0)| 00:00:01 |  Q1,00 | PCWC |            |
    |   5 |      TABLE ACCESS FULL| T1       |  2048 |     2   (0)| 00:00:01 |  Q1,00 | PCWP |            |
    
    PLAN_TABLE_OUTPUT
    --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    -------------------------------------------------------------------------------------------------------
    
    Note
    -----
       - dynamic sampling used for this statement (level=2)
    

    And I ended up executing the statement.

    SQL> commit;
    Commit complete.
    
    SQL> alter session enable parallel dml;
    Session altered.
    
    SQL> delete /*+parallel (t1,8) */ from t1;
    2048 rows deleted.
    

    As we can see, the statement was executed in parallel:

    SQL> select * from v$pq_sesstat;
    
    STATISTIC                      LAST_QUERY SESSION_TOTAL
    ------------------------------ ---------- -------------
    Queries Parallelized                    1             1
    DML Parallelized                        0             0
    DDL Parallelized                        0             0
    DFO Trees                               1             1
    Server Threads                          5             0
    Allocation Height                       5             0
    Allocation Width                        1             0
    Local Msgs Sent                        55            55
    Distr Msgs Sent                         0             0
    Local Msgs Recv'd                      55            55
    Distr Msgs Recv'd                       0             0
    
    11 rows selected.
    

    Is this normal? It is not supposed to be supported on Oracle 11 g with no partitioned table containing the LOB column...

    Thank you for your help.

    Michael

    Hello

    The explain plan shows that only the query is run in parallel but not delete it.

    Concerning

    Maurice

  • SQL error: ORA-01779: cannot modify a column that matches a key examine

    Hi all

    The requirement is that I have two tables s_party_d and S_CONTACT_d. the need to update the column name with FST_NAME | ',' | Last_name when column rowid in both tables are equal. I used the query previously below: -.

    Update
    (select
    E1. Name,
    e.FST_NAME,
    Select
    Of
    s_party_d e1,
    E S_CONTACT_d
    where
    E1. Game of ROW_ID = e.ROW_ID)
    name = FST_NAME | ',' | LAST_NAME;

    But I get the error message when executing the query

    Error in the command line: 31 column: 3
    Error report:
    SQL error: ORA-01779: cannot modify a column that is mapped to a table not preserved key
    01779 00000 - 'impossible to change a column that is mapped to a non-preserved table at key'
    * Cause: An attempt was made to insert or update columns in a join finds out who
    map to a table not kept the key.
    * Action: Change the directly underlying base tables.

    Can U please tell me why this error and how to solve?

    Thank you
    Mathon

    Mathon wrote:

    So, I have to look into some other method... I can't achieve this using a single update statement...

    Well, no matter what you do you need to decide what FST_NAME | ',' | Name to use. As I already pointed out for each line of the line of the s_party_d table there are several rows in table S_CONTACT_d. Again, you must yo decide what S_CONTACT_d table row you want to use. For example:

    update s_party_d e1
       set e1.name = (
                      select  max(e.FST_NAME) ||', '|| max(e.LAST_NAME)
                        from  S_CONTACT_d e
                        where e1.ROW_ID=e.ROW_ID
                     )
     where e1.ROW_ID in (
                         select  e.ROW_ID
                           from  S_CONTACT_d e
                        )
    /
    

    SY.

  • ORA-01481 when we click on the report with link column.

    Request Express 3.1.0.00.32

    I have a sql on a form page report with a column that clickable allowing the end user to quickly change the values.
    I seem to have is because there is a mask of format on the column ($1234,56) I get the error
    ORA-01481: invalid number format model
    Unable to fetch row.
    Googling the error came up with "check your manual.

    Under format of date column / number, I'm using the following:
    FML999G999G999G999G990D00
    The column in the database is number (15.2)

    The only value I'm passing is the pk_id which is present in the case of the URL:
    http://...f?p=293:2:3616213833707847::NO::P2_PK_BUDGET_ID:1
    Anyone had this problem and if so found a work around?
    Thank you.

    Leland,

    The error was caused by apply you the mask of YYYY format a number field. I changed a switch of dates for a list of selection and gave you an LOV query that would give you the current year, the last 3 years and the next two years. You can adjust that, according to the needs. I also put the definition LOV to accept other values incase you had a value in the db that was not in the LOV I've defined.

  • Field in the list with 2 columns

    I am creating listfield with two columns as follows [2 |]  Cokes].

    There is an example on how to do this?

    There is an article on the basis of knowledge to developers to add checkbox to a field, but I don't see anything on the creation of several columns.

    Maybe I can get away with adding a field of text instead of a checkbox or have two fields next to the list and sync.

    any suggestions?

    ListField on nature has a great column.

    You can override drawListRow() to ListFieldCallback to divide each row number of columns.

    In this case, you will need to control the width of each column using the class font getAdvance() method that returns the width of the displayed string. And if you combine graphics and text in columns, you will need to also use getWidth() instance method of the Bitmap class to calculate the width of each column.

  • Gears - error when you try to insert values into a table with multiple columns

    Hello

    I started playing with the gears and SQlLite today and I get an error when I try to insert values into a table with multiple columns.

    I have:

    var db = google.gears.factory.create('beta.database');
        db.open('developerSet');
        db.execute('create table if not exists Developers (DeveloperName text, DeveloperAge int)');
    
        var devName = "Davy"
        var devAge = 32;
    
        try {
            db.execute('insert into Developers values (?, ?)', [devName, devAge]);
            alert('success');
        }
        catch (e) {
            alert(e);
        }
    

    I get the error:

    net.rim.device.api.database.DatabaseException; insert into developers values (?,?): SQL logic error or missing database.

    I use this reference: http://code.google.com/apis/gears/api_database.html

    Everything works if I have only one field as:

    var db = google.gears.factory.create('beta.database');
        db.open('developerSet');
        db.execute('create table if not exists Developers (DeveloperName text)');
    
        var devName = "Davy"
        var devAge = 32;
    
        try {
            db.execute('insert into Developers values (?)', [devName]);
            alert('success');
        }
        catch (e) {
            alert(e);
        }
    

    I use the plug-in Visual Studio 2.0 for 2008 that are running Windows XP SP and Simulator 2.13.0.56

    Thank you

    Davy

    Yes, a SQLite database will persist between battery pulls.  The database is registered either to internal MEM or removable media (not the device memory), depending on which is available on your device.

    In general, its not considered a best practice to remove your table as soon as it is empty and re - create it again when you want to add data.  This adds extra overhead fresh for the final, delete and insert first for a given table.  Instead, define and finalize your drawing before you create your table.  Once created, review the static schema.

    That being said, for development purposes, it may be easier to provide an easy way to drop your tables while you develop your schema.

    See you soon,.

    Adam

  • External table with mixed columns

    Hello everyone. We use Oracle 11R1. We have an external table pointing to a CSV with 7 columns inside. The file has always column 7 but the column order differs from time to time. Each column has a header that remains consistent. Is there a way to map the column names to the column header, s so that we did not change the definition of the external table every time a new file is available in?

    Thank you.

    Hello

    As John said, you must assign names of columns when the table is created.  I guess you could have a dynamic SQL solution that reads the header you mentioned, uses this information to write a CREATE table, drop the table, and then recreated with the new order of the columns.

    You may have a view that maps the 7 columns in your table of 7 columns in the view.  Which column gets the mapping to that may depend on the header.

  • Update a table with one column of another

    Oracle 11g
    Hello

    i'im trying to update the two columns of table SUPPORT (SUPPORT_X, SUPPORT_Y) with two columns of table POST_HTA_BT (POSTHTABT_GPS_X, POSTHTABT_GPS_Y)

    Understand that the two tables have the colum below:

    SUPPORT (SUPPORT_ID, SUPPORT_PLAQUE, POSTHTABT_ID, SUPPORT_X, SUPPORT_Y,...)

    POST_HTA_BT (POSTHTABT_ID, POSTHTABT_GPS_X, POSTHTABT_GPS_Y,...)

    The SUPPORT_PLAQUE has type varachar. Except the keys, the other columns are varchar type in both tables.

    The point here is to update the support_x, support_y with posthtabt_gps_x and posthtabt_gps_y.But before the update we have Sheik if the fifth number of the support plate is a number of characters from "0" to "9"and the rest of the caracter of the support_plaque is '00000'

    Please note that the support_plaque is stored in the table with the form: "0025800000!"

    So I did the below script, I try to execute in sql develop.

    SET SERVEROUTPUT ON

    DECLARE
    chiffre_liste varchar (200): = '0 ', '1', '2', '3', '4', ' 5 ', ' 6' ', 7', ' 8 ', ' 9';
    CURSOR CUR_GPS_SUPPORT IS
    Select MEDIA. SUPPORT_X, SUPPORT. SUPPORT_Y, POSTE_HTA_BT. POSTHTABT_ID, SUPPORT. EXPL_ID,
    SUPPORTED. SUPPORT_PLAQUE, POSTHTABT_GPS_X, POSTHTABT_GPS_Y
    support,.
    POSTE_HTA_BT
    where
    SUPPORTED. SUPPORT_X IS NULL and
    SUPPORTED. SUPPORT_Y IS NULL and
    SUPPORTED. POSTHTABT_ID = POSTE_HTA_BT. POSTHTABT_ID and
    SUPPORTED. EXPL_ID = POSTE_HTA_BT. EXPL_ID
    Order of SUPPORT. POSTHTABT_ID;

    w_POSTHTABT_ID POSTE_HTA_BT. Type of POSTHTABT_ID %;
    w_SUPPORT_X SUPPORT. TYPE % SUPPORT_X;
    w_SUPPORT_Y SUPPORT. TYPE % SUPPORT_Y;
    w_EXPL_ID SUPPORT. TYPE % EXPL_ID;
    w_SUPPORT_PLAQUE SUPPORT. TYPE % SUPPORT_PLAQUE;
    w_POSTHTABT_GPS_X POSTE_HTA_BT. TYPE % POSTHTABT_GPS_X;
    w_POSTHTABT_GPS_Y POSTE_HTA_BT. TYPE % POSTHTABT_GPS_Y;

    BEGIN
    DBMS_OUTPUT. Put_line ('loading the coordoonnees GPS - GPS Coord update takes care of starting ');

    FOR HEART LOOPING CUR_GPS_SUPPORT

    w_POSTHTABT_ID: = cur. POSTHTABT_ID;
    w_SUPPORT_PLAQUE: = cur. SUPPORT_PLAQUE;
    w_SUPPORT_X: = cur. SUPPORT_X;
    w_SUPPORT_Y: = cur. SUPPORT_Y;
    w_POSTHTABT_GPS_X: = cur. POSTHTABT_GPS_X;
    w_POSTHTABT_GPS_Y: = cur. POSTHTABT_GPS_X;

    If substr (cur.support_plaque, 5, 1 chiffre_liste) and substr (cur.support_plaque, 6, 5) = '00000'
    w_SUPPORT_X: = CUR. POSTHTABT_GPS_X
    w_SUPPORT_Y: = CUR. POSTHTABT_GPS_Y
    END if;
    EXCEPTION WHEN NO_DATA_FOUND THEN w_SUPPORT_X: = NULL and w_SUPPORT_Y: = NULL;
    END;

    -Updated the table of the supports
    Update SUPPORT
    Set SUPPORT_X = w_SUPPORT_X,
    SUPPORT_Y = w_SUPPORT_Y
    where SUPPORT_PLAQUE = w_SUPPORT_PLAQUE;
    -On valid imm? immediately
    commit;
    EXCEPTION when no_data_found then null;
    -No details found
    END;

    END;
    /

    and I got the following errors:

    Error report:
    ORA-06550: line 2, colum 34:
    PLS-00103: symbol ',' met instead of one of the following symbols:

    * & = - + ; <>/ is mod remains not rem
    <>< Hurst (*) > or! = or ~ = > = < = <>and like2 or
    like4 likec between | submultiset of type multiset Member
    ORA-06550: line 2, column 52:
    PLS-00103: symbol ';' met instead of one of the following symbols:

    ), * & = - + <>/ is mod remains not rem = >
    <>< Hurst (*) > or! = or ~ = > = < = <>and like2 or
    like4 likec between | Member of multiset must
    ORA-06550: line 38, colum 48:
    PLS-00103: symbol 'CHIFFRE_LISTE' met instead of one of the following symbols:

    (
    Symbol "(" a été substitué à "CHIFFRE_LISTE" verser continuer.) "
    ORA-06550: line 39, 12 colum:
    PLS-00103: symbol 'W_SUPPORT_X' met instead of one of the following symbols:

    ), * & -+ / at rem mod < Hurst (*) > rest and or.
    multiset
    ORA-06550: line 40, 12 colum:
    PLS-00103: symbol 'W_SUPPORT_Y' met instead of one of the following symbols:

    . (), * @ % & = - + <>/ is mod remains not rem
    <>< Hurst (*) > or! = or ~ = > = < = <>and like2 or
    like4 likec between | mult
    ORA-06550: line 41, colum 9:
    PLS-00103: symbol 'END' met instead of one of the following symbols:

    . (), * @ % & = - + <>/ is mod remains not rem
    <>< Hurst (*) > or! = or ~ = > = < = <>and like2 or
    like4 likec between | multiset members
    06550 00000 - "line %s, column % s:\n%s".
    * Cause: Usually a PL/SQL compilation error.
    * Action:

    I checked the line number, but do not see the error in my code.

    Please could you help me?

    peace

    Hello

    glad to know that it worked. In fact, I don't see the reason to make these complicated processes.

    Remember the mantra:

    • If you can do it with SQL then do it with SQL

    Good evening!

    Alberto

  • Problem with comparison column multi Nested Tables

    Hello

    I am facing a problem while comparing two collections using operator of type MULTISET. Below I pasted code examples referring to the Employees table in the HR schema.
    program works very well, if it's a single column if I declare that, tab type is table of varchar2 (n);

    Example code:
    --create type base_type as object (id number,name varchar2(10));
    --create type type_tab is table of base_type;
    declare
    v type_tab :=type_tab();
    v2 type_tab :=type_tab();
    v3 type_tab :=type_tab();
    v1 number;
    begin
    select base_type(employee_id,last_name) bulk collect into v from employees where employee_id in (100,101,102);
    select base_type(employee_id,last_name) bulk collect into v2 from employees where employee_id in (100,101);
    
    v3:= v MULTISET EXCEPT v2;
    end;
    Error
    ERROR on line 10:
    ORA-06550: line 10, column 6:
    PLS-00306: wrong number or types of arguments in the call to 'MULTISET_EXCEPT_ALL '.
    ORA-06550: line 10, column 1:
    PL/SQL: Statement ignored

    Could you please address the issue and guide me how to solve this problem.
    Thank you.
    Renji

    Why would you use collections like this in the first place?

    When the data is the engine of SQL, then use the SQL engine to to deal with - not PL/SQL. And no - nested tables have no place in a good, working, flexible, high-performance and scalable relational design in Oracle.

    To do this, use the multiset SQL function - example

    .. your plsql code..
    
      select
        v MULTISET EXCEPT v2 into  v3
      from dual;
    end;
    
  • View with a column that is derived from a function

    We can create a view with a column being filled using a pl/sql script, which uses 2 other columns on the same line as input?

    Example,
    Let's say I have a vision with

    Reg. Don't | Total | Customer account | Flag of billing. CodeFn
    $1234 45 2109 Y < value in this column would be what returns the expected script pl/sql, after using the Reg # (1234) and Total (45) as entries >
    $1236 15 2101 Y < input values would be 1236 & 15 >.

    Basically, I would like the script to generate a number that is returned in this column rather than do a simple Select stmt to extract columns from other tables/views.

    Edit: The point of view does not display right... Here is a picture
    view

    Thank you!

    Published by: jess_saunders on May 8, 2012 14:05

    Hello

    jess_saunders wrote:
    We can create a view with a column being filled using a pl/sql script, which uses 2 other columns on the same line as input?

    Example,
    Let's say I have a vision with

    Reg. Don't | Total | Customer account | Flag of billing. CodeFn
    $1234 45 2109 Y
    $1236 15 2101 Y .

    Of course, you can use a function that you created in the same way that you would use a built-in function:

    CREATE OR REPLACE VIEW     view_x
    AS
    SELECT  reg_no
    ,     total
    ,     customer_account
    ,     billing_flag
    ,     my_function (reg_no, total)     AS codefn
    FROM     table_x
    ;
    

    You cannot reference the procedures or anyonymous blocks in a CREATE VIEW statement (or any other SQL statement of stinks); only functions.

    Basically, I would like the script to generate a number that is returned in this column rather than do a simple Select stmt to extract columns from other tables/views.

    I don't know what you're saying here.
    As long as the function has no arguments, or make any kind of DML or DDL, then you can use it in the definition of the view, as stated above. The function failed to contain SELECT statements.
    Your notice must be based on other tables or views. If she does not really need anything from any other table, you can base your opinion on double. A CREATE VIEW statement must contain a query, and a query in Oracle must refer to a table or a view.

  • Unique table with several columns or several tables split?

    What is the best.

    A table with multiple columns inside or divided into several tables. Why?
    How will the performance in the two scenarios?

    Hello

    user13024762 wrote:
    I have a table EMP that has column EMP_ID, EMP_NAME MGR_ID, MGR_NAME, SALARY, EXP_IN_MNTHS, EXP_IN_YRS... etc with multiple columns

    I have the following tables
    EMP-> EMP_ID, EMP_NAME

    Each row in the table emp thie represents a separate employee. I guess other columns in the emp table might be birth_date, social_security_number and status (by example, 'Active', 'Leave', 'complete'). Here's what an employee has (at least) one of. If there is a one-to-many relationship between an employee and an attribute, then you probably want another table for this attribute.

    BISHOP-> EMP_ID, MGR_ID, MGR_NAME

    There is a one-to-many relationship between employees and managers? In other words, an employee may have 2 or more managers? If Yes, then you need another table.
    If there is only a one-to-one relationship between employees and managers (in other words, if an employee is never more than 1 Manager) so why don't you just have a mgr_id column in the emp table?
    Managers are also used for? (This is often the case, as in scott.emp and hr.employees.) If so, do not store their names in the EME and tables of mgr. Store name (and date of birth and other information) in the table emp only and, if you need a table of Bishop, just the emp_id and mgr_id column.

    SAL-> EMP_ID, SALARY

    There is a one-to-many relationship between the employees and wages? In other words, an employee may have 2 or more treatments? If so, how will you use the values? Is a special treatments in some way, as it will be used more often than others? (In other words, you may have a current and past wages salary, but the last wages are rarely used.)
    If you never have more than 1 salary for a given employee, why not just have a sal column in the emp table?

    EXP-> EMP_ID, EXP_IN_MNTHS, EXP_IN_YRS

    There is a one-to-many relationship between the employees and what whether you store in this table?

    etc. with more tables

    What is the best based on

    (1) performance and data recovery
    (2) ease of use
    (3) maintainability

    A one-to-many relationship requires an additional table. If an employee can have up to 3 managers, don't have mgr1, mgr2 and mgr3 columns in the emp table. Use a separate table, with up to 3 lines for the same employee, instead.
    For 1-1 relationships, it is usually best to not have separate tables.

  • GetLength errors on CLOB. Retrieves the size of a table with CLOB columns

    Hello

    I try to find the size of a CLOB to a table column and get the error

    PLS-00306: wrong number or types of arguments in the call to "GETLENGTH.

    When you try to use dbms_lob.getlength. Here is the code


    declare
    number num.
    Start
    for rec in (select xmlupload from FILE_TABLE where file_table_id = 33635) loop
    NUM: = dbms_lob.getLength (rec.xmlupload);
    end loop;
    dbms_output.put_line (num);
    end;

    Database version: Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi


    I'm actually trying to find the size of a table with CLOB columns, is there an easy way to do this Besides using getlength and without having to contact the Administrators (they are outsourced)?

    It works fine on my computer, the version is also 10g.

    SQL> declare
      2  num number;
      3  begin
      4  for rec in (select cntnt from ims_toms_msge where rownum<3) loop
      5  num := dbms_lob.getLength(rec.cntnt);
      6  dbms_output.put_line(num);
      7  end loop;
      8
      9  end;
     10  /
    3837
    3837
    
    PL/SQL procedure successfully completed.
    

    You should check if xmlupload is the CLOB data type.
    In addition, if you just want to get the CLOB size, you can use LENGTH() as well, you will get the same result;

    SQL>  select length(cntnt), dbms_lob.getLength(cntnt) from ims_toms_msge where rownum<2;
    
    LENGTH(CNTNT) DBMS_LOB.GETLENGTH(CNTNT)
    ------------- -------------------------
             3837                      3837
    

    Published by: PhoenixBai on September 24, 2009 13:40

Maybe you are looking for