Insert the results of the query with constants
I need to select a table primary keys, then insert them into another table with a status value.Select SQL would SELECT APP_ID OF PLAINTIFF WHERE LAST_NAME 'L % '.
I need all the APP_IDs insert into a table along a status of "in PROGRESS". The table has two columns; ID and the STATE.
How to combine these operations?
You can try
Insert into your_table(ID,STATUS)
SELECT APP_ID ID,'IN PROGRESS' STATUS FROM APPLICANT WHERE LAST_NAME LIKE 'L%';
commit;
Tags: Database
Similar Questions
-
Rewrite the query with joins, and group by
Hello
It's an interview question.
Table names: bookshelf_checkout
virtual library
And the join condition between these two tables is title
We need to rewrite under request without using the join condition and group by clause?
When I was in College, I read most of SELECT statements can be replaced by operations base SQL (DEFINE the OPERATORS). Now, I am rewriting the query with SET operators, but not able to get the exact result.SELECT b.title,max(bc.returned_date - bc.checkout_date) "Most Days Out" FROM bookshelf_checkout bc,bookshelf b WHERE bc.title(+)=b.title GROUP BY b.title;
Kindly help me on this.
Thank you
SuriSomething like that?
1 WITH books AS ( 2 SELECT 'title 1' title FROM dual UNION ALL 3 SELECT 'title 2' FROM dual UNION ALL 4 SELECT 'title 3' FROM dual ), 5 bookshelf AS ( 6 SELECT 'title 1' title, DATE '2012-05-01' checkout_date, DATE '2012-05-15' returned_date FROM dual UNION ALL 7 SELECT 'title 1' title, DATE '2012-05-16' checkout_date, DATE '2012-05-20' returned_date FROM dual UNION ALL 8 SELECT 'title 2' title, DATE '2012-04-01' checkout_date, DATE '2012-05-15' returned_date FROM dual ) 9 SELECT bs.title, MAX(bs.returned_date - bs.checkout_date) OVER (PARTITION BY title) FROM bookshelf bs 10 UNION 11 (SELECT b.title, NULL FROM books b 12 MINUS 13* SELECT bs.title, NULL FROM bookshelf bs) SQL> / TITLE MAX(BS.RETURNED_DATE-BS.CHECKOUT_DATE)OVER(PARTITIONBYTITLE) ------- ------------------------------------------------------------ title 1 14 title 2 44 title 3
Lukasz
-
SQL statement error INSERT The conflicted with the FOREIGN KEY constraint
I recently installed a reporting for vmware vsphere software, but I get a SQL error. I opened a request for assistance with vmware, but so far they have not come up with a solution. The error is caused by: com.microsoft.sqlserver.jdbc.SQLServerException: instruction INSERT The conflicted with the FOREIGN KEY constraint 'FK_CB_VSM_NETWORK_VC_ID '. The conflict occurred in database 'VCChargebackVCC02', table "dbo." " CB_VSM_SERVER', column 'VC_ID '. I don't know a lot about SQL, so I'm lost in the extent of troubleshooting is concerned. If anyone has any ideas I'd love to hear them.
SQL questions are better posed on Technet. They are better equipped to manage the
http://social.technet.Microsoft.com/forums/en-us/categories/
-
can anyone provide a link to insert the image with the text on the button in the apex 4.2.6
ReemaPuri wrote:
in the workspace image:-resign.jpeg
As a button? Seriously?
Ok. First of all, because the image already contains text, there no point in including the same wording in the form of text on the button. Accessibility requirements can be met using re-sign as alternative text. 4.2, create an image button:
Tag/Alt text: Re-sign
Static ID: re - sign
Style button: Image
Button Image: & WORKSPACE_IMAGES.resign.jpeg
To make the image looks more like a button, add the following CSS to Inline CSS property page:
#re-sign img { margin: 0 2px 2px 0; border: 2px outset; border-radius: 4px; } #re-sign img:active { margin: 2px 0 0 2px; border: 2px inset; border-radius: 4px; }
Finally, there is a bug in 4.2 that generates the incorrect URL for the button images, which requires dynamic action of Page Load to fix.
Event: Loading the page
Action: Run the JavaScript Code
Code
var resignImg = $("#re-sign img"); resignImg.attr("src", resignImg.attr("src").replace("/i/", ""));
-
join in the query with the result of a single line
Hi all
I have two tables
I insert the following recordscreate table item(item_id number primary key, item_desc varchar2(200)); create table item_properties(item_id number references item(item_id), property_name varchar2(20), property_value varchar2(100));
now I want a query that produces the following resultsinsert into items values(1,'CPU'); insert into item_properties values(1,'RAM','2gb'); insert into item_properties values(1,'PROCESSOR','2ghz'); insert into item_properties values(1,'HARDDISK','2ghz'); commit;
How to generate this result?item_id RAM PROCESSOR HARDDISK 1 2gb 2ghz 2TB
I create a query, but it generates several lines, instead I need a single line like above.
Kind thanks.select i.item_id,p.property_value from items i , item_properties p where i.item_id=p.item_id and i.item_id=1;
Published by: Maahjoor on May 7, 2013 12:22 AMselect i.item_id, max(decode(p.property_name,'RAM',p.property_value)) ram, max(decode(p.property_name,'PROCESSOR',p.property_value)) processor, max(decode(p.property_name,'HARDDISK',p.property_value)) hd from items i , item_properties p where i.item_id=p.item_id and i.item_id=1 group by i.item_id;
Or pivot to 11g
with details as ( select i.item_id,p.property_name,p.property_value from item i , item_properties p where i.item_id=p.item_id and i.item_id=1 ) select * from details pivot ( max(property_value) for property_name in ('RAM','PROCESSOR','HARDISK') );
Published by: JAC on May 7, 2013 13:04
-
Compare the result of a query with a number and return a message
Hello
I have the following query in oracle 9i:
SELECT COUNT (*)
OF hourly_files
WHERE date_received = TO_DATE ((SELECT TO_CHAR (SYSDATE - INTERVAL '1' DAY, 'DDMMYYYY')
(THE DOUBLE), 'DDMMYYYY');
This will produce a number of lines required
I need to compare the number of output with another number hardcoded (threshold) and print an appropriate example message
If the result of the query above is 18000 and the number of threshold is fixed at 20000, then output a meesage:
Number of files received less than 2000
Any help will be very appreciated!
Thank you.SQL> ed Wrote file afiedt.buf 1 SELECT CASE WHEN COUNT(*) >5 THEN 'Number is > than 5' 2 WHEN COUNT(*) <1 THEN 'Its less than 1' 3 ELSE 'Its in between' 4 END 5 FROM emp 6* WHERE deptno=20 SQL> / CASEWHENCOUNT(*)>5 ------------------ Its in between SQL> SELECT COUNT(*) FROM emp 2 WHERE deptno=10; COUNT(*) ---------- 3
-
How to transpose the query with the following result
Dear all,
Can someone tell me a method to convert my query result
Details are provided in
http://obiee11ge.blogspot.com/2010/07/how-to-transpose-query-with-following.html
Concerning
MustafaHello
Try this
Create a request combined with,criterion no. 1: model, revenue (Actual), Cogs (Actual), Opex (Actual), PL (Actual)
in the dummy column fx enter the "Real" value
criterion 2: model, revenue (Yago), Cogs (YAgo), Opex (Yago), PL (Yago)
in the dummy column fx enter the value as "Yago".
criterion 3: model, revenue (Budget), Cogs (Budget), Opex (Budget), PL (Budget)
in the dummy column fx enter the value as 'Budget '.
Now go to the columns of result and set names coumn (revenue, COGS, Opex, PL) for the result set.
For the Dumny, remove column header.In a sheet view, you will get the result.
Thank you
Vino -
Display of the results of the query with the column names unknown
I use this code to grab the headers of columns in a select * statement. (I never know what table is queried out of 12 000 or more.) I want to make a loop on the column headers, then the query results in a web page table.
< cfoutput >
< cfset colHeaderNames = ArrayToList (recordset1.getColumnList ()) / >
#colHeaderNames #.
< / cfoutput >
Is there a similar method or suggestions for the release of the results of the query - now that I know the column headings?If I understand correctly, you can do something like the code below.
-
results on the query with filter, but no results when the filter removed
I was handed the query below and I may be missing something blinding here but if I run it I get no results
SELECT lipqoh
OF f41021 a, b f0006
WHERE b.mcmcu = a.limcu AND
b.mcstyl = "W";
If I add the filter a.liitm = 105900 as data below is returned (although the inputs are 0 as expected at the moment, this isn't always the case)
SELECT lipqoh
OF f41021 a, b f0006
WHERE b.mcmcu = a.limcu AND
b.mcstyl = 'W '.
a.liitm = 105900;
the fields for each of the tables mentioned in the motion have the following features
lipqoh number NULLABLE
mcmcu Char(12 BYTE) NOT NULLABLE
mcstyl tank (2 BYTE) NULLABLE
liitm number NO NULLABLE
Any guidance would be greatly appreciatedThank you for providing feedback. The only difference seems to come from the mcstyl columns.
The following snipplet perhaps explain how this expression may be true or not true according to the data types.select * from dual where 'W ' = cast('W' as char(2 byte)); DUMMY ----- X select * from dual where cast('W ' as varchar2(2 byte)) = 'W'; no rows found
This statement returns all rows?
SELECT lipqoh FROM f41021 a , f0006 b WHERE b.mcmcu = a.limcu AND b.mcstyl = 'W '; /* blank added */
I expect so. I still don't understand why oracle treats differently the two queries. However I do not have an adequate control environment. Your version is simply a bit outdated (no longer supported). And I know that some of the type conversion rules had been changed between 9i and 10g.
Published by: Sven w. on March 30, 2010 15:15
-
Need help in the optimization of the query with the Group and joins by clause
I'm having the problem by running the following query... It takes a lot of time. To simplify, I added the two tables FILE_STATUS = stores the file load details and COMM table Board table job showing records treated successfully and which was communicated to the other system real. Records with status = T is trasnmitted to another system and traansactions with P is waiting.
Here's the query I wrote to give me the details of the file that has been loaded into the system. He reads the table of State and the commission files to display the name of the file, total records loaded, total at the table of the commission and the number of records which has finally been passed successfully loaded (Status = T) with other systems.CREATE TABLE FILE_STATUS (FILE_ID VARCHAR2(14), FILE_NAME VARCHAR2(20), CARR_CD VARCHAR2(5), TOT_REC NUMBER, TOT_SUCC NUMBER); CREATE TABLE COMM (SRC_FILE_ID VARCHAR2(14), REC_ID NUMBER, STATUS CHAR(1)); INSERT INTO FILE_STATUS VALUES ('12345678', 'CM_LIBM.TXT', 'LIBM', 5, 4); INSERT INTO FILE_STATUS VALUES ('12345679', 'CM_HIPNT.TXT', 'HIPNT', 4, 0); INSERT INTO COMM VALUES ('12345678', 1, 'T'); INSERT INTO COMM VALUES ('12345678', 3, 'T'); INSERT INTO COMM VALUES ('12345678', 4, 'P'); INSERT INTO COMM VALUES ('12345678', 5, 'P'); COMMIT;
In production, this request has several joins and takes a long time to deal with... the main culprit for me is the join on the COMM table to count the number of number of transactions sent. Please can you give me tips to optimize this query to get results faster? What I need to delete the Group and use the partition or something else. Help, please!SELECT FS.CARR_CD ,FS.FILE_NAME ,FS.FILE_ID ,FS.TOT_REC ,FS.TOT_SUCC ,NVL(C.TOT_TRANS, 0) TOT_TRANS FROM FILE_STATUS FS LEFT JOIN ( SELECT SRC_FILE_ID, COUNT(*) TOT_TRANS FROM COMM WHERE STATUS = 'T' GROUP BY SRC_FILE_ID ) C ON C.SRC_FILE_ID = FS.FILE_ID WHERE FILE_ID = '12345678';
Don't know if it will be faster based on the information provided, but analytical functions offer an alternative approach;
select carr_cd, file_name, file_id, tot_rec, tot_succ, tot_trans from (select fs.carr_cd, fs.file_name, fs.file_id, fs.tot_rec, fs.tot_succ, count(case when c.status = 'T' then 1 else null end) over(partition by c.src_file_id) tot_trans, row_number() over(partition by c.src_file_id order by null) rn from file_status fs left join comm c on c.src_file_id = fs.file_id where file_id = '12345678') where rn = 1; CARR_CD FILE_NAME FILE_ID TOT_REC TOT_SUCC TOT_TRANS ------- -------------------- -------------- ---------- ---------- ---------- LIBM CM_LIBM.TXT 12345678 5 4 2
-
Internal XML to the query with join
I have a CF page that reads an XML file in a query using < cffile > XMLParse and QueryAddrow.
I then do a QoQ on the result and voila! I have my page. I hide the query for 8 hours and the XML file is only reread this cache expires. It works well.
My problem now is that the file contains data from three tables of database instead of one, so I need to make an inner join on the tables. But I can't do a t/t with an inner join.
Does anyone know a way for me to do this?
Oh, didn't know that. How about interweaving of QofQ? Join Query1 and Query2 requests in a new query, then join for 3 statement?
-
Structure of the query with parameters
Hello
Consume the web service, the results in a file xml with complex structures.
The function below the structure of the query
< TemplateName CcResultItems = "CgrInfo_1" >
My question is how to reorganize the query to obtain the results of the structure
< TemplateName CcResultItems = "CgrOwners_4" >
which should return three rows.Kind regards
Kostadincreate or replace
FUNCTION WS_SELECT_XML RETURN VARCHAR2 AS
XML_VAR XMLTYPE: = XMLTYPE)
"" ' < soap envelope: xmlns:soap = 'http://www.w3.org/2003/05/soap-envelope"" xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" container = "http://www.w3.org/2001/XMLSchema" >. "
< soap: Header >
"< XmlSoapHeader xmlns ="https://test.wstestx.com/XWS2/ "/>"
< / soap: Header >
< soap: Body >
"< ProcessRequestResponse xmlns ="https://test.wstestx.com/XWS2/">."
< ProcessRequestResult > <! [CDATA [< CcResponse >
< TemplateName CcResultItems = "CgrInfo_1" >
< CcResultItem > < InfoMessage > < / InfoMessage > < IsitTerminated > 0 < / IsitTerminated > < IdObject > 365124 < / IdObject > < sanctuary ObjectlName > < / ObjectlName > < ObjectTaxNumber > 305089321502 < / ObjectTaxNumber > < / CcResultItem >
< / CcResultItems >
< TemplateName CcResultItems = "CgrUnits_2" >
< / CcResultItems >
< TemplateName CcResultItems = "CgrActors_3" >
< CcResultItem > < IdObject > 365124 < / IdObject > < UnitNo > 0 < / UnitNo > < EntityTYPEcode > 1 < / EntityTYPEcode > < EntityTYPEdesc > person < / EntityTYPEdesc > < / CcResultItem >
< / CcResultItems >
< TemplateName CcResultItems = "CgrOwners_4" >
< CcResultItem > < IdObject > 365124 < / IdObject > < EntityTYPEcode > 1 < / EntityTYPEcode > < EntityTYPEdesc > person < / EntityTYPEdesc > < OwnerID > 610697843014 < / OwnerID > < OwnerName > ALEX < / OwnerName > < / CcResultItem >
< CcResultItem > < IdObject > 365124 < / IdObject > < EntityTYPEcode > 1 < / EntityTYPEcode > < EntityTYPEdesc > person < / EntityTYPEdesc > < OwnerID > 840645947005 < / OwnerID > < OwnerName > JOHN < / OwnerName > < / CcResultItem >
< CcResultItem > < IdObject > 365124 < / IdObject > < EntityTYPEcode > 2 < / EntityTYPEcode > < company EntityTYPEdesc > < / EntityTYPEdesc > < OwnerID > 703454 < / OwnerID > < OwnerName > BROWN < / OwnerName > < / CcResultItem >
< / CcResultItems >
< TemplateName CcResultItems = "CgrActivities_5" >
< / CcResultItems >
< TemplateName CcResultItems = "CgrMembership_6" >
< / CcResultItems >
< TemplateName CcResultItems = "CgrFounding_7" >
< CcResultItem > < IdObject > 365124 < / IdObject > < FoundingDate > 2007-08-16 13:53 < / FoundingDate > < Total > 146701.00 < / Total > < / CcResultItem >
< / CcResultItems >
[[< / CcResponse >]] > < / ProcessRequestResult >
< / ProcessRequestResponse >
< / soap: Body >
< / envelope soap: >
');
BEGIN
FOR R IN)
WITH T AS (SELECT (XML_VAR) DOUBLE COLLAR)
SELECT x2.*
FROM XMLTable)
XMLNamespaces)
' http://www.w3.org/2003/05/soap-envelope ' LIKE 'SOAP'
, by default ' https://test.wstestx.com/XWS2/ '
)
, ': soap envelope / soap: Body/ProcessRequestResponse/ProcessRequestResult '
by the way XML_VAR
path of CcResponse clob columns '.'
) x 1
XMLTABLE)
' / CcResponse/CcResultItems.
XMLPARSE PASSAGE (DOCUMENT X 1.) CCRESPONSE)
COLUMNS
TemplateName VARCHAR2 (140) path "@TemplateName"
, IDOBJECT VARCHAR2 (140) PATH "CcResultItem/IdObject.
, PATH of VARCHAR2 (340) OBJECTLNAME ' CcResultItem/ObjectlName '.
, PATH of VARCHAR2 (140) VRSKA 'CcResultItem '.
) X 2
WHERE X 2. TemplateName = "CgrInfo_1."
-WHERE X 2. TemplateName = "CgrActors_3."
-WHERE X 2. TemplateName = "CgrOwners_4."
) LOOP
DBMS_OUTPUT. Put_line (' IdObject: ' |) R.IDOBJECT | ' ObjectlName: ' | R.ObjectlName | "TemplateName ' |" R.TemplateName);
END LOOP;
DBMS_OUTPUT. Put_line ("- end -");
RETURNS A NULL VALUE.
END WS_SELECT_XML;Based on your query, I'll assume that you started with
Extract data from webservice response
In my opinion, it comes of the change you are looking for
FOR R IN ( SELECT x2.TemplateName, x3.idobject, x3.OWNERID FROM XMLTable( XMLNamespaces( 'http://www.w3.org/2003/05/soap-envelope' AS "soap" , default 'https://test.wstestx.com/XWS2/' ) , 'soap:Envelope/soap:Body/ProcessRequestResponse/ProcessRequestResult' passing XML_VAR columns CcResponse clob path '.' ) x1 , XMLTABLE( '/CcResponse/CcResultItems[@TemplateName="CgrOwners_4"]' PASSING XMLPARSE(DOCUMENT X1.CCRESPONSE) COLUMNS TemplateName VARCHAR2(20) PATH '@TemplateName' , ItemXML XMLTYPE PATH 'CcResultItem' ) X2 , XMLTABLE( '/CcResultItem' PASSING x2.itemXML COLUMNS IDOBJECT VARCHAR2(20) PATH 'IdObject' , OWNERID VARCHAR2(20) PATH 'OwnerID' ) X3 )
As Odie post pointed out. The first (x 1) XMLTable retrieves the content of ProcessRequestRequest and by doing this, delete the CDATA tag. We now have a CLOB that resembles XML. The second XMLTable (x 2) converts this CLOB into an XMLType and looking for the node that matches the XPath expression. It's where I've hardcoded in your query to search for a specific node. As you want node has a repeated structure that you want to retrieve each row, I spent structures repeatedly in the third XMLTable (x 3) so he could analyze. You could combine x 2 and x 3 using XQuery, but I suggest starting by this method I found that it's easier to understand what is happening.
To test out your code, simply replace the line
by the way XML_VAR
with
from XMLTYPE ("... the content of the SOAP Message...")
and run the query. You can do this to debug the query as you and just do a SELECT * to see what all went from XMLTable to XMLTable, so went to check the correct data.
-
Insert the hyperlink with &;
Hi I have query that inserts not sure it gives following error...
Enter the docid value:
Enter the value of nsf:
Enter display value:
Enter the value of ESG:
This is the query
INSERT INTO homepage_productlist (product_id, product_desc, product_link, is_enabled, created_by, creation_date, last_updated_by, last_update_date)
VALUES (2, 'Manager', 'https://www-abc.com/esm_65/license_types.jsp?Open & docid = 200 & nsf = custserv - ent.nsf & view = docid & seg = ent', 'Y','s / n, sysdate,'s / n, sysdate);
This gives the following error...
Enter the docid value:
Enter the value of nsf:
Enter display value:
Enter the value of ESG:
Please let me know what is the cause, and sometimes it works without error mesaage some sysstem it works sometimes it fails with the above error...
I appreciate your response.TOGETHER SET OFF THE COAST.
-
Report with the query with union and parameters
Hello
We have an obligation to create a report with the request, which is the union and parameters.
I intend to create a database for the report based on a query. But the problem here is that the way to pass parameters in the query.
Request is something like that
Select x.a, x.b, x.c
x
where x.year =: para1
and x.status = 'A '.
Union of all the
Select x.a, x.b, x.c
x
where x.year =: para1 - 1
and (x.status = 'c' and x.date =: para2 or x.status = 'I' and x.date < =: para2)
Here x.year in the first select statement must be equal to: para1 and second select statement, it should be: para - 1.
How this requirement can be achieved?
Client don't want to separate worksheet, a parameter and another for the actual data that I tried with sys_context and it worked. But the client wants the result in a single sheet only... So I need to change their approach.
Help, please.
Thank youHello
Another option is to convert the request so that you will have the items from the selection
for example on the query you provided that you can use:Select 'Curr' rec_type, x.a, x.b, x.c, x.year, x.date, x.status
x
where x.status = "A".
Union of all the
Select 'Prev' rec_type, x.a, x.b, x.c, x.year, x.date, x.status
x
where x.status in ('c', 'I')then, in the workbook, you will be able to create conditions such as:
rec_type = 'Curr' and year =: para1rec_type = 'Prev' and year =: para1-1
rec_type = 'Prev' and (status = 'c' and date =: para2 or status = 'I' and date)<=>=>Tamir
-
Please help improve the query with the analytic function
The mentioned below query takes about 10 hours to complete (10.2.0.4).
There are 3 tables (table t has a relationship 1: n with table e and k table also has a relationship 1: n with table e).
Table a contains 200,000 lines. (this table is truncated and inserted several times a week)
E table contains rows of 1Mio.
K table contains rows of 170Mio.
I need a query that takes the latest 3 posts for a given t_id:drop table t; create table t ( t_id number, constraint t_pk primary key (t_id) ); drop table e; create table e ( e_id number, e_doc nvarchar2(16), e_date date, constraint e_pk primary key (e_id) ); drop table k; create table k ( t_id number, e_id number ); create unique index k_i1 on k(t_id, e_id); exec dbms_stats.gather_table_stats(user, 'T'); exec dbms_stats.gather_table_stats(user, 'K'); exec dbms_stats.gather_table_stats(user, 'E'); -- Sample data: insert into t(t_id) values (100); insert into t(t_id) values (101); insert into t(t_id) values (102); insert into t(t_id) values (103); insert into e(e_id, e_doc, e_date) values (200, 'doc 200', to_date('01.01.2010', 'DD.MM.YYYY')); insert into e(e_id, e_doc, e_date) values (201, 'doc 201', to_date('02.01.2010', 'DD.MM.YYYY')); insert into e(e_id, e_doc, e_date) values (202, 'doc 202', to_date('03.01.2010', 'DD.MM.YYYY')); insert into e(e_id, e_doc, e_date) values (203, 'doc 203', to_date('04.01.2010', 'DD.MM.YYYY')); insert into e(e_id, e_doc, e_date) values (204, 'doc 204', to_date('05.01.2010', 'DD.MM.YYYY')); insert into e(e_id, e_doc, e_date) values (205, 'doc 205', to_date('06.01.2010', 'DD.MM.YYYY')); insert into e(e_id, e_doc, e_date) values (206, 'doc 206', to_date('07.01.2010', 'DD.MM.YYYY')); insert into e(e_id, e_doc, e_date) values (207, 'doc 207', to_date('08.01.2010', 'DD.MM.YYYY')); insert into k(t_id, e_id) values (100, 200); insert into k(t_id, e_id) values (100, 201); insert into k(t_id, e_id) values (100, 202); insert into k(t_id, e_id) values (100, 203); insert into k(t_id, e_id) values (101, 203); insert into k(t_id, e_id) values (101, 204); select k.t_id, e.e_date, e.e_id, e.e_doc from e, k, t where k.e_id = e.e_id and k.t_id = t.t_id order by k.t_id, e.e_date desc; T_ID E_DATE E_ID E_DOC ---------- -------- ---------- ---------------- 100 04.01.10 203 doc 203 100 03.01.10 202 doc 202 100 02.01.10 201 doc 201 100 01.01.10 200 doc 200 101 05.01.10 204 doc 204 101 04.01.10 203 doc 203
The example query takes several hours in production.T_ID E_DOC_LIST ---------- ----------------------- 100 doc 200/doc 201/doc 202 101 doc 203/doc 204 Sample query: select t_id, e_doc_list from ( select k.t_id, row_number() over(partition by k.t_id order by k.t_id, e.e_date desc) r_num, rtrim( lag(e.e_doc, 0) over(partition by k.t_id order by k.t_id, e.e_date) || '/' || lag(e.e_doc, 1) over(partition by k.t_id order by k.t_id, e.e_date) || '/' || lag(e.e_doc, 2) over(partition by k.t_id order by k.t_id, e.e_date), '/') e_doc_list from e, k, t where k.e_id = e.e_id and k.t_id = t.t_id order by k.t_id, e.e_date desc ) where r_num = 1 ; T_ID E_DOC_LIST ---------- -------------------------------------------------- 100 doc 203/doc 202/doc 201 101 doc 204/doc 203
The r_num = 1 filter is applied quite late. Is there another way to generate the query or even review the tables.
For the sample query: ----------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | ----------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 6 | 468 | 6 (50)| 00:00:01 | |* 1 | VIEW | | 6 | 468 | 6 (50)| 00:00:01 | |* 2 | WINDOW SORT PUSHED RANK | | 6 | 216 | 6 (50)| 00:00:01 | | 3 | WINDOW SORT | | 6 | 216 | 6 (50)| 00:00:01 | | 4 | NESTED LOOPS | | 6 | 216 | 4 (25)| 00:00:01 | | 5 | MERGE JOIN | | 6 | 198 | 4 (25)| 00:00:01 | | 6 | TABLE ACCESS BY INDEX ROWID| E | 8 | 208 | 2 (0)| 00:00:01 | | 7 | INDEX FULL SCAN | E_PK | 8 | | 1 (0)| 00:00:01 | |* 8 | SORT JOIN | | 6 | 42 | 2 (50)| 00:00:01 | | 9 | INDEX FULL SCAN | K_I1 | 6 | 42 | 1 (0)| 00:00:01 | |* 10 | INDEX UNIQUE SCAN | T_PK | 1 | 3 | 0 (0)| 00:00:01 | ----------------------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 1 - filter("R_NUM"=1) 2 - filter(ROW_NUMBER() OVER ( PARTITION BY "K"."T_ID" ORDER BY "K"."T_ID",INTERNAL_FUNCTION("E"."E_DATE") DESC )<=1) 8 - access("K"."E_ID"="E"."E_ID") filter("K"."E_ID"="E"."E_ID") 10 - access("K"."T_ID"="T"."T_ID") and for query in production --------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| --------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 3118K| 425M| | 160K (1)| | 1 | VIEW | | 3118K| 425M| | 160K (1)| | 2 | SORT ORDER BY | | 3118K| 163M| 383M| 160K (1)| | 3 | WINDOW SORT PUSHED RANK| | 3118K| 163M| 383M| 160K (1)| | 4 | WINDOW SORT | | 3118K| 163M| 383M| 160K (1)| | 5 | HASH JOIN | | 3118K| 163M| 40M| 33991 (1)| | 6 | TABLE ACCESS FULL | E | 1053K| 28M| | 4244 (1)| | 7 | NESTED LOOPS | | 3118K| 80M| | 21918 (1)| | 8 | TABLE ACCESS FULL | T | 144K| 1829K| | 282 (2)| | 9 | INDEX RANGE SCAN | K_I1 | 22 | 308 | | 1 (0)| ---------------------------------------------------------------------------------------
TimWong765 wrote:
...
Table a contains 200,000 lines. (* this table is truncated and inserted several times a week *)You could be in one of the rare cases where the index should be rebuild, take a look in the following thread:
http://asktom.Oracle.com/pls/asktom/f?p=100:11:0:P11_QUESTION_ID:6601312252730 #69571308712887 (search for 'index of Sweeper')
Make sure that you have checked if you are in this case before going for an expensive index rebuild.Nicolas.
Maybe you are looking for
-
iMovie - Equalizer custom beyond Presets
I use iMovie 10.1.1. I'm looking for custom equalizer, beyond the 9 presets on the menu drop down. I read somewhere that you can access more than custom EQ sliders for each frequency, either by clicking on "Custom" in the drop down menu equalizer, or
-
Apple Watch + watch OS 2.2 + iOS 9.3
Hello dear support team! I'm one of the Estonian users Apple Watch, which cannot properly use Apple Watch after the Watch OS 2.2 update Disorders: 1) Runtastic App do to save not the pulse is more. Before the update it worked properly! It is a very b
-
Error 1310 during the installation of Adobe reader.
Vista Home premium. I tried a single repair for this error. I can't do a reinstall/upgrade as suggested I bought a disc of upgrade and it only let me do a full installation and not an upgrade.
-
print the allignment on hp photosmart 7520
I have a HP all-in-one printer - Photosmart 7520. I would like to know if it is possible to adjust the placement of the printing on the paper? The text is placed as it is expanded so that the header & foot are cut in two along the top and bottom of
-
VPN site-to-site initiated in one direction
Hello. We try to establish a VPN site-to site between two ASA firewalls, let's call them ASA1 and ASA2. Problem is that ASA1 cannot start the connection. ISAKMP of ASA1 packets reach ASA2, but removed by an unwritten rule. When ASA2 launches, everyth