Seeking workarounds to give effect of INSERT...SELECT...RETURNING
What is the most efficient way to get record counts from subqueries within an INSERT INTO () SELECT () statement on Oracle 11g? I feel like I'm too close to the code to see the obvious answer here.
Background:
I am building a dynamic data quality testing framework, wherein stored procedures call SQL blocks for specific tests from a table in accordance with the test identifier and boundary parameters passed in. The blocks: (a) log an entry for the test activity, (b) prepare a "should be" snapshot of the data in a staging table, (c) perform a source-to-target comparison, dropping discrepancies into a results table, and then (d) update the test activity record with the result counts.
Action (c) is accomplished by selecting a union of the "should be" data from a staging table and the "as is" data from a target table or MV, dropping all exact duplicate records so that only mismatches (errors) remain, and inserting those details in a results table, labeling each record with whether it comes from the source ("should be") or target ("as is") subquery. I am trying to not to hit the DB twice (performance concerns), so I am running the source and target rowcounts on the "should be" and "as is" subqueries using COUNT () OVER PARTITION. Currently I dump these counts into the results table, but if there are zero defects, there are no results records to dump them into. I want to select these counts into bind variables, but for some reason I am not succeeding.
I am currently trying to use the Method 2 workaround described in [http://www.oracle-developer.net/display.php?id=413|http://www.oracle-developer.net/display.php?id=413] , but can't seem to get my query block to adapt to the INSERT ALL format.
Here's a shell of the analysis block without trying to integrate the Method 2 workaround:
DECLARE
StartDate DATE;
EndDate DATE;
TEST_KEY NUMBER;
BEGIN
INSERT INTO TEST_EVENT_DETAIL
(TEST_EVENT_KEY,TEST_EVENT_DETAIL_KEY,COLUMN1,COLUMN2,COLUMN3,COLUMN4,
COLUMN5, COLUMN6)
SELECT
TEST_KEY as TEST_EVENT_KEY,
TEST_EVENT_DETAIL_SEQ.NEXTVAL AS TEST_EVENT_DETAIL_KEY,
RESULTS.TABLENAME as COLUMN1,
RESULTS.COLUMNNAME1 as COLUMN2,
RESULTS.COLUMNNAME2 as COLUMN3,
RESULTS.source_count as COLUMN4,
RESULTS.target_count as COLUMN5,
null as COLUMN6 -- there are more generic columns, this is just an example; columns not used by a particular test are filled with nulls
FROM
(SELECT MIN(TABLENAME) as TABLENAME,
min(source_count) as source_count,
min(target_count) as target_count,
COLUMNNAME1,
COLUMNNAME2
FROM
(SELECT TABLENAME as TABLENAME,
case when TABLENAME='SOURCE' then count(TABLENAME) over (partition by TABLENAME) else null end source_count,
case when TABLENAME='TARGET' then count(TABLENAME) over (partition by TABLENAME) else null end target_count,
COLUMNNAME1,
COLUMNNAME2
from
/** Source Data **/
SELECT 'SOURCE' as TABLENAME,
COLUMNNAME1,
COLUMNNAME2
FROM TEST_EVENT_STAGE A
WHERE A.TEST_EVENT_KEY=TEST_KEY
UNION ALL
/** Target Data **/
SELECT 'TARGET' as TABLENAME,
COLUMNNAME1,
COLUMNNAME2
FROM TABLENAME B
WHERE ______(criteria for target query goes here)_______
) TMP
GROUP BY COLUMNNAME1, COLUMNNAME2
HAVING COUNT(*) = 1 -- this drops out all records that don't match
ORDER BY COLUMNNAME1, COLUMNNAME2, TABLENAME ASC
) RESULTS;
END;What am I missing here? It should be simple to get these values into a variable, but whatever I try gives me nulls.
Figured it out,...needed to add a level and get MAX across all partitions, and then use a "zero defects" entry to capture it for later harvesting. (The "zero defects" entry is removed if there are other records for that test event stored in the details table.)
Here's what it evolved into:
DECLARE
vPROCESSSTARTTIME DATE;
vSTARTDATETIME DATE;
vENDDATETIME DATE;
vTESTEVENTKEY NUMBER;
source_count NUMBER;
target_count NUMBER;
BEGIN
INSERT INTO TEST_EVENT_DETAIL
(TEST_EVENT_KEY,TEST_EVENT_DETAIL_KEY,PROCESS_START_TIME,COLUMN1,
COLUMN2,COLUMN3,COLUMN4,COLUMN5,COLUMN6,COLUMN7,COLUMN8,COLUMN9,
COLUMN10,COLUMN11,COLUMN12,COLUMN13,COLUMN14,COLUMN15,COLUMN16,
COLUMN17,COLUMN18,COLUMN19,COLUMN20,COLUMN21,COLUMN22,COLUMN23,
COLUMN24,COLUMN25,COLUMN26,COLUMN27,COLUMN28,COLUMN29,COLUMN30)
SELECT
vTESTEVENTKEY as TEST_EVENT_KEY,
TEST_EVENT_DETAIL_SEQ.NEXTVAL AS TEST_EVENT_DETAIL_KEY,
vPROCESSSTARTTIME as PROCESS_START_TIME,
vSTARTDATETIME as COLUMN1,
vENDDATETIME as COLUMN2,
RESULTS.source_count as COLUMN3,
RESULTS.target_count as COLUMN4,
RESULTS.RECORD_SOURCE as COLUMN5,
RESULTS.columnname as COLUMN6,
RESULTS.columnname as COLUMN7,
--continue for the rest of the columns, null for anything unpopulated
NULL as COLUMN29,
NULL as COLUMN30
FROM
(SELECT MIN(RECORD_SOURCE) as RECORD_SOURCE,
min(source_count) as source_count,
min(target_count) as target_count,
columnname,
columnname,
--continue for the rest of the columns
FROM
(SELECT
MAX(source_count) OVER () as source_count,
MAX(target_count) OVER () as target_count,
RECORD_SOURCE,
columnname,
columnname,
--continue for the rest of the columns
FROM
(SELECT RECORD_SOURCE as RECORD_SOURCE,
case when TABLENAME='SOURCE' then count(RECORD_SOURCE) over (partition by RECORD_SOURCE) else 0 end source_count,
case when TABLENAME='TARGET' then count(RECORD_SOURCE) over (partition by RECORD_SOURCE) else 0 end target_count,
columnname,
columnname,
--continue for the rest of the columns
from
/** Source Data **/
Select * from
SELECT 'SOURCE' as RECORD_SOURCE,
A.COLUMN6 as columnname,
A.COLUMN7 as columnname,
--continue for the rest of the columns
FROM TEST_EVENT_STAGE A
WHERE A.TEST_EVENT_KEY=vTESTEVENTKEY
) src
UNION ALL
/** Target Data **/
Select * from
SELECT 'TARGET' as RECORD_SOURCE,
B.columnname,
B.columnname,
--continue for the rest of the columns
FROM target_tablename B
WHERE --criteria as needed
and B.whatever_DT >= vSTARTDATETIME
AND B.whatever_DT < vENDDATETIME
) tgt
UNION ALL
/** zero defects placeholder record **/
Select * from
SELECT 'ZERO' as RECORD_SOURCE,
NULL as columnname,
NULL as columnname,--continue for the rest of the columns
FROM dual C
) zero
) TMP
GROUP BY columnname,columnname,--continue for the rest of the columns
HAVING COUNT(*) = 1 -- this drops out all records that don't match
ORDER BY columnname,columnname,--continue for the rest of the columns
RECORD_SOURCE ASC
) RESULTS;
END;
Similar Messages
-
Smart scan not working with Insert Select statements
We have observed that smart scan is not working with insert select statements but works when select statements are execute alone.
Can you please help us to explain this behavior?There is a specific exadata forum - you would do better to post the question there: Exadata
I can't give you a definitive answer, but it's possible that this is simply a known limitation similar to the way that "Create table as select" won't run the select statement the same way as the basic select if it involves a distributed query.
Regards
Jonathan Lewis -
Poor performance and high number of gets on seemingly simple insert/select
Versions & config:
Database : 10.2.0.4.0
Application : Oracle E-Business Suite 11.5.10.2
2 node RAC, IBM AIX 5.3Here's the insert / select which I'm struggling to explain why it's taking 6 seconds, and why it needs to get > 24,000 blocks:
INSERT INTO WF_ITEM_ATTRIBUTE_VALUES ( ITEM_TYPE, ITEM_KEY, NAME, TEXT_VALUE,
NUMBER_VALUE, DATE_VALUE ) SELECT :B1 , :B2 , WIA.NAME, WIA.TEXT_DEFAULT,
WIA.NUMBER_DEFAULT, WIA.DATE_DEFAULT FROM WF_ITEM_ATTRIBUTES WIA WHERE
WIA.ITEM_TYPE = :B1
call count cpu elapsed disk query current rows
Parse 1 0.00 0.00 0 0 4 0
Execute 2 3.44 6.36 2 24297 198 36
Fetch 0 0.00 0.00 0 0 0 0
total 3 3.44 6.36 2 24297 202 36
Misses in library cache during parse: 1
Misses in library cache during execute: 2Also from the tkprof output, the explain plan and waits - virtually zero waits:
Rows Execution Plan
0 INSERT STATEMENT MODE: ALL_ROWS
0 TABLE ACCESS MODE: ANALYZED (BY INDEX ROWID) OF 'WF_ITEM_ATTRIBUTES' (TABLE)
0 INDEX MODE: ANALYZED (RANGE SCAN) OF 'WF_ITEM_ATTRIBUTES_PK' (INDEX (UNIQUE))
Elapsed times include waiting on following events:
Event waited on Times Max. Wait Total Waited
---------------------------------------- Waited ---------- ------------
library cache lock 12 0.00 0.00
gc current block 2-way 14 0.00 0.00
db file sequential read 2 0.01 0.01
row cache lock 24 0.00 0.01
library cache pin 2 0.00 0.00
rdbms ipc reply 1 0.00 0.00
gc cr block 2-way 4 0.00 0.00
gc current grant busy 1 0.00 0.00
********************************************************************************The statement was executed 2 times. I know from slicing up the trc file that :
exe #1 : elapsed = 0.02s, query = 25, current = 47, rows = 11
exe #2 : elapsed = 6.34s, query = 24272, current = 151, rows = 25
If I run just the select portion of the statement, using bind values from exe #2, I get small number of gets (< 10), and < 0.1 secs elapsed.
If I make the insert into an empty, non-partitioned table, I get :
call count cpu elapsed disk query current rows
Parse 1 0.00 0.00 0 0 0 0
Execute 1 0.01 0.08 0 137 53 25
Fetch 0 0.00 0.00 0 0 0 0
total 2 0.01 0.08 0 137 53 25and same explain plan - using index range scan on WF_Item_Attributes_PK.
This problem is part of testing of a database upgrade and country go-live. On a 10.2.0.3 test system (non-RAC), the same insert/select - using the real WF_Item_Attributes_Value table takes :
call count cpu elapsed disk query current rows
Parse 1 0.00 0.00 0 0 0 0
Execute 1 0.00 0.10 10 27 136 25
Fetch 0 0.00 0.00 0 0 0 0
total 2 0.00 0.10 10 27 136 25So I'm struggling to understand why the performance on the 10.2.0.4 RAC system is so much worse for this query, and why it's doing so many gets. Suggestions, thoughts, ideas welcomed.
I've verified system level things - CPUs weren't/aren't max'd out, no significant paging/swapping activity, run queue not long. AWR report for the time period shows nothing unusual.
further info on the objects concerned:
query source table :
WF_Item_Attributes_PK : unique index on Item_Type, Name. Index has 144 blocks, non-partitioned
WF_Item_Attributes tbl : non-partitioned, 160 blocks
insert destination table:
WF_Item_Attribute_Values:
range partitioned on Item_Type, and hash sub-partitioned on Item_Key
both executions of the insert hit the partition with the most data : 127,691 blocks total ; 8 sub-partitions with 15,896 to 16,055 blocks per sub-partition.
WF_Item_Attribute_Values_PK : unique index on columns Item_Type, Item_Key, Name. Range/hash partitioned as per table.
Bind values:
exe #1 : Item_Type (:B1) = OEOH, Item_Key (:B2) = 1048671
exe #2 : Item_Type (:B1) = OEOL, Item_Key (:B2) = 4253168
number of rows in WF_Item_Attribute_Values for Item_Type = OEOH : 1132587
number of rows in WF_Item_Attribute_Values for Item_Type = OEOL : 18763670
The non-RAC 10.2.0.3 test system (clone of Production from last night) has higher row counts for these 2.
thanks and regards
Ivanhi Sven,
Thanks for your input.
1) I guess so, but I haven't lifted the lid to delve inside the form as to which one. I don't think it's the cause though, as I got poor performance running the insert statement with my own value (same statement, using my own bind value).
2) In every execution plan I've seen, checked, re-checked, it uses a range scan on the primary key. It is the most efficient I think, but the source table is small in any case - table 160 blocks, PK index 144 blocks. So I think it's the partitioned destination table that's the problem - but we only see this issue on the 10.2.0.4 pre-production (RAC) system. The 10.2.0.3 (RAC) Production system doesn't have it. This is why it's so puzzling to me - the source table read is fast, and does few gets.
3) table storage details below - the Item_Types being used were 'OEOH' (fast execution) and 'OEOL' (slow execution). Both hit partition WF_ITEM49, hence I've only expanded the subpartition info for that one (there are over 600 sub-partitions).
============= From DBA_Part_Tables : Partition Type / Count =============
PARTITI SUBPART PARTITION_COUNT DEF_TABLESPACE_NAME
RANGE HASH 77 APPS_TS_TX_DATA
1 row selected.
============= From DBA_Tab_Partitions : Partition Names / Tablespaces =============
Partition Name TS Name High Value High Val Len
WF_ITEM1 APPS_TS_TX_DATA 'A1' 4
WF_ITEM2 APPS_TS_TX_DATA 'AM' 4
WF_ITEM3 APPS_TS_TX_DATA 'AP' 4
WF_ITEM47 APPS_TS_TX_DATA 'OB' 4
WF_ITEM48 APPS_TS_TX_DATA 'OE' 4
WF_ITEM49 APPS_TS_TX_DATA 'OF' 4
WF_ITEM50 APPS_TS_TX_DATA 'OK' 4
WF_ITEM75 APPS_TS_TX_DATA 'WI' 4
WF_ITEM76 APPS_TS_TX_DATA 'WS' 4
WF_ITEM77 APPS_TS_TX_DATA MAXVALUE 8
77 rows selected.
============= From dba_part_key_columns : Partition Columns =============
NAME OBJEC Column Name COLUMN_POSITION
WF_ITEM_ATTRIBUTE_VALUES TABLE ITEM_TYPE 1
1 row selected.
PPR1 sql> @q_tabsubpart wf_item_attribute_values WF_ITEM49
============= From DBA_Tab_SubPartitions : SubPartition Names / Tablespaces =============
Partition Name SUBPARTITION_NAME TS Name High Value High Val Len
WF_ITEM49 SYS_SUBP3326 APPS_TS_TX_DATA 0
WF_ITEM49 SYS_SUBP3328 APPS_TS_TX_DATA 0
WF_ITEM49 SYS_SUBP3332 APPS_TS_TX_DATA 0
WF_ITEM49 SYS_SUBP3331 APPS_TS_TX_DATA 0
WF_ITEM49 SYS_SUBP3330 APPS_TS_TX_DATA 0
WF_ITEM49 SYS_SUBP3329 APPS_TS_TX_DATA 0
WF_ITEM49 SYS_SUBP3327 APPS_TS_TX_DATA 0
WF_ITEM49 SYS_SUBP3325 APPS_TS_TX_DATA 0
8 rows selected.
============= From dba_part_key_columns : Partition Columns =============
NAME OBJEC Column Name COLUMN_POSITION
WF_ITEM_ATTRIBUTE_VALUES TABLE ITEM_KEY 1
1 row selected.
from DBA_Segments - just for partition WF_ITEM49 :
Segment Name TSname Partition Name Segment Type BLOCKS Mbytes EXTENTS Next Ext(Mb)
WF_ITEM_ATTRIBUTE_VALUES @TX_DATA SYS_SUBP3332 TblSubPart 16096 125.75 1006 .125
WF_ITEM_ATTRIBUTE_VALUES @TX_DATA SYS_SUBP3331 TblSubPart 16160 126.25 1010 .125
WF_ITEM_ATTRIBUTE_VALUES @TX_DATA SYS_SUBP3330 TblSubPart 16160 126.25 1010 .125
WF_ITEM_ATTRIBUTE_VALUES @TX_DATA SYS_SUBP3329 TblSubPart 16112 125.875 1007 .125
WF_ITEM_ATTRIBUTE_VALUES @TX_DATA SYS_SUBP3328 TblSubPart 16096 125.75 1006 .125
WF_ITEM_ATTRIBUTE_VALUES @TX_DATA SYS_SUBP3327 TblSubPart 16224 126.75 1014 .125
WF_ITEM_ATTRIBUTE_VALUES @TX_DATA SYS_SUBP3326 TblSubPart 16208 126.625 1013 .125
WF_ITEM_ATTRIBUTE_VALUES @TX_DATA SYS_SUBP3325 TblSubPart 16128 126 1008 .125
WF_ITEM_ATTRIBUTE_VALUES_PK @TX_IDX SYS_SUBP3332 IdxSubPart 59424 464.25 3714 .125
WF_ITEM_ATTRIBUTE_VALUES_PK @TX_IDX SYS_SUBP3331 IdxSubPart 59296 463.25 3706 .125
WF_ITEM_ATTRIBUTE_VALUES_PK @TX_IDX SYS_SUBP3330 IdxSubPart 59520 465 3720 .125
WF_ITEM_ATTRIBUTE_VALUES_PK @TX_IDX SYS_SUBP3329 IdxSubPart 59104 461.75 3694 .125
WF_ITEM_ATTRIBUTE_VALUES_PK @TX_IDX SYS_SUBP3328 IdxSubPart 59456 464.5 3716 .125
WF_ITEM_ATTRIBUTE_VALUES_PK @TX_IDX SYS_SUBP3327 IdxSubPart 60016 468.875 3751 .125
WF_ITEM_ATTRIBUTE_VALUES_PK @TX_IDX SYS_SUBP3326 IdxSubPart 59616 465.75 3726 .125
WF_ITEM_ATTRIBUTE_VALUES_PK @TX_IDX SYS_SUBP3325 IdxSubPart 59376 463.875 3711 .125
sum 4726.5
[the @ in the TS Name is my shortcode, as Apps stupidly prefixes every ts with "APPS_TS_"]
The Tablespaces used for all subpartitions are UNIFORM extent mgmt, AUTO segment_space_management ; LOCAL extent mgmt.regards
Ivan -
How to insert select columns from one internal table to another
Hi,
How to insert select columns from one internal table to another based on condition as we do from a standart table to internal table.
regards,
SriramHi,
If your question is for copying data from 1 int table to other ;
we can use
APPEND LINES OF it_1 TO it_2.
or if they have different columns then:
loop at it_1 into wa_it1.
move wa_it1-data to wa_it2-d1.
apped wa_it2 to it_2.
clear wa_it2.
endloop.
thnxz -
How to Insert-Select and Updade base table
Hi All,
How is the best way to do this?
I have a table A that has 1million rows.
I need to Insert-Select into table B from a Group by on table A,
and Update all rows in table A that were used into Insert with a flag.
(select a hundred from A and insert 10 thousands into B)
What to do?
1-Update table A with flag before Insert-Select?
2-Insert-Select group by into table B, before Update?
3-Another way?
Thanks in advance,
EdsonEither way. But you may find that updating the source flag first and then using that flag as part of your where clause when extracting rows to put in the destination table is a bit faster.
In any case, you will commit only once after all of the work is done. -
Error when included Order in Insert Select
Dear oracle guru's
I am working with Oracle 10g both forms and database . in one of my forms i try to insert values in a table from other table
the code is
insert into sstab(paramnam) select CP.Parameter_Object.Parameter_Name
from Customer_Parameters cp
order by cp_display_order;
earlier there was no order but to enhance further i added the order by command to the existing Insert-Select. But this threw an error while compiling the module itself .
Encounterd the symbol ORDER when expecting one of the ,;...
Kindly guide me in this regardd
with warm regards
ssrHi,
All DDL operations will automatically commit all the pending transaction.
But in the care of FORMS_DDL, if you are running an insert or update statement, then the pending transactions won't commit. For that you have to pass a DDL statement through FORMS_DDL.
If I am wrong, then please correct me.
Regards,
Manu.
Edited by: Manu. on Jan 7, 2010 5:57 PM -
Applying Effects to a Selection
I think I must be missing something and I'd swear I've done this before. Working on an audio project in the timeline and selecting a portion of the waveform to apply an effect... all is good until the clip is flattened. After the flatten the effect is applied to the entire clip. What's the deal? I am not sending this over from FCP. I am opening an AIFF and trying to add a plug-in just to the selected area. Would someone please describe the workflow or explain why the effect ultimately applies itself to the entire clip. Thanks!
G5, Dual 2, 2.5GB RAM Mac OS X (10.4.6)Here's a step-by-step for applying effects to a region of a file:
-Open the file in the waveform editor
-click-drag across the waveform to select the region
-process->Effects->whatever effect you want...to apply an effect to the selection
The effect is only applied to the selected region.
If you applied an effect that has a long tail (e.g. a reverb or a delay) then you will see the impact carry on after the right-hand edge of the selection area--that's just the way these sort of effects work.
If you really want a reverb within the selection region with no tail outside of the selection region, then copy the file, apply the reverb to the selection region, copy the selection region, then go to the un-effected file, put the playhead at the start of where your selection was and select edit->paste special->paste mix and select 100% clipboard and 0% original and you'll get what you want. It might help to put markers at the start and the end of the selection before you copy the file.
I hope that helps. -
Inserting carriage returns in a concatenated string
Hi.....
Does anyone know how to insert carriage returns within a concatenated string in a sql statement?
i.e. Select 'John'||'Smith' from dual
I'm trying to return:
John
Smith
as opposed to John Smith
Thanks,
~ChristineAs suggested chr(10) is what you need, but it's not carriage return, but line feed, carriage return is chr(13). See the difference :
TEST@db102 SQL> select 'John'||chr(10)||'Smith' from dual;
'JOHN'||CH
John
Smith
TEST@db102 SQL> ed
Wrote file afiedt.buf
1* select 'John'||chr(13)||'Smith' from dual
TEST@db102 SQL> /
'JOHN'||CH
Smith
TEST@db102 SQL> -
in the previous version of Number, the menu table in table options, there is an option that gives me the option: the Return key moves to next cell. I do not see this option in the new number. can you help me please?
Hi silvano,
If you use a regular pattern when entering values, press enter (return) after entering the last value in a row. That will take you to the first Body Cell of the next row.
Start in Cell B2
1 Tab 2 Tab 3 Enter
4 Tab 5 Tab 6 Enter
7 Tab 8 Tab 9 Enter
Now you are ready to type into B5 .
Another way that some people find easier is to enter one column at a time
Start at B2
1 enter
4 enter
7 enter
etc.
Now start with C2.
Use whatever suits your work flow.
Regards,
Ian. -
SELECT returns no result when there is a default namespace definition inXML
Hi,
I have a problem that my select doesn't return any result when there is a default namespace definition in my XML file.
I'm using oracle 11g release 1
XML file stored as a binary XML:
<SIMS xmlns="http://sims.ics.muni.cz" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://sims.ics.muni.cz jh_sims_matricni_vystupy_or.xsd">
<Vystup Datum="2006-07-18" Typ="2" Nazev="Poslední etapy" PocetStudentu="1" PocetStudii="2">
<Student RodneCislo="8001011001">
<Jmeno>Petr</Jmeno>
</Student>
</Vystup>
</SIMS>
This select return no result:
SELECT student.jmeno FROM jh_sims_bin_no_schema s, XMLTable('/SIMS/Vystup/Student' PASSING s.OBJECT_VALUE COLUMNS jmeno VARCHAR2(10) PATH 'Jmeno') student
When I remove default namespace definition (xmlns="http://sims.ics.muni.cz") everything works fine and the same SELECT returns "Petr". Also when the file is stored in object relational storage everything works fine!
<SIMS xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://sims.ics.muni.cz jh_sims_matricni_vystupy_or.xsd">
<Vystup Datum="2006-07-18" Typ="2" Nazev="Poslední etapy" PocetStudentu="1" PocetStudii="2">
<Student RodneCislo="8001011001">
<Jmeno>Petr</Jmeno>
</Student>
</Vystup>
</SIMS>
Thanks for any help!
Jan HrubyHi Jan,
You need to specify the default namespace of the document in the XMLNamespaces clause :
SELECT student.jmeno
FROM jh_sims_bin_no_schema s,
XMLTable(
XMLNamespaces(default 'http://sims.ics.muni.cz'),
'/SIMS/Vystup/Student'
PASSING s.OBJECT_VALUE
COLUMNS jmeno VARCHAR2(10) PATH 'Jmeno'
) student
; -
"Select Color Range" not working. "Warning: No pixels were selected" returned when attempting to use. Using Photoshop CS6 on a Mac running OS X Yosemite
Here are three screenshots in succession from trying to perform the color selection:
Dropbox - Screenshot 2015-02-12 14.57.40.png
Dropbox - Screenshot 2015-02-12 15.00.14(2).png
Dropbox - Screenshot 2015-02-12 15.01.00.png -
SELECT in SELECT returning multiple columns ?
10.2.0.3 version.
I am trying to tune this query
SELECT A.EMPLID, A.EFFDT, A.ACAD_PROG,
(SELECT A1.DESCR FROM PS_ACAD_PROG_TBL A1
WHERE A1.INSTITUTION = 'AUAO1' AND A1.ACAD_PROG = A.ACAD_PROG AND A1.EFFDT = (SELECT MAX (EFFDT) FROM PS_ACAD_PROG_TBL WHERE INSTITUTION = A1.INSTITUTION AND ACAD_PROG = A1.ACAD_PROG),
(SELECT A2.DESCRSHORT FROM PS_ACAD_PROG_TBL A2
WHERE A2.INSTITUTION = 'AUAO1' AND A2.ACAD_PROG = A.ACAD_PROG AND A2.EFFDT = (SELECT MAX (EFFDT) FROM PS_ACAD_PROG_TBL WHERE INSTITUTION = A2.INSTITUTION AND ACAD_PROG = A2.ACAD_PROG),
as you can see it reading the table PS_ACAD_PROG_TBL two time to get two cloumns DESCR (alias A1) and DESCRSHORT (alias A2) exactly with the same where condition.
I am trying to replace it with just one select returning multiple columns like this
SELECT A.EMPLID, A.EFFDT, A.ACAD_PROG,
(SELECT A1.DESCR, A1.DESCRSHORT FROM PS_ACAD_PROG_TBL A1
WHERE A1.INSTITUTION = 'AUAO1' AND A1.ACAD_PROG = A.ACAD_PROG AND A1.EFFDT = (SELECT MAX (EFFDT) FROM PS_ACAD_PROG_TBL WHERE INSTITUTION = A1.INSTITUTION AND ACAD_PROG = A1.ACAD_PROG),
but I am getting ORA-00913: too many values.
Please help on how to get around this. Thanks in advance.William,
On similar lines I am struggling with the below query based on your suggestions.
SQL*Plus: Release 9.2.0.1.0 - Production on Wed Aug 5 14:17:21 2009
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> WITH arch_dup AS
2 (SELECT a.file_id,
3 a.sale_start,
4 a.activity_start,
5 a.activity_end,
6 a.item_code_cust,
7 a.division,
8 (SELECT MAX (DISTINCT (NVL (b.advertised, 'No')))
9 FROM ah_cust_gis_arch_stg b
10 WHERE b.file_id = a.file_id
11 AND NVL (b.sale_start, 'NULL') = NVL (a.sale_start, 'NULL')
12 AND NVL (b.activity_start, 'NULL') = NVL (a.activity_start, 'NULL')
13 AND NVL (b.activity_end, 'NULL') = NVL (a.activity_end, 'NULL')
14 AND b.item_code_cust = a.item_code_cust
15 AND b.division = a.division) advertised,
16 COUNT (*)
17 FROM ah_cust_gis_arch_stg a
18 WHERE a.file_id = 209
19 AND a.status_id = 21
20 GROUP BY a.file_id, a.sale_start, a.activity_start, a.activity_end, a.item_code_cust, a.d
ivision
21 HAVING COUNT (*) > 1)
22 SELECT dup.*,
23 (SELECT activity_id
24 FROM (SELECT activity_id,
25 ROW_NUMBER () OVER (ORDER BY (activity_retail / activity_mult)) rnk
26 FROM ah_cust_gis_arch_stg
27 WHERE status_id = 21
28 AND NVL (sale_start, 'NULL') = NVL (dup.sale_start, 'NULL')
29 AND NVL (activity_start, 'NULL') = NVL (dup.activity_start, 'NULL')
30 AND NVL (activity_end, 'NULL') = NVL (dup.activity_end, 'NULL')
31 AND item_code_cust = dup.item_code_cust
32 AND division = dup.division
33 AND file_id = 209
34 AND UPPER (NVL (advertised, 'N')) = dup.advertised)
35 WHERE rnk = 1) activity_id
36 FROM arch_dup dup;
AND UPPER (NVL (advertised, 'N')) = dup.advertised)
ERROR at line 34:
ORA-00904: "DUP"."ADVERTISED": invalid identifierCan you throw some light on what to do to make the outer query columns available to inner query?
Thanks,
Raj. -
Insert, select and create table as give different results
Hi all
I have a strange situation with this three cases:
1) select statement: SELECT (...)
2) insert statement with that same select as above: INSERT INTO SELECT (...)
3) create table statement again with that same select: CREATE TABLE AS SELECT (...)
Each of these cases produce different number of rows (first one 24, second 108 and third 58). What's more the data for second and third case doesn't have any sense with what they should return. The first case returns good results.
One interesting thing is that select uses "UNION ALL" between 2 queries. When simple UNION is used, everything works fine and all three cases return 24 rows. Also if each query is run seaprately, they work fine.
Anyone encountered something like this? (before i create an SR :)
Database is 10.2.0.2 on AIX 5.3. It's a data warehouse.
Edited by: dsmoljanovic on Dec 10, 2008 3:57 PMI understand UNION vs UNION ALL. But that doesn't change the fact that same SELECT should return same set of rows wether in INSERT, CREATE TABLE AS or a simple SELECT.
DB version is 10.2.0.2.
Here is the SQL:
INSERT INTO TMP_TRADING_PROM_BM_OSTALO
select
5 AS VRSTA_PLANIRANJA_KLJUC, u1.UNOS_KLJUC, t1.TRADING_TIP_KLJUC, i1.IZVOR_KLJUC, m1.ITEMNAME AS MJESEC,
l1.PLAN AS IZNOS, l1.TEKUA AS TEKUCA, l1.PROLA AS PROSLA, l1.PLANTEKUA_ AS IZNOS_TEKUCA, l1.PLANPROLA_ AS IZNOS_PROSLA, l1.TEKUAPROLA_ AS TEKUCA_PROSLA, l1.DATUM_UCITAVANJA
from
HR_SP_PLAN.L_12_ET_PROMETI_I_BRUTO_MARZA l1,
select
m1.ITEMIID, m1.ITEMNAME
from
HR_SP_PLAN.L_12_IT_4_MJESECI m1
where
UPPER (m1.ITEMNAME) NOT LIKE '%KVARTAL%' AND UPPER (m1.ITEMNAME) NOT LIKE '%GODINA%' AND UPPER (m1.ITEMNAME) NOT LIKE '%PROC%' and
m1.DATUM_UCITAVANJA = to_date('24.11.2008','dd.mm.yyyy')
union all
select -99, null from dual
) m1,
HR_SP_PLAN.L_12_IT_5_SEKTORI l2,
HR_SP_PLAN.L_12_IT_2_TIPOVI_OSTALO l3, HR_SP_PLAN.D_UNOS u1, HR_SP_PLAN.D_TRADING_TIP t1, HR_SP_PLAN.L_12_IT_1_PROMET_I_BM_OSTALO p1, HR_SP_PLAN.D_IZVOR i1
where
l1.ELIST = l2.ITEMIID and
l2.ITEMNAME = u1.UNOS_NAZIV and u1.USER_KLJUC = 12 and l2.DATUM_UCITAVANJA = to_date('24.11.2008','dd.mm.yyyy') and
l1.DIMENSION_1_PROMET = p1.ITEMIID and
p1.ITEMNAME = i1.IZVOR_NAZIV and i1.USER_KLJUC = 12 and p1.DATUM_UCITAVANJA = to_date('24.11.2008','dd.mm.yyyy') and
nvl(l1.DIMENSION_4_MJESEC , -99) = m1.ITEMIID and
l1.DIMENSION_2_TIPOVI = l3.ITEMIID and
l3.ITEMNAME = t1.TRADING_TIP_NAZIV and l3.DATUM_UCITAVANJA = to_date('24.11.2008','dd.mm.yyyy') and
l1.DATUM_UCITAVANJA = to_date('24.11.2008','dd.mm.yyyy') and
'PROC' = 'PLAN'
union all
select
4 AS VRSTA_PLANIRANJA_KLJUC, u1.UNOS_KLJUC, t1.TRADING_TIP_KLJUC, i1.IZVOR_KLJUC, m1.ITEMNAME AS MJESEC,
l1.PROCJENA AS IZNOS, l1.TEKUA AS TEKUCA, l1.PROLA AS PROSLA, l1.PROCJENATEKUA_ AS IZNOS_TEKUCA, l1.PROCJENAPROLA_ AS IZNOS_PROSLA, l1.TEKUAPROLA_ AS TEKUCA_PROSLA, l1.DATUM_UCITAVANJA
from
HR_SP_PLAN.L_13_ET_PROMETI_I_BRUTO_MARZA l1,
select
m1.ITEMIID, m1.ITEMNAME
from
HR_SP_PLAN.L_13_IT_4_MJESECI m1
where
UPPER (m1.ITEMNAME) NOT LIKE '%KVARTAL%' AND UPPER (m1.ITEMNAME) NOT LIKE '%GODINA%' AND UPPER (m1.ITEMNAME) NOT LIKE '%PROC%' and
nvl(ceil(to_number(m1.ITEMNAME)/3), mod(4, 5)) = mod(4, 5) and m1.DATUM_UCITAVANJA = to_date('24.11.2008','dd.mm.yyyy')
union all
select -99, null from dual
) m1,
HR_SP_PLAN.L_13_IT_5_SEKTORI l2, HR_SP_PLAN.L_13_IT_2_TIPOVI_OSTALO l3,
HR_SP_PLAN.D_UNOS u1, HR_SP_PLAN.D_TRADING_TIP t1,
HR_SP_PLAN.L_13_IT_1_PROMET_I_BM_OSTALO p1, HR_SP_PLAN.D_IZVOR i1
where
l1.ELIST = l2.ITEMIID and
l2.ITEMNAME = u1.UNOS_NAZIV and u1.USER_KLJUC = 13 and l2.DATUM_UCITAVANJA = to_date('24.11.2008','dd.mm.yyyy') and
l1.DIMENSION_1_PROMET = p1.ITEMIID and
p1.ITEMNAME = i1.IZVOR_NAZIV and i1.USER_KLJUC = 13 and p1.DATUM_UCITAVANJA = to_date('24.11.2008','dd.mm.yyyy') and
nvl(l1.DIMENSION_4_MJESEC , -99) = m1.ITEMIID and
l1.DIMENSION_2_TIPOVI = l3.ITEMIID and
l3.ITEMNAME = t1.TRADING_TIP_NAZIV and l3.DATUM_UCITAVANJA = to_date('24.11.2008','dd.mm.yyyy') and
l1.DATUM_UCITAVANJA = to_date('24.11.2008','dd.mm.yyyy') and
'PROC' = 'PROC'; -
Help in query required – Insert, Select in same table
Hi All
I need your help on writing the queries effectively.
Oracle Version: 10.2.0.3.0
OS: UNIX
I have a table METRICS_TBL as mentioned below.
CYCLE_DATE METRICS VALUE
08/17/2008 COST-TV 100
08/17/2008 COST-NEWSPAPER 50
08/17/2008 COST-POSTALMAIL 25
08/17/2008 PROD-TV 10
08/17/2008 PROD-NEWSPAPER 25
08/17/2008 PROD-POSTALMAIL 5
Based on the above data, I need to append (Insert into METRICS_TBL select from METRICS_TBL) the same table with the records as mentioned below.
08/17/2008 COSTPERPROD-TV 10
08/17/2008 COSTPERPROD-NEWSPAPER 2
08/17/2008 COSTPER PROD-POSTALMAIL 5
Basically, I need to calculate Cost per Product for each category. Depending upon the available metrics, metrics also should be changed like COSTPERPROD and values should be Cost/prod under each category.
Can somebody help me with the query.
ThanksSQL> WITH t AS
2 (
3 SELECT TO_DATE('8/17/2008', 'MM/DD/YYYY') AS CYCLE_DATE, 'COST-TV' AS METRICS, 100 AS VALUE
4 FROM DUAL
5 UNION ALL
6 SELECT TO_DATE('08/17/2008', 'MM/DD/YYYY'), 'COST-NEWSPAPER', 50
7 FROM DUAL
8 UNION ALL
9 SELECT TO_DATE('08/17/2008', 'MM/DD/YYYY'), 'COST-POSTALMAIL', 25
10 FROM DUAL
11 UNION ALL
12 SELECT TO_DATE('08/17/2008', 'MM/DD/YYYY'), 'PROD-TV', 10
13 FROM DUAL
14 UNION ALL
15 SELECT TO_DATE('08/17/2008', 'MM/DD/YYYY'), 'PROD-NEWSPAPER', 25
16 FROM DUAL
17 UNION ALL
18 SELECT TO_DATE('08/17/2008', 'MM/DD/YYYY'), 'PROD-POSTALMAIL', 5
19 FROM DUAL)
20 SELECT COST.CYCLE_DATE, 'COSTPERPROD-' || SUBSTR(COST.metrics, 6) AS Metrics,
21 COST.VALUE / prod.VALUE AS COSTPERPROD
22 FROM t COST, t prod
23 WHERE COST.CYCLE_DATE = PROD.CYCLE_DATE
24 AND COST.metrics LIKE 'COST-%'
25 AND prod.metrics LIKE 'PROD-%'
26 AND SUBSTR(COST.metrics, 6) = SUBSTR(prod.metrics, 6)
27 /
CYCLE_DA METRICS COSTPERPROD
17.08.08 COSTPERPROD-NEWSPAPER 2
17.08.08 COSTPERPROD-POSTALMAIL 5
17.08.08 COSTPERPROD-TV 10 -
Provisioning Profiles Generation gives "Unknown Error" after Selecting Members
Well, I can no longer generate provisioning profiles because it gives an unknown error after selecting members and clicking continue. Any workarounds?
They mentioned when I called that the (-18) error is a network error because of their activation servers being down at this time. They said the activation servers are used to authenticate restores through iTunes for the iPhone. It should be back up tonight or tomorrow sometime according to support.
So if its not back up by tomorrow I will call again. Thanks for the help.
Maybe you are looking for
-
Where is the Picture-In-Picture function?
Hi, where can I find the Picture-In-Picture function in the new version of iMovie (10.0) ? In iMovie '11 (9.0) I only had to drag the clip over another one and choose the "Picture in Picture" option. How can I do this in the new version? I hope you c
-
How can I get rid of my adobe account it is of no use to me
i set up adobe ydy and paid for it but I am npy at all happy and would like to get rid of it with a full refund
-
Zen Micro "The selected items cannot be edited.Please try aga
When using the software to organise tracks eg assigning genre's to a new set of tracks i frequently get the above message. It then reappears for numerous occasions and takes ages to get to the end of. Often the player them won't undock and i have to
-
Motion file missing data after MM export
Hello, after finishing a project I exported it using Media Manager. When I reopened the newly created project, I noticed that all Motion clips where missing the video layer. I used Motion to blur out some faces and the blur is still there but I'm mis
-
Calling transaction with webgui takes forever on some workstation
Hi, I am calling transaction CV03N via webgui from webdynpro application. The problem is on some workstation it takes forever to load the screen with transaction details. For other it works fine. Did anyone come across this situation? Is there anythi