Use two temporary tables to assign "color" to data results

Hi, Everyone... Here's a rundown of what I'm trying to do, any help is obviously appreciated...
Example Tables and Data:
I have 5 Courses, 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.courseIDI need each assignment to get a color assigned to it according to it's courseID. So my theory is that I'd have a temporary table with a list of colors; each courseID would get assigned a color but my question is how do I assign each courseID a color without anything to join the temporary table on? Once each courseID has a color, I'd join in Assigns so that each assignment has a color associated with it according to it's 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 about this but I didn't explain it well and to link to it would probably add confusion to this question... happy to delete that post if someone recommends it.
Thanks for any help! Running Oracle 11g.

Hi,
939920 wrote:
I don't have the ability to store the courseID with the colors...Then get it, or have someone with the ability make the change for you.
Is the problem that you have more than 6 courses, but you want to color-code them with only 6 colors, and there's no telling which courses may 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 output:
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 tealIt would be better if you could create a real table like colors_plus.
If there are more than 6 distinct courses in the output, then 2 or more courses may be coded with the same color, but no color will be used N times (N>1) until all colors have been used N-1 times.
The assignment of courses to coolors is arbitrary. Depending on how fancy you want to make this, you might want to do something more complicated. For example, say you have 2 courses with 10 rows each, and 5 courses with 1 row each. The query above will have to assign the same color to 2 differenct courses, and it might assign the color 'blue' to the 2 courses with 10 rows each. The query above can be modified, if necessary, to assign the colors in order of frequency, to guarantee that the two 10-row courses get different colors, and that the colors are more evenly distibuted in general. I'll leave this as an execise. (Hint: use the frequency in the ORDER BY clause of DENSE_RANK. To get the frequency, use the analytic COUNT function in a sub-query. Why do you need a sub-query? Discuss amongst yourselves.)

Similar Messages

  • Unable to use two af:tables with differing coloring (skins)?

    Im trying to configure the Siebel Self-Services application and customize the skinning. I have some problems though, because i need to show two af:tables on the same page, but with different coloring. One with black background and white text (both header and body) and one with white background and black text. I have tried to use styleClass:es, but the css parameters set for the af table are overriding the ones set in the stylesheets.
    Anyone having an idea how to overcome this?
    Thanks
    /Jon-Erik

    Hi,
    if the styleClass name is table1 then the skin selector would be something like
    .table1 af|table
    or .afTable.af|table
    I don't see how this can be overriden. If you assumption is that the style class reference must be to a CSS definition on the page then this indeed does not work. The styleClass name is kind of a named identifier for the component to skin and is used to further qualify the component to skin
    Frank

  • When to use global temporary tables?

    which are the probable situations when one can think of using global temporary tables?

    In my experience, most often GTTs are used by developers from other RDBMSs who have become used to needing 'intermediate tables' created on the fly to hold data while they 'loop and commit to free locks'.
    These developer may not have had enough exposure to Oracle's concurrency model and therefore use the 'other' concurrency model as the basis for an application port - usually followed up by a call to the forum for assistance in performance tuning. <g>
    That said, legitimate uses for GTTs include staging or scrubbing table for data transport or preparation, eg: ETL into a warehouse, when the intermediate data is
    a) reproducible (therefore does not need to be logged); and
    b) the results of the intermediate operation, but not the source, are stored in permanent tables.
    Some developers also use GTTs to hold the equivalent to a 'temporary materialized view' specifically for complex reporting purposes.

  • Why awful gray color of data results grid in the 1.1.23.64 ?

    SQL Developer 1.1.23.64 Production is a great product. Really great. It will enormously boost the popularity of Oracle database. Hence, it is not understandable:
    1. why SQL Developer development team insists on awful gray color of data results grid? It spoils very good look-and-feeling of SQL Developer IDE. The best solution would be to provide it as an option in Tools\Preferences
    2. why font size of Help file is still too small and unreadable, specially on Linux platform (RHEL-4.4, Sun Java jdk1.5.0_10) ?
    Cheers
    Albert

    Albert,
    Were you also getting a grey color in the SQLWorksheet portion of the IDE? When I hit f9 after entering a script, the script portion turns an ugly gray color, but the results grid looks fine. I'm trying to figure out if your issue is the same as mine.
    Thanks!

  • Using Global Temporary Table in Discoverer.

    Hi All
    I am currently working on a Disco report, where I am initializing a package at the disco condition level which inserts data in to a Global Temporary Table.
    The global temporary table will be having data based on the parameter entered by the user. But the problem occurs when we are trying to use the same GTT in the select statement as shown below. The desktop is not giving me the otuput but the GTT is getting populated with data.
    see below
    SELECT bla1,
    bla2,
    bla3
    FROM GTT (global temp table)
    WHERE 1= PACKAGE.FUNCTION(par1, par2, par3...) <- here we are trying to insert into GTT based on the paramenters passed.
    Can you please suggest how this can be achieved. Or is there any way to trigger the insertion in to GTT other than the calling it in the condition level.
    Thanks
    Arun

    Hi,
    You cannot use a GTT like this because you cannot write and read from the GTT using a single SQL statement. You must either have the insert in a separate worksheet and tell the users to run this worksheet first, or you wrap it all up in a table function called from within a view. The table function can then insert and select from the GTT using two statements.
    Which method is best depends on what you are trying to do and why you want to use a GTT.
    Rod West

  • Appropriate use of temporary table - or can pivot approach be used?

    I am relatively new to pl/sql. My problem is that I need to return one row of data (joining several tables, including a 1-many), but with a varying number of columns (from single values returned from the 1-many table), and record types cannot be dynamically defined or modified (such as with adding columns).
    I am not sure if pivoting the many table would work, because the range of values returned (albeit not expected to realistically exceed a dozen) do not fall within a small set.
    Would dynamically generating SQL to create a temporary table with the requisite number of columns be the best approach? Then I could select all the data into the table, iterate through the results from the 1-many and populate into the columns, and then select * from the temp table for the return resultset.
    Specifics: There is a document table which has a 1-many table containing the CC's for that document. Only one row will ever be returned from the master doc table, and 0-n rows from the CC table. There could be no CC's for the doc, or there could be any number. I need to be able to return all the columns from the document table PLUS the CC's as if they were all one row in a table.
    So example of a return row might be a doc with n # of cc's
    DOC_ID | DOC_TYPE | DOC_OWNER | <etc> | CC_1 | CC_2 | ... | CC_n
    or a doc with all its fields and no cc's
    DOC_ID | DOC_TYPE | DOC_OWNER | <etc>
    So I am thinking the pl/sql would have to
    1. declare the SQL statement to create a temporary table
    2. declare the SQL statement to insert data into the temporary table
    3. declare the SQL statement to query data from the temporary table
    4. fetch the count of CC's based on doc id from the CC table
    5. use that count to loop and
    1. append columns onto the sql that creates the temporary table
    2. append columns onto the sql that will query the temporary table
    6. query the CC's table and read the values into an array
    7. use the count again to loop and dynamically create the insert statement for the temporary table, using the values from step 6
    8. execute the insert statement
    9. query the temporary table using the sql generated in step 5.2 and return that rowset
    HUGE thanks to anyone who can provide input on this. I know it's not a new problem, I am just unsure of the best approach to the solution.

    It's not that I require a single SQL statement to do this; in fact I expected to have to execute at least 2 in the procedure to accomplish the goal. The problem I am running into is that I need to return a dynamic number of columns, based on the number of entries in the 1-many table.
    I'm guessing if I can look up the number of rows in the 1-many table that I need to pivot before I actually do the pivot, I will be able to use this technique?
    The reasoning for all this can be summed up in one word: legacy. The row is being sent back to a legacy component which only takes that one single row of data. Currently, we are only limited to 3 CC entries and are expanding the system to allow >3, hence the 1-many table. However, the legacy component isn't able to handle anything more complex than that one row. Our clients will be able to change their definitions easily to expand from CC1, CC2, CC3 to however many they want to use. However, changing to multiple rows wouldn't be an option because it would incur too much complexity.

  • Query hint to force SQL to use a temporary table in a CTE query?

    Hi,
    is it possible to tell SQL Server to create a temporary table by itself when I'm using a CTE in my query?
    I have a query starting with a CTE where I group by my record, then another recursive CTE use the first CTE and finally my select statement like:
    with cte as (select a,b,c,row_number() ...  from mytable group by a,b,c)
    , cte2(select .... from cte A where rownum =1
    union all select ... from cte B inner join cte2 C on ......
    select * from cte2
    this query is very very slow, but if I store the first CTE into a temporary table and then cte2 consume my temp table rather than the CTE, the query is very fast.
    creating the temp table took 10sec and the select took 20sec
    while the initial query didnt return anything  after 2minutes!!!
    so what can I try to do to have the query running in less than 30sec without creating the temp table first?
    is there a query hint which can be used to tell SQL Server to convert the CTE into a temp table?
    as I have a lot of query to manage, I want to simplify my model without relying in temporary tables every time I suffer this issue...
    thanks.

    What is your SQL Server version?
    There is no hint to materialize results of cte into a temp table, so the solution you tried is the best you can have.
    I think the idea of materializing CTE into a temp table was already proposed on Connect. Try searching for this and vote.
    For every expert, there is an equal and opposite expert. - Becker's Law
    My blog
    My TechNet articles

  • How to use Oracle temporary table and verify if it exists

    1. I got two errors on the following code.
    ORA-06550: line 13, column 4:
    PLS-00428: an INTO clause is expected in this SELECT statement
    ORA-06550: line 17, column 3:
    PLS-00103: Encountered the symbol "CREATE" when expecting one of the following:
    2. Can I include this code in the create view statement?
    Thanks ahead, I am new to oracle dev world.
    ===========================================================
    DECLARE
    l_count NUMBER;
    BEGIN
    select count(*)
    into l_count
    from all_tables
    where table_name like 'TEMP_SHOW_STAFF_2%';
    if l_count > 0 then
    select * from TEMP_SHOW_STAFF_2;
    else
    create global temporary table TEMP_SHOW_STAFF_2
    (employee_id Number,
    last_name varchar(10),
    first_name varchar(10),
    salary_amount varchar(10))
    on COMMIT delete rows;
    end if;
    END;

    The PL/SQL User's Guide will have much more information, but as a quick example (new_dept is an empty table with the same structure as the DEPT table in the SCOTT schema).
      1  declare
      2    -- Create the type & declare a variable of that type
      3    type dept_arr_typ is table of dept%rowtype;
      4    dept_arr dept_arr_typ;
      5  begin
      6    -- Populate the type in memory
      7    select *
      8      bulk collect into dept_arr
      9      from dept;
    10    -- Manipulate the data
    11    for i in 1..dept_arr.count
    12    loop
    13      select 'foo'
    14        into dept_arr(i).dname
    15        from dual;
    16    end loop;
    17    -- Write the data back
    18    for i in 1..dept_arr.count
    19    loop
    20      insert into new_dept( deptno, dname, loc )
    21        values( dept_arr(i).deptno, dept_arr(i).dname, dept_arr(i).loc );
    22    end loop;
    23* end;
    SCOTT @ nx102 Local> /
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:00.01
    SCOTT @ nx102 Local> select * from new_dept;
        DEPTNO DNAME          LOC
            10 foo            NEW YORK
            20 foo            DALLAS
            30 foo            CHICAGO
            40 foo            BOSTONOf course, for this sort of thing, we could do everything in a single SQL statement
    INSERT INTO new_dept( deptno, dname, loc )
      SELECT deptno, 'foo', loc
        FROM dept;Collections can be handy if you need to apply a bit more conditional logic, though.
    Justin

  • Using Global Temporary Table in OBIEE 11

    Hi,
    THe requirement is to run a database function before the report runs. This Function accepts 5 parameters (Presentation Variable) and populates a GTT Global Temporary Table.
    This GTT is configured in presentation Layer.
    Issue:
    1. Created a dummy report which returns only one row and called the fucntion using "Evaluate" in this.
    2. Created 2nd report using GTT Columns.
    All these 2 reports placed on dashboard and Presentation variable are set in the prompt. The first one runs correctly and populate the "Regular Table". Means when I create a regular table instead of GTT I can see the correct record. But if I change it to GTT then the data does not get populated in this table.
    Any Inputs?
    Regards

    HI,
    If you are using a GTT, you need to run the function which populates the GTT before OBI server executes the select query on that table.
    In your case, the OBI server is executing the select query from the table before the data is populated in the table.
    In order to force the BI server to run the query after the GTT is populated, you need to specify the condition in the connection pool settings under the connection scripts tab.
    In the execute before query, enter your physical query which runs the function to populate the GTT.
    Hope this helps !
    Thanks,
    Vineeth

  • Java Error while Using GLobal Temporary Tables

    Hi,
    Am having a global temporary table in my application with ON COMMIT DELETE ROWS option.
    I use it in a procedure to remove previous records, populate new ones and return a ref cursor
    Am calling this procedure from a java bean. In this call, the procedure gets executed successfully but when i try to access the RefCursor Object, I get an SQL Exception that the object no longer exists.
    Here are some inputs for reference:
    My DB Call:
    cstmt = myConn.prepareCall ("{ call MYPACKAGE.GTT_PROCEDURE(?,?,?,?,?, ?,?,?,?,?, ?,?,?,?,?)}");
    My RefCursor Access:
    rsRuleSet = (ResultSet)cstmt.getObject(11);
    The SQLException:
    java.sql.SQLException: ORA-08103: object no longer exists
    Please note that the SQLException shown as per Java Stack trace is on the line with the RefCursor Access
    If anybody has any idea, then do reply
    Thanks in Advance,
    Piyush

    A couple of thoughts...
    Have you tried calling this procedure from PL/SQL to verify that the REF CURSOR returned is valid?
    Is your Java application set to autocommit, or do handle transactions yourself. If the container is handling transactions, it may committing as soon as the stored procedure finishes running, which would clear your temp table.
    Justin
    Distributed Database Consulting, Inc.
    http://www.ddbcinc.com/askDDBC

  • Use two different table in a single alv

    hi all , i m working on zproggram but in display i have a problem that i have data in two int table which do not have common field,i m using  fm REUSE_ALV_BLOCK_LIST_APPEND  and 'REUSE_ALV_BLOCK_LIST_DISPLAY but it is displaying data in this format
    matnr  demand dispatch_ quant   balance
    721008 2000     1000                   1000.
    pdc mc paint fg
    50  80   80   80
    but i want it should come into single coloum  for eg in this format
    matnr    demand   dispatch_ quant   balance  pdc mc paint fg
    721008   2000       1000                   1000.    50   80   80    80
    can anybody help please.
    points will be rewarded surely
    721008 2000     1000                   1000.

    Hi Sarabjit,
    In normal ALV, i dont think it is possible to display two internal tables side by side.....one way is you can club both the internal tables into one internal table (By introducing common fields).
    If not i think using OOPS ALV, with help of containers you can acheive this functionality..
    Best Regards,
    Ram.

  • Problem ! Calling report6 from forms6(run_product()) using global temporary table.

    Requirement :
    To generate stock movement report for certain selected items.
    Background :
    A Form is created with data block (tmp_item_master - a global temporary table)
    when_new_form_instance :
    inserting into tmp_item_master from item_master and then execute_query on tmp_item_master block.
    User selects certain items using check box provided.
    Now tmp_item_master is updated for ch_select_flag_yn = 'Y' for selected items
    and commit.
    Calling report from form(using run_product()).
    Now the main query in report, is joined with tmp_item_master where ch_select_flag_yn = 'Y'
    Here, we are unable to see the report for any item. As the global temporary table data is not visible in the report session.
    How to resolve this problem ?
    Note : global temporary table created with ON COMMIT PRESERVE ROWS
    Thanking you,
    From praful.
    null

    Hi,
    You are using 'ON Commit Delete Rows' . Instead of Use ' ON COMMIT PRESERVE ROWS'
    The ON COMMIT DELETE ROWS clause indicates that the data should be deleted at the end of the transaction.
    CREATE GLOBAL TEMPORARY TABLE my_temp_table (
    column1 NUMBER,
    column2 NUMBER
    ) ON COMMIT DELETE ROWS;
    In contrast, the ON COMMIT PRESERVE ROWS clause indicates that rows should be preserved until the end of the session.
    CREATE GLOBAL TEMPORARY TABLE my_temp_table (
    column1 NUMBER,
    column2 NUMBER
    ) ON COMMIT PRESERVE ROWS;
    Edited by: Mrucha on Nov 26, 2012 6:06 AM

  • Calculate ratio using two fact tables

    Hallo all,
    i have one transaction table orders with detail on hotel (dimension), day (dimension), order state (fact attribute), order and measure ordered roomnights     
    and one state table with detail on level hotel, day and measure hotel rooms count
    i want
    ordered roomnights     
    available roomnights     
    when i make report with the same attributes like hotel, month the results are satisfied i.e. hotel roomnights are visible and sum (all hotels, all months) is as expected.
    but when i add the transaction atribute order state i won't get the numbers for available roomnights, because it has not the attribute.
    I would like to display the number and to be repeated for all the order states, it is possible?
    Here is example
              2012-11     
              Ordered roomnights     Total roomnights available
    Hotel 1     Cancelled     2     100
    Hotel 1     Confirmed     8     100
         Total Hotel 1 10     100
    Hotel 2     Cancelled     2     200
    Hotel 2     Confirmed     18     200
         Total     Hotel 2 20     200
    Total          30     300
    thx

    hi in the capacity fact table remove the level set for the calendar dim and see.

  • When we are using Event pooling tables explicitly we have insert data into

    hi all
    i have read about event pooling table,
    if we implement event pooling tables then explicitly we have insert table information (like product_dim) in event pooling table explicitly
    suppose i have updated more then 5 tables in my database that time i have to enter(insert) 5 table information in event pooling table(Tables_nq_emt) in the back end
    if so then what is the use of event pooling table???
    this is event pooling table i have crated in back end
    CREATE TABLE S_NQ_EPT (
    UPDATE_TYPE DECIMAL(10,0) DEFAULT 1 NOT NULL,
    UPDATE_TS DATE DEFAULT SYSDATE NOT NULL,
    DATABASE_NAME VARCHAR2(120) NULL,
    CATALOG_NAME VARCHAR2(120) NULL,
    SCHEMA_NAME VARCHAR2(120) NULL,
    TABLE_NAME VARCHAR2(120) NOT NULL,
    OTHER_RESERVED VARCHAR2(120) DEFAULT NULL NULL
    Thanks

    Hi,
    IF you are using event pooling then you should make use of triggres in database.Create a trigger 'after insert' on some major table which you think is gonna update after every etl load.As soon as some data is inserted into this table trigger will automatically insert a record in event pooling table and cache will be purged.I am not sure about the syntax of triggers.Please google it around.
    If you are trying to purge cache through oDBC procdure then you need to create a shell script and based on whether ETL load has completed ,you need to execute this script.
    regards,
    Sandeep

  • Use of global temporary tables in Procedures

    Hi
    I am using global temporary tables in the procedures. Loading data in the same table through many procedures. I am fetching the data from the global temporary table in PRO-C by a cursor. Will this degrade performance?
    Please help me..
    Thanks in Advance...

    Will this degrade performance?That depends... in comparison to what?
    Loading data into temporary tables will generally be more efficient than loading data into permanent tables because Oracle needs to do less to protect this data since it is inherently transient. On the other hand, loading the data into a table in the first place tends to be more expensive than alternatives like using a single SQL statement, a pipelined table function, or an in memory collection.
    Justin

Maybe you are looking for

  • Java startup property for Adobe document services

    Hi guyz, since a while i'm facing a random issue when i generate pdf. All the configuration has been done, but when look at in configtool i see a missing parameter: -Dorg.omg.PortableInterceptor.ORBInitializerClass.com.sap.engine. services.ts.jts.ots

  • Can I run a DVD through my macbook pro and stream to the apple tv?

    Can I run a DVD through my MacBook Pro and steam to the apple tv?

  • How do I recover lost notes?

    I wrote one ongoing note between my iPad & iPhone, started under ios6 & finished under ios7, that's gone missing. Rescue ideas?

  • Settings for output of various documents

    Hello All, Working with SRM 6.0. I am unable to define the action profile for other documents other than existing action profile for Purchase order.Through the wizard in we could add conditions for the Purchase order action profile .Hence I am unable

  • Apple TV Photo Album Order

    I just noticed that for some reason, the photo albums that I initially synced to my Apple TV appear alphabetically -- and then right after all of those albums, any new photo albums I synced subsequently appear alphabetically (i.e., A-Z original album