Delete temporary tables

Hi all, we are working with an Oracle schema as a staging area. Basically, what we want, is to store all the intermediate transformations in temporary tables (stored in this area of transit of Oracle). These temporary tables are used as source data warehouses in other interfaces

Our question is about the deletion of the tables. Once in an Oracle DB, we have kept the final data, we want that these temporary tables should be deleted. Do we have to do it via a sql command to remove embedded in an ODI procedure?
We thought that as they were temporary, they could be automatically removed when the package is run.

We assume that if we use the Sunopsis Memory engine and we have the application below, the temporary tables will be deleted when the package ends:

The Test package
Interface 1: make some joins and filters and stores the data in TEMP_1
Interface 2: make some joins and filters using TEMP_1 and stores the data in TEMP_2
Interface 3: do some joins and filters using TEMP_2 and stores the final data in TABLE a.

Option: using Oracle physical schema as transit area
Option b: using the Sunopsis Memory engine as transit area

To conclude, and should be deleted TEMP_1 TEMP_2, if we use Option A?

Another thing, that are the main factors to decide whether to use the Sunopsis Memory or Oracle DB table (for example) engine as transit zone?

Thanks in advance to NSI

Hi-

Rest area can be decided depending on where you load the data. In your scenario, the final data should be loaded into Oracle DB, the staging area should be A option.

Add the drop table statement to remove TEMP_1 and TEMP_2 tables in your approach to Interface3 KM.

Hope it will be useful to you.

Thank you
Silou René-coral

Tags: Business Intelligence

Similar Questions

  • using temporary Tables

    Hello

    I use a temporary table in my procedure to insert and select data. I used ON COMMIT PRESERVE ROWS option.but given in my temporary table are not deleted, even though I explicitly have a close connection to my ASP.NET page. So from now on I use delete (temporary table) to remove the data and insert the new set of records.
    I would like to know why this phenomenon occurs

    Kind regards

    Hello

    ODP.NET uses the default connection pool, so the connection is not actually closed when you call close/features in your application. This is a limitation of the layer OIC you cannot restore an existing connetion to the State 'blank '... That is to say, the packaging, temporary tables, etc.

    Unfortunately, this makes temporary tables a bit difficult to work with. You can either
    (1) use a transaction in your code odp.net rather than ON COMMIT PRESERVE ROWS to keep the data available until you're done with it, or
    (2) disable connection pool by setting Pooling = false in your connection string, or
    (3) explicitly clear the table do you.

    See you soon,.
    Greg

  • How to create a unique temporary table delete automatically after the join?

    I have a lot of users simultaneously accessing web applications.
    My problem is how to fix the SELECT WHERE IN('..') clause ...

    I read a lot of threads with the same option...

    (1) open the connection and start transaction
    2) create temporary table
    (3) Insert (insert batch) data
    (4) the main objective. SELECT JOIN or SELECT WHERE IN (SUBQUERY).
    (5) end of transaction and close the connection

    How can I ensure that the temporary table created was deleting/moving on 5)?

    Thank you very much..

    You can do this by using global temporary tables. Also data from the temporary table is automatically deleted after that validation but the table will remain.

    for example

    CREATE TEMPORARY TABLE global today_sales
    ON COMMIT DELETE ROWS
    AS SELECT * FROM Orders WHERE order_date = SYSDATE;

    http://download.Oracle.com/docs/CD/B19306_01/server.102/b14231/tables.htm#i1006400

    http://download.Oracle.com/docs/CD/B19306_01/server.102/b14200/statements_7002.htm#i2153132

    http://download.Oracle.com/docs/CD/B19306_01/server.102/b14200/statements_7002.htm#i2153132

    Concerning
    Rajesh

    Published by: Rajesh on June 10, 2010 15:34

  • How to use SQLite temporary tables?

    As read here: http://docs.blackberry.com/en/developers/deliverables/8682/BP_Optimizing_SQLite_database_performance...

    Use temporary tables. Do this only if you do not need data to be available following a reset of the BlackBerry device.

    Read here: http://www.sqlite.org/tempfiles.html

    Tables created using the syntax "CREATE THE TEMP TABLE" is visible only to the connection of database in which the "CREATE TEMP TABLE" statement is initially evaluated.

    The confusing part is that if I create an instance of database for temporary tables with a single statement of DatabaseFactory.open, I am only able to use this same instance of database throughout my entire application?

    So, using the same variable throughout the entire application?

    It also means that I can not close the database connection?

    Here is information on temporary tables of SQLite:

    http://www.SQLite.org/tempfiles.html#tempdb

    (1) you must call 'CREATE TABLE TEMP' every time when you open a database if you need this chart.

    (2) temporary table deleted as soon as you close the database. This means you need to keep the database connection open if you want to run previously inserted/updates of records into a temporary table.

    Thank you

    Eugen

  • Are global temporary tables, a standard feature of Oracle?

    I apologize for introducing me to this community with what must seem like a very stupid question...

    I am a software developer, working on a product that uses Oracle as its database, specifically Oracle 11 g Enterprise Edition. Recently, I solved a problem of performance by converting an ordinary table into a global temporary table. Before my boss allows me to put this change in the product, it wants to be sure that global temporary tables are a standard part of Oracle, not something that the customer must install separately or pay extra for. (This is the first time that we never used them in our product, so I think that most of the team are not familiar with them).

    I know that Oracle has had global temporary tables since the last millennium, so if ever, they have been a feature of the premium, they are unlikely to be now, but the boss wants me to get independent confirmation of this.

    Thank you.

    Steve Pemberton

    Here you can see "feature availability by Edition":

    http://docs.Oracle.com/CD/E11882_01/license.112/e47877/editions.htm#DBLIC116

    TWG tables is not even mentioned, which means that they do not belong to the functional components are paid separately.

    One caveat - if you have an application that uses connection pooling, it is recommended to use ON COMMIT DELETE ROWS, not ON COMMIT PRESERVE ROWS

    (or always use explicitly "DELETE gtt_table" at the beginning), because otherwise a user of the application can display the data TWG who has previously made a second user of the application.

    Kind regards

    Zlatko

  • PLS-00357 on a global temporary table

    Oracle 11g R2

    I am using a dynamic SQL statement to delete rows. The WHERE THERE EXIST uses a global temporary table and it gives me

    PLS-00357: Table, view or reference sequence "TMPPRE_ARC" not allowed in this context

    Any ideas of a work around?

    create global temporary table tmppre_arc
      ( id number)
      ON COMMIT PRESERVE ROWS;
    
    
    CREATE OR REPLACE PROCEDURE test_del
    IS
       v_owner_tbl varchar2(61) := 'test_table'     ;
    BEGIN   /* DELETE_SOURCE */
            EXECUTE IMMEDIATE
                'DELETE FROM ' || v_owner_tbl || ' v ' || chr(10) ||
                'WHERE EXISTS ( SELECT    null '       || chr(10) ||
                'FROM      ' || tmppre_arc || ' r '  || chr(10) ||
                'WHERE       r.id     = v.id )' ;
    END test_del;
    /
    show errors
    
    
    LIsNE/COL ERROR
    -------- -----------------------------------------------------------------
    5/9      PL/SQL: Statement ignored
    8/29     PLS-00357: Table,View Or Sequence reference 'TMPPRE_ARC' not
    allowed in this contenxt
    
    
    
    
    
             allowed in this context
    

    This is false:

    'FROM ' | tmppre_arc | ' r '  || Chr (10) |

    Should be

    "OF tmppre_arc r | Chr (10) |

    SY.

  • CANCEL reading and overall-TWG temporary table

    Hello Expert!

    Based on an analysis made by my colleagues... He mentions on a compound of SQL to extract data only to leave a TWG and overturn readings! (Current_obj # ash captured as a event 0 and wait - db_file_sequential_read)

    The thought difficult to obtain a cancellation reason reading when extracting data from TWG!.

    On cancellation, cancellation would be needed!

    But as TWG specific Session, at any time in my session would read the latest copy for all operations. This reading must come from a buffer or disc (Temp).

    Why a reading of cancellation will be required?

    Can you please help me understand a scenario where cancel read for TWG is valid or unrealistic?

    Or conceptually missed something?

    Based on an analysis made by my colleagues... He mentions on a compound of SQL to extract data only to leave a TWG and overturn readings! (Current_obj # ash captured as a event 0 and wait - db_file_sequential_read)

    The thought difficult to obtain a cancellation reason reading when extracting data from TWG!.

    TWG activity generates CANCEL as a result of DML for any table. Which CANCEL then also causes RESTORE to be generated.

    On cancellation, cancellation would be needed!

    OK - but this isn't the only case of use.

    But as TWG specific Session, at any time in my session would read the latest copy for all operations. This reading must come from a buffer or disc (Temp).

    And that is where you get off the track. These statements are NOT correct.

    A session can open several sliders on these data TWG and these several cursors can represent a different "coherent reading" as far as data is concerned.

    Tom Kyte explains better in this AskTom blog.

    https://asktom.Oracle.com/pls/Apex/f?p=100:11:0:P11_QUESTION_ID:4135403700346803387

    and we said...

    Yes, temporary tables generate UNDO - and therefore to generate REDO to CANCEL it.

    Do it again for the cancellation must be created because Cancel is treated the same, the undo tablespace seems to be corrupted on an event of failure/media instance recovery if the cancellation has disappeared.

    The cancellation must be filed in support of the coherence of reading. For example, if you:

    (a) charge a TWG of temporary table with data

    (b) open cursor_1 SELECT * from TWG

    (c) update the data of TWG

    (d) open cursor_2 SELECT * from TWG

    (e) delete most of the data of TWG

    (f) open cursor_3 SELECT * from TWG

    Each of these sliders should see a different result set - we have not recovered from them, has just opened their. cursor_1 must push the blocks changed to point in time (b). This requires CANCELLATION. Thus, the cancellation must be generated - and undo is always protected by the roll forward.

    Changed blocks to the TWG, as for ANY table could be physically written to disk until the transaction is completed. It is not always room in the cache buffers for ALL data that has changed.

    And, as Tom above, each of the sliders really sees the data at a point different 'read-consistent. If some of these extractions of cursor will require reading the UNDO data for "compatible" data for this particular slider.

    The point in time' is established when a cursor is open - no data has yet been read yet.

    See the section 'Multiversion Concurrency Control' of the doc

    https://docs.Oracle.com/CD/B28359_01/server.111/b28318/consist.htm#i17881

    Multiversion Concurrency Control

    Database Oracle automatically provides the reading consistency to a query so that all the data that sees the request comes from a single point in time (at the level of instruction read consistency). Oracle database can also provide read consistency to all queries in a transaction (consistency of reading at the level of transactions).

    Oracle database uses information stored in its rollback segments to provide these consistent views. Rollback segments contain old data values that have been changed by validated or recently committed transactions. Figure 13-1 shows how the Oracle database provides consistent reading using rollback segments data at the level of instruction.

    That reference above 'consistent read to a query' also applies when cursors are opened.

  • What to fill in 'field of the temporary table' for global temporary tables?

    Hello

    I use the Data Modeler 4.0.1.836 and everything that I put in the box 'the scope of the table temp' for a global temporary table doesn't seem to affect the DDL script about the ON COMMIT PRESERVE/DELETE the LINES option. The script poster ON COMMIT PRESERVE ROWS always anything.

    Yet, some of my temporary tables must be created as ON COMMIT DELETE ROWS.

    Using the Data Modeler wrote about it:

    Scope of the temporary Table:

    For a class as a temporary table, you can specify a scope, such as the Dimension or the Session.

    Not sure what 'Dimension' has to do with the scope here, but it makes no difference.

    I tried to put 'Session', 'Dimension', 'Operation', but no luck. So what is the text for the script generate ON COMMIT DELETE ROWS?

    Thank you

    Hello

    The temporary Scope of Table property (on page Types of Classification of the table properties dialog box) is purely documentary.

    To set ON COMMIT DELETE ROWS you must expand the browser for the relational model and find the node for the relevant Oracle physical model.  If you develop it you will find an entry there for your Table. Double-click on that to get the physical model properties dialog box for your table, and you will find a "Temporary" facility that has options (Preserve Rows), YES (Delete Rows) YES or no.

    David

  • Create temporary table in the procedure

    I have a procedure which can be called at any time by multiple users. So I cann't use table in there, because on each call, the table is truncated and inserted. How can I create a temporary table in the procedure?

    Temporary tables in Oracle are different from other RDBMS like SQL Server.

    In Oracle, you create a global temporary table ONCE as part of the design of your database.

    create a global temporary table MyTableName (... columns...) on commit preserve rows;

    You can then use this table in your code as you would any other table.

    The difference is that any data that you insert in this table are only available/visible so that the code runs in the session, and if delete you / truncate the table it only removes the data for this session.  In this way, several sessions we can table without interfering with each other.

    (Note: instead of "preserve" you can change this to "delete" If you want that deleted data automatically when a commit is issued in your session, otherwise the data will be automatically deleted at the end of the session)

  • Global temporary tables

    Hi, db 10g,

    I created a global temporary table with this statement:

    create a table temporary global items (item_id);

    and tried to insert inside of Toad, and I got the message

    1 row inserted,

    but when I asked it, I got

    no selected line?

    I tried the script several times, and the result is the same?

    Thank you

    Hello

    Hi Salem wrote:

    It worked, I added this clause

    ON COMMIT PRESERVE ROWS;

    to create it, statement and it worked correctly, but are not this clause the default?

    No, the default is ON COMMIT DELETE ROWS.  I don't know why; ON COMMIT PRESERVE ROWS seems to be much more widely used.

  • Global temporary table in PL/SQL with XML

    Hello

    I have the impression that it is something strange or maybe I'm missing something basic.

    Step 1: Create a global Temp table that should not be specific transaction.

    create a global temporary table Temp01

    (

    NUMBER OF TICKET_ID

    , Varchar2 (10) of the REGION

    NUMBER OF THE YEAR

    , CO_ID VARCHAR2 (10)

    ) ON COMMIT DELETE ROWS.

    Step 2:

    My XML that goes as a parameter to a new function.

    < TICKET >

    < TICKET_ID > 38498051 < / TICKET_ID >

    the USA < REGION > < / REGION >

    < YEAR > 2014 < / YEAR >

    XYZ123 < CO_ID > < / CO_ID >

    < / TICKET >

    Step 3: Create a Stand Alone function:

    -drop function aagarwal.wr_creation;

    create or replace FUNCTION XML_FUNC

    (

    ret_msg out varchar2,.

    p_xmlval IN varchar2

    )

    RETURN varchar2

    is

    l_xmlval varchar2 (4000): = p_xmlval;

    V_CO_ID VARCHAR2 (10);

    V_CODE VARCHAR2 (10);

    BEGIN

    BEGIN

    INSERT INTO Temp01

    (

    TICKET_ID,

    REGION,

    BLEACHED,

    CO_ID

    )

    SELECT

    EXTRACTVALUE (XmlType (p_xmlval), "/ TICKET/TICKET_ID ') ID,.

    EXTRACTVALUE (XmlType (p_xmlval), "/ TICKET/REGION") REGION.

    EXTRACTVALUE (XmlType (p_xmlval), "/ TICKET per YEAR"),.

    EXTRACTVALUE (XmlType (p_xmlval), "/ TICKET/CO_ID ') CO_ID

    FROM DUAL;

    ret_msg: = 'SUCCESS';

    -SELECT CO_ID IN V_CO_ID of aagarwal. TEMP_STAGE_WR;

    -return ret_msg;

    EXCEPTION

    WHILE OTHERS THEN

    ret_msg: = sqlerrm;

    Return ret_msg;

    END;

    BEGIN

    SELECT CO_ID INTO V_CO_ID FROM Temp01;

    / * MERGE IN the site is

    With the HELP of aagarwal. TEMP01 T

    WE (T.co_id = se.code AND se.type_nm = ' TYPE' and se.src_nm = T.region)

    WHEN NOT MATCHED THEN

    INSERT (ID, SRCNM, CODE, TYPENM)

    VALUES (SHARED_SEQ. NEXTVAL, T.region, T.co_id, 'TYPE');

    -commit; */

    return ret_msg | "ACE" | v_co_id;

    END;

    END;

    /

    Fact - created function.

    NOTE: MERGE statement is blocked and if the function was created in sweetness.

    Step 4: Call the function

    declare

    l_out varchar2 (50);

    l_outr varchar2 (50);

    p_xml XMLTYPE.

    Start

    l_outr: = XML_FUNC (l_out, ' < TICKET >)

    < TICKET_ID > 38498051 < / TICKET_ID >

    the USA < REGION > < / REGION >

    < YEAR > 2014 < / YEAR >

    XYZ123 < CO_ID > < / CO_ID >

    (< / TICKET > ');

    dbms_output.put_line (l_outr);

    end;

    /


    Step 5: Check the value being inserted into the temporary Table:


    Select * from temp01;


    So far so good.

    THE PROBLEM:

    Now I want to tweek the XML_FUNC function above by uncommenting MERGE statement, which brings me to an error that is not differentiable:

    I.e. PL/SQL: ORA-00942: table or view does not exist in line on MERGE pointing to Temp01 statement.

    NOTE: I tested this Merge statement explicitly (as long as the execution of Stand Alone and also by calling via anonymous block PLSQL) and its absolutely perfect work. And SITE table exist.

    PS: I would be grateful, if there is a better way to write this code? I'm not a regular PLSQL developer and so badly can write the code of practice.

    Kind regards

    AAG.

    Using 11.2.0.3:

    Owner of all these three objects is DBA.

    Are you sure?

    After the release of:

    Select object_name, object_type

    of object

    where object_name in ('TEMP01', 'SITE', 'XML_FUNC');

    You must grant the explicit right to select on the table for the owner of the function if the owners are different.

    This works as expected for me (user DEV has all 3 items):

    Connected to Oracle Database 11g Enterprise Edition Release 11.2.0.3.0

    Logged in as dev

    SQL >

    SQL > create a global temporary table Temp01)

    NUMBER OF TICKET_ID 2

    3, Varchar2 (10) of the REGION

    4, NUMBER OF THE YEAR

    5, CO_ID VARCHAR2 (10)

    6)

    7. ON COMMIT DELETE ROWS.

    Table created

    SQL >

    SQL > create table site)

    Identification number 2

    3, srcnm varchar2 (10)

    4, code varchar2 (10)

    5, typenm varchar2 (10)

    6  );

    Table created

    SQL > create the sequence shared_seq;

    Order of creation

    SQL >

    SQL >

    SQL > create or replace FUNCTION XML_FUNC)

    2 p_xmlval IN varchar2

    3)

    4 RETURN varchar2

    5 is

    6 l_xmlval xmltype: = xmltype (p_xmlval);

    7. START

    8

    9 INSERT INTO Temp01

    (10)

    TICKET_ID 11,

    REGION 12,

    13 YEARS,

    CO_ID 14

    15)

    16. SELECT ID EXTRACTVALUE(l_xmlval, '/TICKET/TICKET_ID'),

    17 EXTRACTVALUE(l_xmlval, '/TICKET/REGION') REGION,

    18 EXTRACTVALUE (l_xmlval, ' / TICKET per YEAR ') YEAR.

    19 EXTRACTVALUE(l_xmlval, '/TICKET/CO_ID') CO_ID

    20 FROM DUAL;

    21

    22. MERGE IN site

    23. WITH THE HELP OF TEMP01 T

    (24)

    25 T.co_id = se.code

    26 AND se.typenm = 'TYPE '.

    27 and se.srcnm = T.region

    28)

    29 WHEN NOT MATCHED THEN

    30 INSERT (ID, SRCNM, CODE, TYPENM)

    31 VALUES (SHARED_SEQ. NEXTVAL, T.region, T.co_id, 'TYPE');

    32

    33 return "SUCCESS";

    34

    35 END;

    36.

    Feature created

    SQL >

    SQL >

    SQL > set serveroutput on

    SQL >

    SQL >

    SQL > declare

    2

    3 l_outr varchar2 (50);

    4

    5. start

    6

    7 l_outr: = XML_FUNC (')

    8 38498051

    9 USA

    10 2014

    11 XYZ123

    12    ');

    13

    14 dbms_output.put_line (l_outr);

    15

    16 end;

    17.

    SUCCESS

    PL/SQL procedure successfully completed

    SQL > select * from site;

    ID CODE TYPENM SRCNM

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

    TYPE 1 USA XYZ123

  • Clarification of temporary Table

    I have a small question, I think that must be answered easily, but I couldn't find anything it clarify for me online.

    I have a statement:

    CREATE GLOBAL TEMPORARY TABLE MATR_RPT
    ()PERCENTAGE varchar2()40),
    NUMBER of NUM_OF_CONTRACTS
    ,
    NUMBER OF NUM_OF_CONTRACTS_C
    )
    on commit preserve rows

    BUT if I used "on commit preserve rows" who wouldn t be the same using a standard non-temporary table if it maintains the lines? Or I have forgotten here?

    Thank you!

    on validation keeps the lines:

    On the temporary table will remain once the transaction is complete. These recordings will live as long as the session that inserted is connected to them. After that this session left (dc), records have disappeared.

    on commit delete rows:

    On the temporary table will be gone when the transaction is closed without worrying if the session remains online or disconnect after.

    Concerning

  • trigger on the global temporary table

    Hello

    I have a global temporary table

    CREATE GLOBAL TEMPORARY table to register)

    no_registre NUMBER primary key,

    date of create_time

    ) ON COMMIT DELETE ROWS.

    I have to write a trigger on the table every time that the insertion is made.

    create or replace trigger tri_register

    before inserting the REGISTER

    for each line

    Start

    : new create_Date: = sysdate;

    end;

    /

    This trigger can work on this registry table?

    Thank you

    913578 wrote:

    Sorry Karthik.

    the thing is that I did not have privelleges to test, I send the code to some dba who makes deployment.

    Sorry to hear that!

    Please tell me... We can write triggers on GTT?

    of course, you can!

    SQL > create a global temporary table registry
    () 2
    no_registre 3 number primary key,
    create_time date 4
    5)
    6 on the validation to delete lines;

    Table created.

    SQL > create or replace trigger register_trig before insert in the register for each line
    2 start
    3: new.create_time: = sysdate;
    4 end;
    5.

    Trigger created.

    SQL > insert into values of registry (no_registre) (1);

    1 line of creation.

    SQL > select * from registry;

    NO_REGISTRE CREATE_TI
    ----------- ---------
    1 8 JULY 13

  • How to insert into a GLOBAL TEMPORARY TABLE and get the data from it?

    The requrement is
    Split the string ENTRY point on the base and store it in a Collection. And the values of the collection will be stored in a global temporary table. Then, I'm updating some other table based on the data from the temporary table.

    There is in fact no error message. But there is no data in the temporary table and also no change in the update statement

    First of all, I'm creatiing a global temporary table only once outside the procedure.

    CREATE GLOBAL TEMPORARY table GLt (data_element number)


    create or replace procedure test_proc (p_in_string VARCHAR2) is
    i the number: = 0;
    number of POS: = 0;
    CLOB lv_str: = p_in_string;
    p_delim VARCHAR2 (1): = ', ';

    TYPE t_array IS TABLE OF VARCHAR2 (20) INDEX directory.
    t_array channels;

    BEGIN

    -cutting of string input and store in the strings (i) collection

    POS: = instr (lv_str, p_delim, 1, 1);
    WHILE (pos! = 0) LOOP
    i: = i + 1;
    Strings (i): = substr(lv_str,1,pos-1);
    lv_str: = substr (lv_str, pos + 1, length (lv_str));
    POS: = instr (lv_str, p_delim, 1, 1);
    IF pos = 0 THEN
    Strings (i + 1): = lv_str;
    END IF;
    END LOOP;

    run immediately "drop table TWG;
    run immediately ' CREATE GLOBAL TEMPORARY table (data_element number) TWG on commit preserve rows ";

    FORALL i in strings.first... Strings.Last
    INSERT INTO VALUES TWG (strings (i));
    commit;

    Update first_tbl set PIN is "XXX" where first_col in (select data_element from TWG);.
    commit;

    END test_proc;

    Published by: cedric b on January 25, 2013 12:59

    Remove the two execute immediate line. They are wrong.

    And then use the table in your code that you created at the beginning. The name is GLT.
    And delete the first commit. This validation would empty the temporary table of GLT.

    You get an error? Or it does not work as expected?

    Also, show how you call the procedure.

    Published by: Sven w. January 25, 2013 14:45

  • Use two temporary tables to assign 'color' to the results of the data

    Hello world... Here's what I'm trying to do, any help is appreciated of course...

    Data and Tables in the example:

    I have 5 dishes, each course has 2 assignments.
    with Courses as (
     select 100 courseID from dual union all
     select 200 from dual union all
     select 300 from dual union all
     select 400 from dual union all
     select 500 from dual
    ), Assigns as (
     select 'test100' name, 100 courseID from dual union all
     select 'test100', 100 from dual union all
     select 'test200', 200 from dual union all
     select 'test200', 200 from dual union all
     select 'test300', 300 from dual union all
     select 'test300', 300 from dual union all
     select 'test400', 400 from dual union all
     select 'test400', 400 from dual union all
     select 'test500', 500 from dual union all
     select 'test500', 500 from dual
    )
    select assigns.name, assigns.courseID from courses
    inner join assigns on assigns.courseID = courses.courseID
    I need each assignment to get a color assigned to it according to its courseID. So my theory is that I have a temporary table with a list of colors; each courseID would be are they assigned a color, but my question is how can I assign each courseID a color without anything to join the temporary table? Once that each courseID has a color, I would join rights holders so that each assignment has a color associated with it according to its courseID.
    --Color table with 6 colors
    with Colors as (
     select 'red' color from dual union all
     select 'blue' from dual union all
     select 'yellow' from dual union all
     select 'green' from dual union all
     select 'purple' from dual union all
     select 'teal' from dual
    )
    I have a previous post on this topic, but I didn't do well explain and make a link to it would probably add to the confusion to this question... happy to delete this post if someone recommends.

    Thanks for any help! Running Oracle 11 g.

    Hello

    939920 wrote:
    I don't have the ability to store the courseID with colors...

    Can get it, or ask someone with the makeup of capacity change for you.

    Is the problem that you have more than 6 courses but you want to add color to them with only 6 colors, and it is unclear what courses can be included in the results of a given query?
    If so, you can do somehting like this:

    WITH     colors     AS
    (
         SELECT  'red' AS color_name     FROM dual UNION ALL
         SELECT  'blue'                FROM dual UNION ALL
         SELECT      'yellow'          FROM dual UNION ALL
         SELECT     'green'               FROM dual UNION ALL
         SELECT  'purple'          FROM dual UNION ALL
         SELECT     'teal'                FROM dual
    )
    ,     colors_plus     AS
    (
         SELECT     color_name
         ,     ROW_NUMBER () OVER (ORDER BY NULL) - 1     AS color_id
         ,     COUNT (*)     OVER ()                    AS color_cnt
         FROM     colors
    )
    ,     course_assigns     AS
    (
         SELECT  a.name
         ,     a.courseid
         ,     DENSE_RANK () OVER (ORDER BY  a.courseid)     AS course_num
         FROM          assigns          a
         INNER JOIN      courses      c     ON   a.courseid   = c.courseid     -- If needed
    )
    SELECT     ca.name
    ,     ca.courseid
    ,     cp.color_name
    FROM     course_assigns  ca
    JOIN     colors_plus       cp  ON   cp.color_id  = MOD ( ca.course_num
                                                 , cp.color_cnt
                                      )
    ;
    

    Typical power:

    AME      COURSEID COLOR_
    ------- ---------- ------
    test100        100 blue
    test100        100 blue
    test200        200 yellow
    test200        200 yellow
    test300        300 green
    test300        300 green
    test400        400 purple
    test400        400 purple
    test500        500 teal
    test500        500 teal
    

    It would be better if you could create a real table as colors_plus.

    If there are more than 6 separate courses in the output, then 2 or more courses can be coded in the same color, but no color will be used N times (N > 1) until all the colors have been used N-1 times.
    The assignment of courses coolors is arbitrary. Depending on how fancy you want to do this, you might want to do something more complicated. For example, you have 2 course with 10 lines of each and 5-course dinner with 1 row of each. The query above will have to assign the same color to 2 courses of differenct, and it can assign the color "blue" for 2 courses with 10 rows of each. The query above can be modified, if necessary, assign the colors in order of frequency, in order to ensure that two 10-line courses get different colors, and that the colors tend to be more evenly distributed. I'll leave that as an exercise. (Tip: use the frequency in the clause ORDER BY of DENSE_RANK.) To obtain the frequency, use the COUNT function analytical in a subquery. Why do you need a subquery? Discuss among you).

Maybe you are looking for