SQL Query - store the result for optimization?

Good day experts,

I'm looking for advice on a report. I did a lot of analytical functions to get the basic data that I have to do my report and its takes about 50 min for SQL finish. Now, with these data, I need to create 3 different reports and I can't use the SQL even since there are a lot of aggregation (example would be product group in one case and by customer in 2nd). For each of these different group garages I need another report.

So how to create 3 reports of 1 SQL query without running the query 3 times?

First thing that comes to mind is to store the result set in a fictitious table, and then query the table since I get the basic data are about 300 lines and then perform different garages group.

Best regards

Igor

So how to create 3 reports of 1 SQL query without running the query 3 times?

You already know the obvious answer - store data 'somewhere '.

If any 'somewhere' depends on your needs and you have not provided ALL the.

MV - if the query is always the same, you might use a MV and make a complete refresh when you want that new data. The data are permanent and can be queried by other sessions, but the query that accesses the data is frozen in the definition of MV.

GTT (global temporary table) - If a NEW charge of data AND three reports will be ALWAYS executed by a single session and then data are no longer necessary so a TWG may work. The application that loads the TWG can be different for each race, but the data won't be available for a single session and ONLY for the duration of this session. So if something goes wrong and the session ends the data are missing.

First thing that comes to mind is to store the result set in a fictitious table, and then query the table since I get the basic data are about 300 lines and then perform different garages group.

Which is commonly called a "table of REPORT-READY." Those that are useful when data must be permanent and available for multiple sessions/users. Generally, there is a batch (for example the package procedure) that periodically refreshes / updates the data during a window of failure. Or the table can have a column (for example AS_OF) that allows it to contain multiple data sets and the update process let alone the existing data and creates a new set of data.

If your database is about 300 lines you can consider a table report and even use it to contain multiple data sets. Then, the reports can be written to query the data by using a value AS_OF that wraps and returns the appropriate data. You don't need a window of failure since the oldest data are still available (but can be removed when you no longer need.

If you need a set of data, you can use a partitioned table work (with only one partition) to collect the new set of data, then a SWAP PARTITION to 'swap' in the new data. Only, this "Exchange" takes a fraction of a second and avoids a window of failure. Once the swap done no matter what user query will get new data.

Tags: Database

Similar Questions

  • Store the result in the file in SQL Developer

    Hello
    Is it possible to store the results of the query, or MS in physical file?
    I found no option to do this, I'm under it from Windows using SQL Developer machine.
    then I expect output file will be stored on the server of Ora machine, right? There is probably no option for Oracle to store on the local computer of W.


    TX all

    TRent

    Right-click in the selection of grid, export data, an option.

  • Store the result of SQL in the local file?

    Hello
    Is it possible to store the results of SQL (executed from ksh scripts) in the file on the local client (server not DB), I know how to do in SQLPlus, but want to simpify process using existing script .ksh calling Oracle and exec any SQL.

    Is this possible?

    TX
    M

    Well, you always need SQL * more:

    #!/bin/sh
    sqlplus -s username/password@tnsentry << EOF
    set trimout on trimspool on tab off echo off feed off verify off pages 0 lines 20000
    spool result.txt replace
    select * from emp;
    spool off
    exit
    EOF
    exit
    

    NOTE: code not tested, not Linux/Unix to play with for now

  • The right way to store the results of the query

    Hey wizards Oracle,.

    I have a few questions that take a long time to run. Given that the results of these queries change only once a day, I will execute queries every morning and store their results in a table.

    I was going to serialize them in chains to the CSV format and then store them as CLOB. But shit, Oracle is a data table, storage system! This is reinventing the wheel within a wheel.
    Then I thought about creating one table per query would be the right way to store their results. But ordinary tables data recovery would be slow, because I would need to create an additional of ORDER_BY column to maintain the order of the results of the query.

    It seems that there is a way to store varrays in the LOB columns, but it does not seem to be appropriate.
    There may be a caching mechanism that could help?

    Does anyone know the proper way to store the result of a query?

    What you describe is a reinvention of the materialized views.
    Have you considered using them?

    ----------
    Sybrand Bakker
    Senior Oracle DBA

  • How to store the result of the second SP in variable in first SP

    Hello

    I have two stored procedures "sp1" and "sp2". I want to call sp1 sp2, but I want to store the result of sp2 in any variable or derive from table or anything else

    so that I can use the result of sp2 in sql sp1.

    Yours sincerely.

    >
    I have two stored procedures "sp1" and "sp2". I want to call sp1 sp2, but I want to store the result of sp2 in any variable or derive from table or anything else

    so that I can use the result of sp2 in sql sp1.
    >
    Too many questions and not enough information.

    1. the number of rows of data are you talking about?
    2. have you already written procedures? If you could put the two procs in the same package and use a collection of share plan.
    3. what actually does sp2? Could you do it in sp1 query/cursor instead of having a separate procedure?
    4. you could make sp2 a procedure in pipeline and then sp1 can query sp2 such as table data.
    5. for large amounts of data, you can use a global temporary Table.
    6. for small amounts of data, you can use a collection of PL/SQL.

  • Vs. runtime vs. ViewObject ViewObject SQL query in the xml file.

    Hello

    I wonder what is the difference between query SQL in the long term, creating a view object in the duration and the creation of a display with an XML object.

    I'm not trying to have the result set cached just to pick once.


    My code for a creation of a view in a run-time object:

    HashSet<Integer> allPersonIdThatUserHasAccessTo = new HashSet<Integer>();
                AppModuleImpl am = (AppModuleImpl)ADFUtils.getApplicationModuleForDataControl("AppModuleDataControl");
    
                String sqlStr = "SELECT up.person_id FROM user_person up where up.user_id = " + userId;
                ViewObjectImpl vo = (ViewObjectImpl)am.createViewObjectFromQueryStmt("AllPeopleUserHasAccessToVo", sqlStr);
                vo.executeQuery();
                RowSetIterator rsi = vo.createRowSetIterator(null);
                while (rsi.hasNext()) {
                    Row personRow = rsi.next();
                    Integer personId = ((BigDecimal)personRow.getAttribute(0)).intValue();
                    allPersonIdThatUserHasAccessTo.add(personId);
                }
    
                rsi.closeRowSetIterator();
                vo.remove();
    

    When should I use SQL query, when the view object use at time of execution and time to create the view object to an xml file?

    In general you should not write this code in a managed bean. Access code or in your case creating a VO belongs behind the façade in the module of the application.

    You can create the original Version, but the main difference is that it takes more time. Code everything that the definition of VO created in the data model of the application module would make too and it clears directly after the query only to create the same code again the next time you call the method.

    If the goal is not to keep the data, you can create the hashset class and call executeEmptyRowSet() on the VO (https://blogs.oracle.com/smuenchadf/entry/what_does_executeemptyrowset_d for details). This way you only need a VO that takes a parameter and gets you the same result in less time.

    Timo

  • Store the result of a function in a variable

    Hello
    I have an interface where I do some transformations (get Oracle COST of the corresponding values of PeopleSoft). For research, I have a PL/SQL function in place. This function takes the values of the columns in my input in the runtime source data store. I want to store the result of the function in a variable, use the variable instead of calling the function again later. Any help is appreciated.

    Hello

    I had the problem...

    Gotta 'keep' the same order value to execute the PL/SQL only once...

    In this case, a first suggestion is:

    (1) create an interface to load a temporary table (yellow interface). The target table will be the PK and a field with the PL/SQL returned returns. The source will have the same tables as the real interface.
    Remember, IKM, to set the create table and options to truncate to 'yes '.

    2) add the temporary table to the real interface (drag / move the yellow interface itself in the source of real interface box) and create a join by PK.

    (3) just to map the column transformed (from the temporary table) for columns 4 targets...

    This help you?

    Published by: Cezar Santos on 02/12/2008 13:52

  • Dynamic SQL query in the DB adapter

    Hello
    I want to use the following custom SQL query in the DB adapter:

    SELECT EMP_ID, EMP_NAME, EMP_LOCATION FROM EMP WHERE EMP_ID IN (#iNPUT_PARAMETER)

    the problem I'm facing is that I don't know at the time of the development that EMP_ID how much will be passed to the process so that I can not use the input parameter specific number. I cannot use it IN the query within which statement I concatenate all the EMP_ID separated by comma and passed under INPUT_PARAMETER, but when running, he read the full concatenated string as a single string rather than identify them as a list of different: with comma separation. could someone help me in this case

    Thank you
    Sunil

    Use the following query with two parameters. Build the string with delimiter when running and pass this string and delimiter to query... (in this example, the input value would be the same for both Delimiter1 and Delimiter2.)

    Select * from EMP WHERE deptno IN (SELECT SUBSTR (STRING_TO_TOKENIZE, DECODE (LEVEL, 1, 1, INSTR (STRING_TO_TOKENIZE, SEPARATOR, 1, LEVEL-1) + 1), INSTR (STRING_TO_TOKENIZE, SEPARATOR, 1, LEVEL)-DECODE (LEVEL, 1, 1, INSTR (STRING_TO_TOKENIZE, SEPARATOR, 1, LEVEL-1) + 1)) FROM (SELECT #StringToTokenizer | #Delimiter1 AS STRING_TO_TOKENIZE, #Delimiter2 AS DELIMITER FROM DUAL) CONNECT BY INSTR (STRING_TO_TOKENIZE SEPARATOR) ((, 1, LEVEL) > 0)

    Thank you
    -Sreeny

  • Error: you have an error in your SQL syntax; consult the manual for your version of the MySQL server for the right syntax to use near ')' at line 5

    Original title: how to solve this problem:

    System error

    You have an error in your SQL syntax; consult the manual for your version of the MySQL server for the right syntax to use near ')' at line 5

    Hi Roger,

    It seems that you have problems with the SQL syntax. The question you have posted is related to encoding and it would be better suited to the MSDN Community. Please report it in the community below.

    http://social.msdn.Microsoft.com/forums/SQLServer/en-us/home

    Hope this is useful.

  • What is the best way to store the RCS for an insert/update in this rec

    Oracle on Win 64 non-conteneur 12.1.0.2

    When a record in one table is inserted or updated, what would be the best way to store the RCS for this record in this folder.

    I thought of a line after trigger, but did not know if this trigger to store the current_scn would still fire that trigger again (recursive trigger).

    Someone at - he a good idea of what the best way is to do?  The devs don't want to store the pk and the SNA in yet another table...

    Yes, row_dependencies would be the best way to go.  But mgmt doesn't recreate all tables for this.

    3rd party applications retrieve data from tables (all data).  We are looking for a way for them to just pull what is new or updated updated since their last sweater.

    I suggest that you try again and give all OF THE REQUIREMENTS.

    You have rejected ANY answer given and he justified using 'hidden' on what knowledge management or the devs want or do not want to. Stop making us guess what are the requirements and constraints. If you want a real answer then tell us ALL the news.

    When a record in one table is inserted or updated, what would be the best way to store the RCS for this record in this folder.

    Solomon answered repeatedly. If you want to add a column to a table to store the then "best" SNA is to let the Oracle to do this for you automatically by using the DEPENDENCY LINE.

    As he says also re-create the table to add this clause will be MUCH MORE EFFECTIVE that everything THAT you can do it manually. It will be also more accurate because Oracle will fill the value ORA_ROWSCN with the SNA at the time the line was committed. You, as long as user, can't fill a column in function when a line is engaged since real VALIDATION belongs to a transaction, not the line or the trigger that you use.

    Yes - there are two drawbacks to this method:

    1. you need to re-create the table

    2. you cannot add an index to this "hidden" column

    The devs don't want to store the pk and the SNA in yet another table...

    Then? Who cares what the devs want to do? You want the BEST solution? Next, you will need to put aside personal preferences and determine what is the 'best' solution. Why it is important that certain dev wants to do this or not?

    OK, the problem of biz is now, 3rd party external users are an all-wheel drive large number of tables in the database via the API that we wrote.  That was obviously interrupted OLTP during the day.  To reduce to the minimum, we want for them just to extract data that has been inserted/updated since their last sweater.

    It is the definition of a "replica" DB Then why don't you consider a real replicated DB? You can use DataGuard and have replicated DB which is read only that can be used to generate reports. Oracle does ALL the work to keep ALL the tables in sync. You and your developers do NOTHING!

    We thought that store the RCS higher their last sweater would allow the API to extract only data with YVERT higher than their last data pull CHN.

    OK - except you keep rejecting solutions actually do. Ask you questions about the SNA stored in the same table, but then reject the solution that does this. And then you add your "devs" don't want to store the info in a new table either.

    Then your solutions must ONLY use the replication or Log Miner. The REDO logs have all changes, if you want to extract yourself. Replication (e.g., DataGuard) will use these logs for you to maintain a replicated database.

    We thought about it, but recreate all tables in production with ROWDEPENDENCIES as well as dealing with CF and other dependencies idea this was shot.

    Well you NEVER mentioned you "thought that" and rejected it. And you NEVER mentioned anything about FKs and other dependencies. What is FKs and other dependencies which prevents this working solution? Tell us! Give us ALL the information.

    Wouldn't a trigger AFTER LINE capture the commit YVERT?  Or is after really not after validation?

    No - a trigger has NOT one commit. A trigger runs as a step in a transaction. Validation applies to the entire transaction. Until you, or Oracle, issues a commit, there is NO "committed SNA" to be stored as ORA_ROWSCN.

    You can easily see that for yourself. Create a simple table with dependencies of the line and then update two different sessions.

    create the table emp_scn rowdependencies in select * from emp where rownum<>

    Select empno, emp_scn ora_rowscn

    Update emp_scn set work = 'b' where empno = 7499

    commit;

    The first SELECT statement will show you that each row has the same SNA.

    EMPNO, ORA_ROWSCN

    7369,70622201

    7499,70622201

    7521,70622201

    Now, do the update (but no commit), then SELECT it

    EMPNO, ORA_ROWSCN

    7369,70622201

    7499,

    7521,70622201

    Where is the value of 7499? This session will NOT see a value for the changed lines in the current transaction. Other sessions will still see the old value.

    Now do the validation, then SELECT

    EMPNO, ORA_ROWSCN

    7369,70622201

    7499,70622301

    7521,70622201

    7499 now has a new and different value than the other lines. It will not be this new value until the validation occurs.

    Yes, row_dependencies would be the best way to go.  But mgmt doesn't recreate all tables for this.

    Well, you got the answer you want. You ask the best way. Now, you say that you were told the best way. But now you don't like the answer.

    How is it our fault? Your question has been answered wasn't she?

    Here are the facts:

    1 oracle creates a history of changes - the REDO log files

    2. you can use Log Miner to extract these changes

    3. you can create your own change log by adding a log file of MV to your table.

    4. you can then write a custom code to use this MV log file to determine which rows to "reproduce".

    So far reject you all THE POSSIBLE solutions.

    Accept it or change the requirements to allow one of the solutions proposed to be used.

    Personally, if I HAD to use a customized solution, I would use a MV journal to record the ROWID of the lines that have changed (for tables ROWID cannot be changed). I would then extract the appropriate lines by pulling on the lines corresponding to these row ID.

    Even that has problems since a line can be changed several times and children lines can also be amended several times - these questions FK you mentioned.

    I suggest you read this entire thread on AskTom a dozen years ago. It addresses ALL these issues.

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

    Then in your next reply on this topic give us a summary of where some things with your question and what help you further expect.

  • Why do I get a SQL syntax; consult the manual for your version of the MySQL server for the proper syntax

    I have a purchase order where my buyers can add to my form. I use a loop that adds an extra line when they add a new product. I'm storing the information in two tables different mySQL. The first is alll of my personal, the second is the elements. My personal records correctly. However, I get the following error when you save the items:

    You have an error in your SQL syntax; consult the manual for your version of the MySQL server for the right syntax to use near 1, 'wer 2345', 1, 1)' on line 9

    The error occurred in E:\webs\clarkwebhosting.com\SSL\esrc\order_add.cfm on line 74

    ++ After storage of the personal information, I take the command ID to populate the table of Articles

    < cflock timeout = "5" >

    < name cfquery = "qGetorderID" datasource = "#application.dsn #" >

    Select max (orderID) as oid of orders

    < / cfquery >

    < / cflock >

    < cfoutput > < cfset getoid = #qGetorderID.oid # > < / cfoutput >

    ++ Is the loop that I use to fill the table items ++

    < cfloop to = "#form.numba # '1' = ' index 'idx' = >"

    < cfset getqty = evaluate ("form.qty" & idx) >

    < cfset getitem = evaluate ("form.item" & idx) >

    < cfset getunit = evaluate ("form.unit" & idx) >

    < cfset gettotal = evaluate ("form.total" & idx) >

    < name cfquery = "insertItems" datasource = "#application.dsn #" >

    INSERT in Articles

    (orderID,

    quantity,

    agenda,

    Unit,

    total

    )

    VALUES)

    < cfqueryparam value = "" #getoid # "CFSQLType ="CF_SQL_INTEGER">"

    < cfqueryparam value = "" #getqty # "CFSQLType ="CF_SQL_INTEGER">,"

    < cfqueryparam value = "" #getitem # "CFSQLType ="CF_SQL_VARCHAR">,"

    < cfqueryparam value = "" #getunit # "CFSQLType ="CF_SQL_INTEGER">,"

    < cfqueryparam value = "" #gettotal # "CFSQLType ="CF_SQL_INTEGER">"

    )

    < / cfquery >

    < / cfloop >

    This line: 1, 'wer' 2345, 1, 1 is the first element of the command line. Any ideas as to why it doesn't work? I use 5.5.9 - log CF9 and mySQL

    My apologies... that should have been (note the quotes)...

    In addition, it would be...

    On another note... You should probably avoid using cfinput and simply use the standard form tags.

  • SQL Query to retrieve records for all after the Max Dates.

    Hello everyone,

    I am trying to retrieve the record more recent, based on the date field ( nextDate ).

    Currently, there are only 4 records in the MC_Maintenance table and two in the Machine table.

    Machine table

    MC_id             EquipID          

    1                      0227

    MC_id EquipID

    2                     0228

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

    MC_Maintenance table

    Maint_id MC_id Next_maint

    1                      2                      08/25/2010     

    2                      2                      07/01/2010

    3                      1                      2010-11-06

    4                      1                      07/11/2010

    I have am trying to accomplish is,.

    the list of the two machines of the table of the Machine with the MAX (Next_maint) control the list of MC_Maintenance results

    These are the records I want to display.

    Maint_id MC_id Next_maint

    1                      2                      08/25/2010

    4                      1                      07/11/2010                 

    Here is the SQL query

    SELECT

           MC. MC_ID as ID,

    MC.complete_Date completed.

    MC.next_maint as nextDate,.

    MC.maint_notes as noted,.

    MC.facility Facility.

    M.EquipId,.

    $m.name as the name.

    M.SerialNumber SN.

    M.dept as dept.

    M.Freq as freq

    Of MC_Maintenance MC, Machine M

            where  MC. MC_ID = M.MC_ID

    '           Using MAX (nextDate)

    Any ideas would be useful.

    TJ

    I thought it was a simple group of problem?

    SELECT M.EquipID, MC.MC_ID, Max(MC.next_maint)
    FROM MC_Maintenance MC INNER JOIN Machine M ON MC.MC_ID = M.MC_ID
    GROUP BY M.EquipID, MC.MC_ID
    
  • How to store the result of a query in a variable in the data model

    In a model of date I want to do something like this

    < name of dataTemplate = than one dataSourceRef "HURDetail" = "BRM_DATA_SOURCE" >
    < Parameters >
    < parameter name = "PARAM_THRESHOLD_VALUE" dataType = "number", defaultValue = "0" / >
    < / Parameter >

    < SQLStatement instance name = "Q1" >
    <! [CDATA]
    SELECT count (*) FROM TABLE_NAME
    []] >
    < / sqlStatement >

    -I want to assign the output of the above query to PARAM_THRESHOLD_VALUE so I can use it in future requests...
    -My query is complex, for reason of performance I want to store the output of the query.

    Please suggest how do...
    Made a package with the PARAM_THRESHOLD_VALUE parameter and the function value entry assigns the done variable to work?

    Thank you
    Shiva

    Hey Shiva,

    If you want to use the value of the counter in the other queries in the data model, you can have an alias for the extraction of County and use it as a bind variable in other queries as


    SELECT count (*) PARAM_THRESHOLD_VALUE
    FROM TABLE_NAME
    ]]>

    and can use it in another query as


    SELECT XYZ
    FROM TABLE_NAME2
    WHERE XXX = *: PARAM_THRESHOLD_VALUE *.
    ]]>

    Hope this is what you want.
    Thank you.

  • Date query shows no results for the date of the day

    Hello everyone. I use Jdeveloper 11.1.1.3.0 with ADF and I have a view named query with a single field, Date. The operator that he uses is equal to a value written in the field. The problem is that when I insert a line in the table (the date is automatically set to the current date on the insertion) and I'm looking for today it returns nothing. However if I leave the field blank it will find me the line. I tried to do this with the timestamp option, but it is not very user-friendly, the user will need to type in the time line was inserted to find, or use between it operator for two fields which is something I want to avoid if possible

    The requirement is a query field that allows the user to choose a date on the calendar and shows all lines that are inserted at this date (even if the date is today, and the line was inserted a few minutes before).

    Published by: Dino2dy on April 6, 2011 02:50

    Dino2dy,

    The best way to proceed would be just to add an additional attribute to your VO - use "TRUNC (your_date_column_name)" as the value for the attribute - then just compare this attribute in the named view criteria.

    John

  • SQL to display the results if the number of output is below a limit

    I have a requirement where I can display the SQL result set if the number of records output is 1000 or less than that... otherwise raise a user-defined exception, say "Please change the search criteria. I can achieve this by GET the the number of SQL rows first and then re-run the same SQL to display the data if the number of rows is less than 1001. Could someone let me know if this is possible without re - run the SQL several times as the SQL is the query intensive re-source

    Hello

    You can try in bulk collect into a collection.

    If the number of rows in the collection is less than 1000 triggers an application error or return results, if it is greater than 1000

    If this is suitable for your needs, please post more information on the system requirements.

    Kind regards

    Cool

Maybe you are looking for

  • HP Envy5544: The heavier weight of card for HP Envy5544

    Just bought a HP Envy 5544. Delighted with the quality of printing on paper. However, I make cards and use good quality card. What is the heaviest weight I can put in the printer? Happy to put a sheet at a time - it's more about the weight it can han

  • Qosmio G50: Need advice Vista Ultimate Upgrade

    Because I want to access the local security policy editor, it is necessary to upgrade Vista Home Premium to Vista Ultimate. Before I have to embark on this mission, can someone please advise me on the potential pitfalls, both in installation (that I

  • How to share files between Windows XP and Windows 7 without password?

    Hey guys, I want to share files between windows 7 and windows XP. I don't want to put the password on my Windows 7 or Windows XP account. I am going on my Windows XP perfectly shared files from Windows 7, but I am not able to go on my files of window

  • Windows XP Pro SP3, very, VERY, SLOW to the hibernation

    Reference Dell Lattitude D620, Windows XP Professional, recently upgraded from SP2 to SP3 & IE6 to IE8. 2 GB of RAM. Before the upgrade, "Fn + F1" = hibernation; the process took 12-13 seconds to complete. After upgrade, I rebooted Ad-Aware, Spybot S

  • Download Windows Vista .iso

    I have a computer that has the Windows Vista Home Basic (key) sticker on this subject. The HD has been re-partitioned and reformatted. I don't have the CD of Windows Vista. Is it possible to get a .iso file so I can install a legal OS? States of owne