Stragg Distinct
Hi,
My DB is 9i.
I run a script that deletes all records from a table, and then repopulates based on a SQL insert.
This works fine.
I try to run the same combination but with...
BEGIN
END;...around the code, all other things being equal, and the script errors, complaining that my combination of stragg and distinct is not valid.
"ORA-06550: line 36, column 22:
PL/SQL: ORA-30482: DISTINCT option not allowed for this function
ORA-06550: line 5, column 1:
PL/SQL: SQL Statement ignored"
This being the offending line>
, apps.stragg(distinct substr(cmt_code,1,2)) parent_typesBut it does work as pure SQL....
Stragg, being a string aggregation text summary function that I picked up courtesy of 'Ask Tom' - shameless plug!
http://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:2196162600402
My full code, is below - anyone have any idea why this would fail in an anonymous block run as exactly the same user???
Thanks for your time,
Robert
begin
delete cust.xx_eris_users_all;
insert into cust.xx_eris_users_all
(RAW_ENCRYPTED_KEY,
NAME,
E_MAIL,
COST_CENTRES,
NUM_COST_CENTRES,
PARENT_CODES,
PARENT_TYPES,
NUM_OF_PARENTS,
PERIOD_NAME,
PERIOD_NUM,
PERIOD_YEAR,
QUARTER_NUM
(select UTL_RAW.CAST_TO_RAW(isis.inner_text_link_1) raw_encrypted_key
, isis.inner_attribute_1 name
, isis.inner_attribute_2 e_mail
, apps.stragg(eris.cost_centre) cost_centres
, count(eris.cost_centre) num_cost_centres
, inna.parent_codes
, inna.parent_types
, count(inna.parent_codes) num_of_parents
, to_char(add_months(sysdate,-1),'MON-YY') period_name
, prd.period_num
, prd.period_year
, prd.quarter_num
from cust.xx_isis_all isis
, gl.gl_periods prd
, CUST.XX_ERIS_COST_CENTRE_SECURE_MV eris
, (select encrypted_key
, apps.stragg(cmt_code) parent_codes
, apps.stragg(distinct substr(cmt_code,1,2)) parent_types
from CUST.XX_ERIS_CMT_SECURE_MV eriscmt
group by
encrypted_key) inna
where isis.isis_protocol_id = 'XX_ERIS_USER'
and isis.inner_attribute_1 <> 'ALL'
--and isis.inner_attribute_1 = 'Robert Angel'
and eris.encrypted_key(+) = isis.inner_text_link_1
and inna.encrypted_key(+) = isis.inner_text_link_1
and prd.period_name = to_char(add_months(sysdate,-1),'MON-YY')
group by
UTL_RAW.CAST_TO_RAW(isis.inner_text_link_1)
, isis.inner_attribute_1
, isis.inner_attribute_2
, inna.parent_codes
, inna.parent_types
, prd.period_num
, prd.period_year
, prd.quarter_num);
end;Edited by: Robert Angel on 11-Nov-2010 02:02 - Added Ask Tom link to summary function
In the same page search for the post dated "November 23, 2009". Tom, has provided an alternative to this problem.
Alternatively you can code two separate functions one performs distinct and one doesn't. Something like this.
SQL> select * from v$version;
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
PL/SQL Release 10.2.0.4.0 - Production
CORE 10.2.0.4.0 Production
TNS for 64-bit Windows: Version 10.2.0.4.0 - Production
NLSRTL Version 10.2.0.4.0 - Production
SQL> create or replace type string_agg_nodist_type as object
2 (
3 total varchar2(4000),
4
5 static function
6 ODCIAggregateInitialize(sctx IN OUT string_agg_nodist_type )
7 return number,
8
9 member function
10 ODCIAggregateIterate(self IN OUT string_agg_nodist_type ,
11 value IN varchar2 )
12 return number,
13
14 member function
15 ODCIAggregateTerminate(self IN string_agg_nodist_type ,
16 returnValue OUT varchar2,
17 flags IN number)
18 return number,
19
20 member function
21 ODCIAggregateMerge(self IN OUT string_agg_nodist_type ,
22 ctx2 IN string_agg_nodist_type)
23 return number
24
25 );
26 /
Type created.
SQL> create or replace type body string_agg_nodist_type
2 is
3
4 static function ODCIAggregateInitialize(sctx IN OUT string_agg_nodist_type )
5 return number
6 is
7 begin
8 sctx := string_agg_nodist_type ( null );
9 return ODCIConst.Success;
10 end;
11
12 member function ODCIAggregateIterate(self IN OUT string_agg_nodist_type ,
13 value IN varchar2 )
14 return number
15 is
16 begin
17 self.total := self.total || ',' || value;
18 return ODCIConst.Success;
19 end;
20
21 member function ODCIAggregateTerminate(self IN string_agg_nodist_type ,
22 returnValue OUT varchar2,
23 flags IN number)
24 return number
25 is
26 begin
27 returnValue := ltrim(self.total,',');
28 return ODCIConst.Success;
29 end;
30
31 member function ODCIAggregateMerge(self IN OUT string_agg_nodist_type ,
32 ctx2 IN string_agg_nodist_type)
33 return number
34 is
35 begin
36 self.total := self.total || ctx2.total;
37 return ODCIConst.Success;
38 end;
39
40
41 end;
42 /
Type body created.
SQL>
SQL> create or replace type string_agg_dist_type as object
2 (
3 total varchar2(4000),
4
5 static function
6 ODCIAggregateInitialize(sctx IN OUT string_agg_dist_type )
7 return number,
8
9 member function
10 ODCIAggregateIterate(self IN OUT string_agg_dist_type ,
11 value IN varchar2 )
12 return number,
13
14 member function
15 ODCIAggregateTerminate(self IN string_agg_dist_type ,
16 returnValue OUT varchar2,
17 flags IN number)
18 return number,
19
20 member function
21 ODCIAggregateMerge(self IN OUT string_agg_dist_type ,
22 ctx2 IN string_agg_dist_type)
23 return number
24
25 );
26 /
Type created.
SQL>
SQL> create or replace type body string_agg_dist_type
2 is
3
4 static function ODCIAggregateInitialize(sctx IN OUT string_agg_dist_type )
5 return number
6 is
7 begin
8 sctx := string_agg_dist_type ( null );
9 return ODCIConst.Success;
10 end;
11
12 member function ODCIAggregateIterate(self IN OUT string_agg_dist_type ,
13 value IN varchar2 )
14 return number
15 is
16 begin
17 if instr(nvl(self.total,' '), value,1) = 0
18 then
19 self.total := self.total || ',' || value;
20 else
21 self.total := self.total;
22 End If;
23 return ODCIConst.Success;
24 end;
25
26 member function ODCIAggregateTerminate(self IN string_agg_dist_type ,
27 returnValue OUT varchar2,
28 flags IN number)
29 return number
30 is
31 begin
32 returnValue := ltrim(self.total,',');
33 return ODCIConst.Success;
34 end;
35
36 member function ODCIAggregateMerge(self IN OUT string_agg_dist_type ,
37 ctx2 IN string_agg_dist_type)
38 return number
39 is
40 begin
41 self.total := self.total || ctx2.total;
42 return ODCIConst.Success;
43 end;
44
45
46 end;
47 /
Type body created.
SQL>
SQL>
SQL> CREATE or replace
2 FUNCTION stragg_nodistinct(input varchar2 )
3 RETURN varchar2
4 PARALLEL_ENABLE AGGREGATE USING string_agg_nodist_type;
5 /
Function created.
SQL>
SQL> CREATE or replace
2 FUNCTION stragg_distinct(input varchar2 )
3 RETURN varchar2
4 PARALLEL_ENABLE AGGREGATE USING string_agg_dist_type;
5 /
Function created.
SQL> begin
2 for i in (
3 with t
4 as
5 (
6 select 1 empno, 'hello' name from dual union all
7 select 1, 'hello' from dual union all
8 select 1, 'world' from dual union all
9 select 2, 'abc' from dual union all
10 select 2, 'dual' from dual
11 )
12 select empno, stragg_nodistinct(name) nodistinct_string, stragg_distinct(name) distinct_string from t
13 group by empno
14 )
15 Loop
16 dbms_output.put_line('Empno : ' || i.empno);
17 dbms_output.put_line('No distinct string : ' || i.nodistinct_string);
18 dbms_output.put_line('Distinct String : ' || i.distinct_string);
19 end loop;
20 end;
21 /
Empno : 1
No distinct string : hello,hello,world
Distinct String : hello,world
Empno : 2
No distinct string : abc,dual
Distinct String : abc,dual
PL/SQL procedure successfully completed.
SQL> spool offHope this helps.
Regards
Raj
Similar Messages
-
Search an ID in concatenated by stragg
Hi there,
Oracle Database 11g Release 11.1.0.7.0 - 64bit Production
PL/SQL Release 11.1.0.7.0 - Production
Sample data
with person as(
select 1 as pid, 'person1' as name from dual union all
select 2 as pid, 'person2' as name from dual union all
select 3 as pid, 'person3' as name from dual union all
select 4 as pid, 'person4' as name from dual union all
select 5 as pid, 'person5' as name from dual union all
select 6 as pid, 'person6' as name from dual
function_type as (
select 1 as ftid, 'function1' as name from dual union all
select 2 as ftid, 'function2' as name from dual union all
select 3 as ftid, 'function3' as name from dual union all
select 4 as ftid, 'function4' as name from dual union all
select 5 as ftid, 'function5' as name from dual union all
select 11 as ftid, 'function11' as name from dual
person_function_types as(
select 1 as pid, 1 as ftid from dual union all
select 1 as pid, 2 as ftid from dual union all
select 1 as pid, 3 as ftid from dual union all
select 2 as pid, 1 as ftid from dual union all
select 2 as pid, 5 as ftid from dual union all
select 3 as pid, 2 as ftid from dual union all
select 3 as pid, 3 as ftid from dual union all
select 3 as pid, 4 as ftid from dual union all
select 4 as pid, 5 as ftid from dual union all
select 5 as pid, 1 as ftid from dual union all
select 6 as pid, 11 as ftid from dual
person_function_view as(
select p.pid,
p.name,
stragg(distinct ft.ftid) as function_ids,
stragg(distinct ft.name) as function_types
from person_function_types pft
left join person p
on p.pid = pft.pid
left join function_type ft
on ft.ftid = pft.ftid
group by p.name
select pfv.name,
pfv.function_types
from person_function_view pfv
where pfv.function_ids like '%1%'
Problem
The result of this query should be person all persons with function_ids containing 1.
How ever the result of this query returns person6 containing function_id 11.
Understandable that 11 is like %1% ... how can I avoid this?
Thanks in advance!
Kind regards,
MetroickhaHi,
you can use regular expression.
Actually I could not test completely your query as I don't have STRAGG in my DB. There are several new alternatives to STRAGG. On 11g you can use LISTAGG.
Anyway assuming that using STRAGG after the comma you have one space you can do in this way:
select pfv.name,
pfv.function_types
from person_function_view pfv
where regexp_like(pfv.function_ids ,'(^|, )1(,|$)');If STRAGG don't put a space after the comma then remove the space after the comma in the regular expression pattern:
where regexp_like(pfv.function_ids ,'(^|,)1(,|$)');Regards.
Al -
Order by clause slows down my query
Greetings!!!
I need an advice on how can i make the query below run faster preserving the order by fields.I have only 8000 records but it gives the output in 21.8 sec.
SELECT
ORDER_ITEM.OI_ITEM_ID,
ORDER_ITEM.OI_SEQ,
GEN_ORDER_NUMBER_OPERATOR.GONO_ORDER_NUMBER_ID,
ORDER_ITEM.OI_ORDER_NUMBER_OPER_ID,
ORDER_ITEM.OI_ITEM_CODE,
ORDER_ITEM.OI_ITEM_DESC,
ORDER_ITEM.OI_ITEM_SIZE_ID,
ORDER_ITEM.OI_QTY,
(VIEW_SUM_ITEM_SHIPMENT_QTY.TOTAL_QTY_SHIPPED-ORDER_ITEM.OI_QTY) BALANCE_SHIP_QTY,
ORDER_ITEM.OI_DELVERY_DATE,
ORDER_ITEM.OI_ENTRY_DATE,
(round((select sysdate from sys.dual)-
ORDER_ITEM.OI_ENTRY_DATE)) no_days_passed,
ORDER_ITEM.OI_SALES_CONTRACT_ITEM_FLAG,
ORDER_ITEM.OI_ITEM_DESCC,
ORDER_ITEM.OI_DESIGNER_ID OI_DESIGNER_ID,
ORDER_ITEM.OI_FABRIC_GROUP_CODE,
ORDER_ITEM.OI_UM_ID,
ORDER_ITEM.OI_GROUP_CODE,
ORDER_ITEM.OI_GENRE_ID,
ORDER_ITEM.OI_ORDER_NUMBER_OPER_PART_ID,
ORDER_ITEM.OI_THEME_GROUP_CODE,
ORDER_ITEM.OI_THEME_DESC,
ORDER_ITEM.OI_ITEM_STATUS_ID,
ORDER_ITEM.OI_BARCODE,
SIZE_TEMPLATE.ST_SIZETEMPLATECODE,
SIZE_TEMPLATE.ST_SIZETEMPLATEDESC,
SIZE_TEMPLATE.ST_COL1,
SIZE_TEMPLATE.ST_COL2,
SIZE_TEMPLATE.ST_COL3,
SIZE_TEMPLATE.ST_COL4,
SIZE_TEMPLATE.ST_COL5,
SIZE_TEMPLATE.ST_COL6,
SIZE_TEMPLATE.ST_COL7,
SIZE_TEMPLATE.ST_COL8,
SIZE_TEMPLATE.ST_COL9,
SIZE_TEMPLATE.ST_COL10,
SIZE_TEMPLATE.ST_COL11,
SIZE_TEMPLATE.ST_COL12,
STAFF.S_STAFFNAMEC,
STAFF.S_STAFFCODE,
STAFF.S_STAFFNAMEE,
UNIT_MEASUREMENT.UM_UNIT_CODE, ITEM_GENRE.IG_DESC_ENG,
ORDER_ITEM_STATUS.OIS_STATUS_DESC,
MIN(VIEW_ORDER_ITEM_PART.OIP_GROUP_CODE)MIN_OIP_GROUP_CODE,
STRAGG( DISTINCT VIEW_ORDER_ITEM_PART.F_SHORTCODEC)STRAGG_F_SHORTCODEC,
STRAGG(DISTINCT VIEW_ORDER_ITEM_PART.S_STAFFNAMEC)STRAGG_QCNAME,
STRAGG(DISTINCT VIEW_ORDER_ITEM_PART.F_FABRIC_DESC_CHN)STRAGG_FABRIC,
ORDER_ITEM.OI_REMARKS,
ORDER_ITEM.OI_HSCODE,
ORDER_ITEM.OI_CATEGORY,
ORDER_ITEM.OI_CAT,
ORDER_ITEM.QCS_CATEGORY_ID,
QUOTA_CATEGORY_STANDARD.QCS_CATEGORY_CODE,
ORDER_ITEM.OI_ORDER_TYPE
FROM ORDER_ITEM, SIZE_TEMPLATE, STAFF, UNIT_MEASUREMENT, ITEM_GENRE,ORDER_ITEM_STATUS,VIEW_ORDER_ITEM_PART,GEN_ORDER_NUMBER_OPERATOR,VIEW_SUM_ITEM_SHIPMENT_QTY,QUOTA_CATEGORY_STANDARD
WHERE ((ORDER_ITEM.OI_ITEM_SIZE_ID = SIZE_TEMPLATE.ST_SIZETEMPLATE_ID(+))
AND (ORDER_ITEM.OI_DESIGNER_ID = STAFF.S_STAFF_ID(+))
AND (ORDER_ITEM.OI_UM_ID = UNIT_MEASUREMENT.UM_UNIT_ID(+))
AND (ORDER_ITEM.OI_GENRE_ID = ITEM_GENRE.IG_GENRE_ID(+))
AND (ORDER_ITEM.OI_ITEM_STATUS_ID=ORDER_ITEM_STATUS.OIS_STATUS_ID(+))
AND (ORDER_ITEM.OI_ITEM_ID=VIEW_ORDER_ITEM_PART.OIP_ITEM_ID(+))
AND (ORDER_ITEM.QCS_CATEGORY_ID=QUOTA_CATEGORY_STANDARD.QCS_CATEGORY_ID(+))
AND (ORDER_ITEM.OI_ITEM_ID=VIEW_SUM_ITEM_SHIPMENT_QTY.OI_ITEM_ID(+))
AND (ORDER_ITEM.OI_ORDER_NUMBER_OPER_ID = GEN_ORDER_NUMBER_OPERATOR.GONO_ORDER_NUMBER_OPER_ID(+)))
GROUP BY
ORDER_ITEM.OI_ITEM_ID,
ORDER_ITEM.OI_SEQ,
GEN_ORDER_NUMBER_OPERATOR.GONO_ORDER_NUMBER_ID,
ORDER_ITEM.OI_ORDER_NUMBER_OPER_ID,
ORDER_ITEM.OI_ITEM_CODE,
ORDER_ITEM.OI_ITEM_DESC,
ORDER_ITEM.OI_ITEM_SIZE_ID,
ORDER_ITEM.OI_QTY,
(VIEW_SUM_ITEM_SHIPMENT_QTY.TOTAL_QTY_SHIPPED-ORDER_ITEM.OI_QTY),
ORDER_ITEM.OI_DELVERY_DATE,
ORDER_ITEM.OI_ENTRY_DATE,
ORDER_ITEM.OI_SALES_CONTRACT_ITEM_FLAG,
ORDER_ITEM.OI_ITEM_DESCC,
ORDER_ITEM.OI_DESIGNER_ID,
ORDER_ITEM.OI_FABRIC_GROUP_CODE,
ORDER_ITEM.OI_UM_ID,
ORDER_ITEM.OI_GROUP_CODE,
ORDER_ITEM.OI_GENRE_ID,
ORDER_ITEM.OI_ORDER_NUMBER_OPER_PART_ID,
ORDER_ITEM.OI_THEME_GROUP_CODE,
ORDER_ITEM.OI_THEME_DESC,
ORDER_ITEM.OI_ITEM_STATUS_ID,
ORDER_ITEM.OI_BARCODE,
SIZE_TEMPLATE.ST_SIZETEMPLATECODE,
SIZE_TEMPLATE.ST_SIZETEMPLATEDESC,
SIZE_TEMPLATE.ST_COL1,
SIZE_TEMPLATE.ST_COL2,
SIZE_TEMPLATE.ST_COL3,
SIZE_TEMPLATE.ST_COL4,
SIZE_TEMPLATE.ST_COL5,
SIZE_TEMPLATE.ST_COL6,
SIZE_TEMPLATE.ST_COL7,
SIZE_TEMPLATE.ST_COL8,
SIZE_TEMPLATE.ST_COL9,
SIZE_TEMPLATE.ST_COL10,
SIZE_TEMPLATE.ST_COL11,
SIZE_TEMPLATE.ST_COL12,
STAFF.S_STAFFNAMEC,
STAFF.S_STAFFCODE,
STAFF.S_STAFFNAMEE,
UNIT_MEASUREMENT.UM_UNIT_CODE, ITEM_GENRE.IG_DESC_ENG,
ORDER_ITEM_STATUS.OIS_STATUS_DESC,
ORDER_ITEM.OI_REMARKS,
ORDER_ITEM.OI_HSCODE,
ORDER_ITEM.OI_CATEGORY,
ORDER_ITEM.OI_CAT,
ORDER_ITEM.QCS_CATEGORY_ID,
QUOTA_CATEGORY_STANDARD.QCS_CATEGORY_CODE,
ORDER_ITEM.OI_ORDER_TYPE
ORDER BY
ORDER_ITEM.OI_ORDER_NUMBER_OPER_ID,
ORDER_ITEM.OI_ITEM_STATUS_ID ASC NULLS FIRST,
ORDER_ITEM.OI_THEME_GROUP_CODE,
ORDER_ITEM.OI_THEME_DESC,
MIN(VIEW_ORDER_ITEM_PART.OIP_GROUP_CODE),
STRAGG( DISTINCT VIEW_ORDER_ITEM_PART.F_FABRIC_DESC_CHN),
STRAGG(DISTINCT VIEW_ORDER_ITEM_PART.F_SHORTCODEC),
STRAGG(DISTINCT VIEW_ORDER_ITEM_PART.S_STAFFNAMEC),
ORDER_ITEM.OI_DELVERY_DATE,
SIZE_TEMPLATE.ST_SIZETEMPLATECODE,
SIZE_TEMPLATE.ST_SIZETEMPLATEDESC,
ORDER_ITEM.OI_SEQ,
ORDER_ITEM.OI_ITEM_ID
Tnx in AdvanceTnx Rob for the reply...
Here's the explain plan
Plan hash value: 3988043906
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 7663 | 2207K| | 1190 (3)| 00:00:15 |
| 1 | FAST DUAL | | 1 | | | 2 (0)| 00:00:01 |
| 2 | SORT ORDER BY | | 7663 | 2207K| 4728K| 1190 (3)| 00:00:15 |
| 3 | SORT GROUP BY | | 7663 | 2207K| 4728K| 1190 (3)| 00:00:15 |
|* 4 | HASH JOIN RIGHT OUTER | | 7663 | 2207K| | 212 (13)| 00:00:03 |
| 5 | VIEW | VIEW_SUM_ITEM_SHIPMENT_QTY | 4238 | 76284 | | 17 (18)| 00:00:01 |
| 6 | SORT ORDER BY | | 4238 | 38142 | | 17 (18)| 00:00:01 |
| 7 | SORT GROUP BY | | 4238 | 38142 | | 17 (18)| 00:00:01 |
|* 8 | TABLE ACCESS FULL | SHIPMENT_ITEM | 4924 | 44316 | | 14 (0)| 00:00:01 |
|* 9 | HASH JOIN RIGHT OUTER | | 7663 | 2072K| | 194 (12)| 00:00:03 |
| 10 | TABLE ACCESS FULL | SIZE_TEMPLATE | 422 | 16458 | | 2 (0)| 00:00:01 |
|* 11 | HASH JOIN RIGHT OUTER | | 7663 | 1781K| | 192 (12)| 00:00:03 |
| 12 | TABLE ACCESS FULL | STAFF | 115 | 2530 | | 2 (0)| 00:00:01 |
|* 13 | HASH JOIN RIGHT OUTER | | 7663 | 1616K| | 189 (12)| 00:00:03 |
| 14 | TABLE ACCESS FULL | UNIT_MEASUREMENT | 7 | 49 | | 2 (0)| 00:00:01 |
|* 15 | HASH JOIN RIGHT OUTER | | 7663 | 1564K| 544K| 187 (12)| 00:00:03 |
| 16 | VIEW | VIEW_ORDER_ITEM_PART | 7320 | 450K| | 53 (33)| 00:00:01 |
|* 17 | HASH JOIN RIGHT OUTER | | 7320 | 736K| | 53 (33)| 00:00:01 |
| 18 | TABLE ACCESS FULL | STAFF | 115 | 1610 | | 2 (0)| 00:00:01 |
|* 19 | HASH JOIN RIGHT OUTER | | 7320 | 636K| | 51 (34)| 00:00:01 |
| 20 | TABLE ACCESS FULL | FABRIC | 1773 | 69147 | | 8 (0)| 00:00:01 |
|* 21 | HASH JOIN RIGHT OUTER| | 7320 | 357K| | 42 (39)| 00:00:01 |
| 22 | TABLE ACCESS FULL | FACTORY | 352 | 5280 | | 8 (0)| 00:00:01 |
| 23 | NESTED LOOPS OUTER | | 7320 | 250K| | 34 (48)| 00:00:01 |
| 24 | NESTED LOOPS OUTER | | 7320 | 221K| | 29 (38)| 00:00:01 |
| 25 | NESTED LOOPS OUTER| | 7320 | 200K| | 24 (25)| 00:00:01 |
| 26 | TABLE ACCESS FULL| ORDER_ITEM_PART | 7320 | 164K| | 18 (0)| 00:00:01 |
|* 27 | INDEX UNIQUE SCAN| PK_OI_ITEM_ID | 1 | 5 | | 0 (0)| 00:00:01 |
|* 28 | INDEX UNIQUE SCAN | PK_UNIT_MEASUREMENT | 1 | 3 | | 0 (0)| 00:00:01 |
|* 29 | INDEX UNIQUE SCAN | PK_F_FACTORY_ID | 1 | 4 | | 0 (0)| 00:00:01 |
|* 30 | HASH JOIN RIGHT OUTER | | 7040 | 1003K| | 41 (5)| 00:00:01 |
| 31 | TABLE ACCESS FULL | ITEM_GENRE | 5 | 35 | | 2 (0)| 00:00:01 |
|* 32 | HASH JOIN RIGHT OUTER | | 7040 | 955K| | 39 (6)| 00:00:01 |
| 33 | TABLE ACCESS FULL | ORDER_ITEM_STATUS | 5 | 70 | | 2 (0)| 00:00:01 |
|* 34 | HASH JOIN RIGHT OUTER | | 7040 | 859K| | 36 (3)| 00:00:01 |
| 35 | TABLE ACCESS FULL | GEN_ORDER_NUMBER_OPERATOR | 360 | 2880 | | 2 (0)| 00:00:01 |
|* 36 | HASH JOIN RIGHT OUTER| | 7040 | 804K| | 34 (3)| 00:00:01 |
| 37 | TABLE ACCESS FULL | QUOTA_CATEGORY_STANDARD | 60 | 480 | | 2 (0)| 00:00:01 |
| 38 | TABLE ACCESS FULL | ORDER_ITEM | 7040 | 749K| | 31 (0)| 00:00:01 |
Predicate Information (identified by operation id):
4 - access("ORDER_ITEM"."OI_ITEM_ID"="VIEW_SUM_ITEM_SHIPMENT_QTY"."OI_ITEM_ID"(+))
8 - filter("SHIPMENT_ITEM"."OI_ITEM_ID" IS NOT NULL)
9 - access("ORDER_ITEM"."OI_ITEM_SIZE_ID"="SIZE_TEMPLATE"."ST_SIZETEMPLATE_ID"(+))
11 - access("ORDER_ITEM"."OI_DESIGNER_ID"="STAFF"."S_STAFF_ID"(+))
13 - access("ORDER_ITEM"."OI_UM_ID"="UNIT_MEASUREMENT"."UM_UNIT_ID"(+))
15 - access("ORDER_ITEM"."OI_ITEM_ID"="VIEW_ORDER_ITEM_PART"."OIP_ITEM_ID"(+))
17 - access("ORDER_ITEM_PART"."OIP_QC_ID"="STAFF"."S_STAFF_ID"(+))
19 - access("ORDER_ITEM_PART"."OIP_FABRIC_ID"="FABRIC"."F_FABRIC_ID"(+))
21 - access("ORDER_ITEM_PART"."OIP_FACTORY_ID"="FACTORY"."F_FACTORY_ID"(+))
27 - access("ORDER_ITEM_PART"."OIP_ITEM_ID"="ORDER_ITEM"."OI_ITEM_ID"(+))
28 - access("ORDER_ITEM_PART"."OIP_UNIT"="UNIT_MEASUREMENT"."UM_UNIT_ID"(+))
29 - access("ORDER_ITEM_PART"."OIP_ALT_FACTORY_ID"="FACTORY_A1"."F_FACTORY_ID"(+))
30 - access("ORDER_ITEM"."OI_GENRE_ID"="ITEM_GENRE"."IG_GENRE_ID"(+))
32 - access("ORDER_ITEM"."OI_ITEM_STATUS_ID"="ORDER_ITEM_STATUS"."OIS_STATUS_ID"(+))
34 - access("ORDER_ITEM"."OI_ORDER_NUMBER_OPER_ID"="GEN_ORDER_NUMBER_OPERATOR"."GONO_ORDER_NUMBER_OPER_ID"(+)
36 - access("ORDER_ITEM"."QCS_CATEGORY_ID"="QUOTA_CATEGORY_STANDARD"."QCS_CATEGORY_ID"(+))The output from tkprof
TKPROF: Release 10.1.0.2.0 - Production on Wed Aug 1 18:47:32 2007
Copyright (c) 1982, 2004, Oracle. All rights reserved.
Trace file: erpdada_ora_3464.trc
Sort options: prsela exeela fchela
count = number of times OCI procedure was executed
cpu = cpu time in seconds executing
elapsed = elapsed time in seconds executing
disk = number of physical reads of buffers from disk
query = number of buffers gotten for consistent read
current = number of buffers gotten in current mode (usually for update)
rows = number of rows processed by the fetch or execute call
SELECT
ORDER_ITEM.OI_ITEM_ID,
ORDER_ITEM.OI_SEQ,
GEN_ORDER_NUMBER_OPERATOR.GONO_ORDER_NUMBER_ID,
ORDER_ITEM.OI_ORDER_NUMBER_OPER_ID,
ORDER_ITEM.OI_ITEM_CODE,
ORDER_ITEM.OI_ITEM_DESC,
ORDER_ITEM.OI_ITEM_SIZE_ID,
ORDER_ITEM.OI_QTY,
(VIEW_SUM_ITEM_SHIPMENT_QTY.TOTAL_QTY_SHIPPED-ORDER_ITEM.OI_QTY) BALANCE_SHIP_QTY,
ORDER_ITEM.OI_DELVERY_DATE,
ORDER_ITEM.OI_ENTRY_DATE,
(round((select sysdate from sys.dual)-
ORDER_ITEM.OI_ENTRY_DATE)) no_days_passed,
ORDER_ITEM.OI_SALES_CONTRACT_ITEM_FLAG,
ORDER_ITEM.OI_ITEM_DESCC,
ORDER_ITEM.OI_DESIGNER_ID OI_DESIGNER_ID,
ORDER_ITEM.OI_FABRIC_GROUP_CODE,
ORDER_ITEM.OI_UM_ID,
ORDER_ITEM.OI_GROUP_CODE,
ORDER_ITEM.OI_GENRE_ID,
ORDER_ITEM.OI_ORDER_NUMBER_OPER_PART_ID,
ORDER_ITEM.OI_THEME_GROUP_CODE,
ORDER_ITEM.OI_THEME_DESC,
ORDER_ITEM.OI_ITEM_STATUS_ID,
ORDER_ITEM.OI_BARCODE,
SIZE_TEMPLATE.ST_SIZETEMPLATECODE,
SIZE_TEMPLATE.ST_SIZETEMPLATEDESC,
SIZE_TEMPLATE.ST_COL1,
SIZE_TEMPLATE.ST_COL2,
SIZE_TEMPLATE.ST_COL3,
SIZE_TEMPLATE.ST_COL4,
SIZE_TEMPLATE.ST_COL5,
SIZE_TEMPLATE.ST_COL6,
SIZE_TEMPLATE.ST_COL7,
SIZE_TEMPLATE.ST_COL8,
SIZE_TEMPLATE.ST_COL9,
SIZE_TEMPLATE.ST_COL10,
SIZE_TEMPLATE.ST_COL11,
SIZE_TEMPLATE.ST_COL12,
STAFF.S_STAFFNAMEC,
STAFF.S_STAFFCODE,
STAFF.S_STAFFNAMEE,
UNIT_MEASUREMENT.UM_UNIT_CODE, ITEM_GENRE.IG_DESC_ENG,
ORDER_ITEM_STATUS.OIS_STATUS_DESC,
MIN(VIEW_ORDER_ITEM_PART.OIP_GROUP_CODE)MIN_OIP_GROUP_CODE,
STRAGG( DISTINCT VIEW_ORDER_ITEM_PART.F_SHORTCODEC)STRAGG_F_SHORTCODEC,
STRAGG(DISTINCT VIEW_ORDER_ITEM_PART.S_STAFFNAMEC)STRAGG_QCNAME,
STRAGG(DISTINCT VIEW_ORDER_ITEM_PART.F_FABRIC_DESC_CHN)STRAGG_FABRIC,
ORDER_ITEM.OI_REMARKS,
ORDER_ITEM.OI_HSCODE,
ORDER_ITEM.OI_CATEGORY,
ORDER_ITEM.OI_CAT,
ORDER_ITEM.QCS_CATEGORY_ID,
QUOTA_CATEGORY_STANDARD.QCS_CATEGORY_CODE,
ORDER_ITEM.OI_ORDER_TYPE
FROM ORDER_ITEM, SIZE_TEMPLATE, STAFF, UNIT_MEASUREMENT, ITEM_GENRE,ORDER_ITEM_STATUS,VIEW_ORDER_ITEM_PART,GEN_ORDER_NUMBER_OPERATOR,VIEW_SUM_ITEM_SHIPMENT_QTY,QUOTA_CATEGORY_STANDARD
WHERE ((ORDER_ITEM.OI_ITEM_SIZE_ID = SIZE_TEMPLATE.ST_SIZETEMPLATE_ID(+))
AND (ORDER_ITEM.OI_DESIGNER_ID = STAFF.S_STAFF_ID(+))
AND (ORDER_ITEM.OI_UM_ID = UNIT_MEASUREMENT.UM_UNIT_ID(+))
AND (ORDER_ITEM.OI_GENRE_ID = ITEM_GENRE.IG_GENRE_ID(+))
AND (ORDER_ITEM.OI_ITEM_STATUS_ID=ORDER_ITEM_STATUS.OIS_STATUS_ID(+))
AND (ORDER_ITEM.OI_ITEM_ID=VIEW_ORDER_ITEM_PART.OIP_ITEM_ID(+))
AND (ORDER_ITEM.QCS_CATEGORY_ID=QUOTA_CATEGORY_STANDARD.QCS_CATEGORY_ID(+))
AND (ORDER_ITEM.OI_ITEM_ID=VIEW_SUM_ITEM_SHIPMENT_QTY.OI_ITEM_ID(+))
AND (ORDER_ITEM.OI_ORDER_NUMBER_OPER_ID = GEN_ORDER_NUMBER_OPERATOR.GONO_ORDER_NUMBER_OPER_ID(+)))
GROUP BY
ORDER_ITEM.OI_ITEM_ID,
ORDER_ITEM.OI_SEQ,
GEN_ORDER_NUMBER_OPERATOR.GONO_ORDER_NUMBER_ID,
ORDER_ITEM.OI_ORDER_NUMBER_OPER_ID,
ORDER_ITEM.OI_ITEM_CODE,
ORDER_ITEM.OI_ITEM_DESC,
ORDER_ITEM.OI_ITEM_SIZE_ID,
ORDER_ITEM.OI_QTY,
(VIEW_SUM_ITEM_SHIPMENT_QTY.TOTAL_QTY_SHIPPED-ORDER_ITEM.OI_QTY),
ORDER_ITEM.OI_DELVERY_DATE,
ORDER_ITEM.OI_ENTRY_DATE,
ORDER_ITEM.OI_SALES_CONTRACT_ITEM_FLAG,
ORDER_ITEM.OI_ITEM_DESCC,
ORDER_ITEM.OI_DESIGNER_ID,
ORDER_ITEM.OI_FABRIC_GROUP_CODE,
ORDER_ITEM.OI_UM_ID,
ORDER_ITEM.OI_GROUP_CODE,
ORDER_ITEM.OI_GENRE_ID,
ORDER_ITEM.OI_ORDER_NUMBER_OPER_PART_ID,
ORDER_ITEM.OI_THEME_GROUP_CODE,
ORDER_ITEM.OI_THEME_DESC,
ORDER_ITEM.OI_ITEM_STATUS_ID,
ORDER_ITEM.OI_BARCODE,
SIZE_TEMPLATE.ST_SIZETEMPLATECODE,
SIZE_TEMPLATE.ST_SIZETEMPLATEDESC,
SIZE_TEMPLATE.ST_COL1,
SIZE_TEMPLATE.ST_COL2,
SIZE_TEMPLATE.ST_COL3,
SIZE_TEMPLATE.ST_COL4,
SIZE_TEMPLATE.ST_COL5,
SIZE_TEMPLATE.ST_COL6,
SIZE_TEMPLATE.ST_COL7,
SIZE_TEMPLATE.ST_COL8,
SIZE_TEMPLATE.ST_COL9,
SIZE_TEMPLATE.ST_COL10,
SIZE_TEMPLATE.ST_COL11,
SIZE_TEMPLATE.ST_COL12,
STAFF.S_STAFFNAMEC,
STAFF.S_STAFFCODE,
STAFF.S_STAFFNAMEE,
UNIT_MEASUREMENT.UM_UNIT_CODE, ITEM_GENRE.IG_DESC_ENG,
ORDER_ITEM_STATUS.OIS_STATUS_DESC,
ORDER_ITEM.OI_REMARKS,
ORDER_ITEM.OI_HSCODE,
ORDER_ITEM.OI_CATEGORY,
ORDER_ITEM.OI_CAT,
ORDER_ITEM.QCS_CATEGORY_ID,
QUOTA_CATEGORY_STANDARD.QCS_CATEGORY_CODE,
ORDER_ITEM.OI_ORDER_TYPE
ORDER BY
ORDER_ITEM.OI_ORDER_NUMBER_OPER_ID,
ORDER_ITEM.OI_ITEM_STATUS_ID ASC NULLS FIRST,
ORDER_ITEM.OI_THEME_GROUP_CODE,
ORDER_ITEM.OI_THEME_DESC,
MIN(VIEW_ORDER_ITEM_PART.OIP_GROUP_CODE),
STRAGG( DISTINCT VIEW_ORDER_ITEM_PART.F_FABRIC_DESC_CHN),
STRAGG(DISTINCT VIEW_ORDER_ITEM_PART.F_SHORTCODEC),
STRAGG(DISTINCT VIEW_ORDER_ITEM_PART.S_STAFFNAMEC),
ORDER_ITEM.OI_DELVERY_DATE,
SIZE_TEMPLATE.ST_SIZETEMPLATECODE,
SIZE_TEMPLATE.ST_SIZETEMPLATEDESC,
ORDER_ITEM.OI_SEQ,
ORDER_ITEM.OI_ITEM_ID
call count cpu elapsed disk query current rows
Parse 1 3.99 4.20 0 744 0 0
Execute 2 0.00 0.00 0 0 0 0
Fetch 5 14.03 18.13 2813 7811 63 50
total 8 18.02 22.34 2813 8555 63 50
Misses in library cache during parse: 1
Optimizer mode: ALL_ROWS
Parsing user id: 64
Rows Row Source Operation
0 SORT ORDER BY (cr=0 pr=0 pw=0 time=0 us)
0 SORT GROUP BY (cr=0 pr=0 pw=0 time=0 us)
0 HASH JOIN RIGHT OUTER (cr=0 pr=0 pw=0 time=0 us)
0 VIEW (cr=0 pr=0 pw=0 time=0 us)
0 SORT ORDER BY (cr=0 pr=0 pw=0 time=0 us)
0 SORT GROUP BY (cr=0 pr=0 pw=0 time=0 us)
0 TABLE ACCESS FULL SHIPMENT_ITEM (cr=0 pr=0 pw=0 time=0 us)
0 HASH JOIN RIGHT OUTER (cr=0 pr=0 pw=0 time=0 us)
0 TABLE ACCESS FULL SIZE_TEMPLATE (cr=0 pr=0 pw=0 time=0 us)
0 HASH JOIN RIGHT OUTER (cr=0 pr=0 pw=0 time=0 us)
0 TABLE ACCESS FULL STAFF (cr=0 pr=0 pw=0 time=0 us)
0 HASH JOIN RIGHT OUTER (cr=0 pr=0 pw=0 time=0 us)
0 TABLE ACCESS FULL UNIT_MEASUREMENT (cr=0 pr=0 pw=0 time=0 us)
0 HASH JOIN RIGHT OUTER (cr=0 pr=0 pw=0 time=0 us)
0 VIEW (cr=0 pr=0 pw=0 time=0 us)
0 HASH JOIN RIGHT OUTER (cr=0 pr=0 pw=0 time=0 us)
0 TABLE ACCESS FULL STAFF (cr=0 pr=0 pw=0 time=0 us)
0 HASH JOIN RIGHT OUTER (cr=0 pr=0 pw=0 time=0 us)
0 TABLE ACCESS FULL FABRIC (cr=0 pr=0 pw=0 time=0 us)
0 HASH JOIN RIGHT OUTER (cr=0 pr=0 pw=0 time=0 us)
0 TABLE ACCESS FULL FACTORY (cr=0 pr=0 pw=0 time=0 us)
0 NESTED LOOPS OUTER (cr=0 pr=0 pw=0 time=0 us)
0 NESTED LOOPS OUTER (cr=0 pr=0 pw=0 time=0 us)
0 NESTED LOOPS OUTER (cr=0 pr=0 pw=0 time=0 us)
0 TABLE ACCESS FULL ORDER_ITEM_PART (cr=0 pr=0 pw=0 time=0 us)
0 INDEX UNIQUE SCAN PK_OI_ITEM_ID (cr=0 pr=0 pw=0 time=0 us)(object id 50551)
0 INDEX UNIQUE SCAN PK_UNIT_MEASUREMENT (cr=0 pr=0 pw=0 time=0 us)(object id 50324)
0 INDEX UNIQUE SCAN PK_F_FACTORY_ID (cr=0 pr=0 pw=0 time=0 us)(object id 51087)
0 HASH JOIN RIGHT OUTER (cr=0 pr=0 pw=0 time=0 us)
0 TABLE ACCESS FULL ITEM_GENRE (cr=0 pr=0 pw=0 time=0 us)
0 HASH JOIN RIGHT OUTER (cr=0 pr=0 pw=0 time=0 us)
0 TABLE ACCESS FULL ORDER_ITEM_STATUS (cr=0 pr=0 pw=0 time=0 us)
0 HASH JOIN RIGHT OUTER (cr=0 pr=0 pw=0 time=0 us)
0 TABLE ACCESS FULL GEN_ORDER_NUMBER_OPERATOR (cr=0 pr=0 pw=0 time=0 us)
0 HASH JOIN RIGHT OUTER (cr=0 pr=0 pw=0 time=0 us)
0 TABLE ACCESS FULL QUOTA_CATEGORY_STANDARD (cr=0 pr=0 pw=0 time=0 us)
0 TABLE ACCESS FULL ORDER_ITEM (cr=0 pr=0 pw=0 time=0 us)
SELECT COLUMN_VALUE
FROM
TABLE(:B1 ) ORDER BY 1
call count cpu elapsed disk query current rows
Parse 1 0.00 0.00 0 0 0 0
Execute 21273 3.27 3.62 0 0 0 0
Fetch 21273 1.40 1.36 0 0 0 20844
total 42547 4.67 4.99 0 0 0 20844
Misses in library cache during parse: 0
Optimizer mode: ALL_ROWS
Parsing user id: 64 (recursive depth: 1)
Rows Row Source Operation
20844 SORT ORDER BY (cr=0 pr=0 pw=0 time=1493588 us)
20844 COLLECTION ITERATOR PICKLER FETCH (cr=0 pr=0 pw=0 time=350669 us)
alter session set sql_trace true
call count cpu elapsed disk query current rows
Parse 0 0.00 0.00 0 0 0 0
Execute 1 0.00 0.00 0 0 0 0
Fetch 0 0.00 0.00 0 0 0 0
total 1 0.00 0.00 0 0 0 0
Misses in library cache during parse: 0
Optimizer mode: ALL_ROWS
Parsing user id: 64
OVERALL TOTALS FOR ALL NON-RECURSIVE STATEMENTS
call count cpu elapsed disk query current rows
Parse 1 3.99 4.20 0 744 0 0
Execute 3 0.00 0.00 0 0 0 0
Fetch 5 14.03 18.13 2813 7811 63 50
total 9 18.02 22.34 2813 8555 63 50
Misses in library cache during parse: 1
OVERALL TOTALS FOR ALL RECURSIVE STATEMENTS
call count cpu elapsed disk query current rows
Parse 4 0.00 0.00 0 0 0 0
Execute 21276 3.27 3.62 0 0 0 0
Fetch 21276 1.40 1.36 0 7 0 20847
total 42556 4.67 4.99 0 7 0 20847
Misses in library cache during parse: 0
3 user SQL statements in session.
3 internal SQL statements in session.
6 SQL statements in session.
Trace file: erpdada_ora_3464.trc
Trace file compatibility: 10.01.00
Sort options: prsela exeela fchela
1 session in tracefile.
3 user SQL statements in trace file.
3 internal SQL statements in trace file.
6 SQL statements in trace file.
5 unique SQL statements in trace file.
42783 lines in trace file.
37 elapsed seconds in trace file.
Im sorry for giving trouble guys.....Awaiting for reply...Tnx in advance -
I have one table as test ot_shop_transmittal_test and the sample reords inserted as below, i want a output in range like below
STMH_NO STMH_BATCH_NO STMH_PM_CODE STMH_PM_DESC STMH_REV_NO
PR-1107-0001 0001 1107040-1001 - 1107040-1003 FRAME, COLUMN 0
PR-1107-0001 0002 1107040-1004 FRAME 0
PR-1107-0001 0001 1107040-1006 GIRDER 0
CREATE TABLE OT_SHOP_TRANSMITTAL_TEST
STMH_NO VARCHAR2(15),
STMH_JOB_NO VARCHAR2(12),
STMH_BATCH_NO VARCHAR2(12),
STMH_PM_CODE VARCHAR2(35),
STMH_PM_DESC VARCHAR2(240),
STMH_REV_NO VARCHAR2(12)
INSERT INTO OT_SHOP_TRANSMITTAL_TEST VALUES ('PR-1107-0001','1107040','0001','1107040-1001','FRAME','0');
INSERT INTO OT_SHOP_TRANSMITTAL_TEST VALUES ('PR-1107-0001','1107040','0001','1107040-1002','FRAME','0');
INSERT INTO OT_SHOP_TRANSMITTAL_TEST VALUES ('PR-1107-0001','1107040','0001','1107040-1003','COLUMN','0');
INSERT INTO OT_SHOP_TRANSMITTAL_TEST VALUES ('PR-1107-0001','1107040','0002','1107040-1004','FRAME','0');
INSERT INTO OT_SHOP_TRANSMITTAL_TEST VALUES ('PR-1107-0001','1107040','0001','1107040-1005','FRAME','0');
INSERT INTO OT_SHOP_TRANSMITTAL_TEST VALUES ('PR-1107-0001','1107040','0001','1107040-1006','GIRDER','0');
--What i want is like rownumber to considered also the output will be
STMH_NO STMH_BATCH_NO STMH_PM_CODE STMH_PM_DESC STMH_REV_NO
PR-1107-0001 0001 1107040-1001 - 1107040-1003 FRAME, COLUMN 0
PR-1107-0001 0002 1107040-1004 FRAME 0
PR-1107-0001 0001 1107040-1006 GIRDER 0
select rn,stmh_batch_no,
MIN (a)
|| DECODE (MIN (a),
MAX (a), '',
' - ' || MAX (a)
) STMH_PM_CODE,
MIN (b)|| DECODE (MIN (b),MAX (b), '',' - ' || MAX (b)) des
from (
SELECT DECODE (rn, 1, STMH_PM_CODE, stmh_pm_code) A,
DECODE (rn, 1, STMH_PM_DESC, stmh_pm_desc) B,
rn,
stmh_batch_no
FROM
( SELECT STMH_NO,STMH_BATCH_NO,
STMH_PM_CODE,
STMH_PM_DESC,
ROW_NUMBER () OVER
(PARTITION BY STMH_BATCH_NO,STMH_PM_DESC
ORDER BY stmh_PM_CODE) rn
FROM OT_SHOP_TRANSMITTAL_TEST
ORDER BY 3,5 ) T1 ) t2
where t2.rn=1
group by rn,stmh_batch_no
-- i am getting the result as below with the above query and its wrong since i want 1107040-1006 in a seperate line
STMH_NO STMH_BATCH_NO STMH_PM_CODE STMH_PM_DESC STMH_REV_NO
PR-1107-0001 0001 1107040-1001 - 1107040-1006 COLUMN-GIRDER 0
PR-1107-0001 0002 1107040-1004 FRAME 0user5206327 wrote:
thanks frank, oracle version is 10.2.0.1.0 and can you please demonstrate the query with STRAGG , stmh_rev_no is like stmh_batch_no, and whenver it changes , the result set will also change using your query i am getting the result as below .
STMH_NO STMH_JOB_NO STMH_BATCH_NO pm_code desc
PR-1107-0001 1107040 0001 1107040-1001-1107040-1006 COLUMN,FRAME,GIRDER
PR-1107-0001 1107040 0002 1107040-1004-1107040-1004 FRAMEIt looks like you changed the query.
When I run what I posted, I get
` STMH_ STMH
BATCH _REV
STMH_NO _NO STMH_PM_CODES _NO
PR-1107-0001 0001 1107040-1001 - 1107040-1003 0
PR-1107-0001 0002 1107040-1004 0
PR-1107-0001 0001 1107040-1005 - 1107040-1006 0That is, 3 rows of output, no stmh_job_no or desc columns, but I do get a stmh_rev_no column. Post exactly what you ran.
i want the output like this below.
STMH_NO STMH_JOB_NO STMH_BATCH_NO pm_code desc
PR-1107-0001 1107040 0001 1107040-1001-1107040-1003 COLUMN,FRAME
PR-1107-0001 1107040 0002 1107040-1004 FRAME
PR-1107-0001 1107040 0001 1107040-1005-1107040-1006 FRAME,GIRDERWhen I run the following query, I get that output:
WITH got_diff AS
SELECT stmh_no
, stmh_job_no
, stmh_batch_no
, stmh_pm_code
, stmh_pm_desc
, stmh_rev_no
, ROW_NUMBER () OVER ( PARTITION BY stmh_no
ORDER BY stmh_pm_code
- ROW_NUMBER () OVER ( PARTITION BY stmh_batch_no
, stmh_rev_no
, stmh_no
ORDER BY stmh_pm_code
) AS diff
FROM ot_shop_transmittal_test
SELECT stmh_no
, MIN (stmh_job_no) AS stmh_job_no
, stmh_batch_no
, MIN (stmh_pm_code) || CASE
WHEN COUNT (DISTINCT stmh_pm_code) > 1
THEN '-' || MAX (stmh_pm_code)
END AS stmh_pm_codes
, STRAGG (DISTINCT stmh_pm_desc) AS stmh_pm_descs
FROM got_diff
GROUP BY stmh_no
, stmh_batch_no
, stmh_rev_no
, diff
ORDER BY stmh_no
, stmh_pm_codes
, stmh_batch_no
, stmh_rev_no
;except that I called the last column stmh_pm_descs instead of desc. DESC is a keyword in Oracle (it's used for sorting in DESCending order), so it's not a very good column name.
If stmh_rev_no is similar to stmh_batch_no, then use stmh_rev_no and stmh_batch_no together in all PARTITION BY and GROUP BY clauses.
I still don't understand what role stmh_job_no plays in this problem. If stmh_job_no is like stmh_rev_no and stmh_batch_no, then use all 3 columns together in the PARTITION BY and GROUP BY clauses. -
DISTINCT not working with wmsys.wm_concat
Need help on this :
I need distinct in group concat,wmsys.wm_concat is not working in PL/SQL but its working out side PL/SQL.Am i not using function correct way ? my Oracle version 11g,R2.
Not Working in PL/SQL :
create or replace procedure ttp
as
begin
insert into tt1(cnt1,deptno1,sumt,cbranch)
select count(no),count(deptno),sum(tot),wmsys.wm_concat(DISTINCT branch) from tt group by deptno;
commit;
end;
ERROR :
LINE/COL ERROR
4/1 PL/SQL: SQL Statement ignored
5/48 PL/SQL: ORA-30482: DISTINCT option not allowed for this function
16:42:43 SQL>
Working in SQL :
select count(no),count(deptno),sum(tot),wmsys.wm_concat(distinct branch) from tt group by deptno;
Thanks,
Edited by: user607128 on Oct 30, 2011 1:50 PMHi,
I don't know why DISTINCT doesn't work in PL/SQL. You might need to do two GROUP BYs; one to get distinct branches, and the other to collapse that down to one row per deptno:
INSERT INTO tt1 (cnt1, deptno1, sumt, cbranch)
WITH got_distinct_branch AS
SELECT deptno
, branch
, COUNT (no) AS count_no
, COUNT (deptno) AS count_deptno
, SUM (tot) AS sum_tot
FROM tt
GROUP BY deptno
, branch
SELECT SUM (count_no)
, SUM (count_deptno)
, SUM (sum_tot)
, LISTAGG (branch, ',') WITHIN GROUP (ORDER BY branch)
FROM got_distinct_branch
GROUP BY deptno
;You didn't post CREATE TABLE and INSERT statements for your tables, so I can't test it.
Don't use wm_concat; it's not documented. Since you have Oracle 11.2, you can use LISTAGG, or, if you really need the DISTINCT feature outside of PL/SQL, the user-defined STRAGG which you can copy from the following page:
http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:2196162600402 -
Hi
I am trying to use Stragg and merge a clob .
requirement is
Tables": EMPL_HDR, EMPL-EDU, EMPL-CERT, EMPL-EMPLMNT-HISTORY, EMPL-CLEARANCE, EMPL-MIL-SVC etc
there is a hdr_seq that is carried over to all the tables. At the end of the job, for reporting purposes, we want all relevant data for the employee to be put in one relevant column.
for eg:
EMPL_ID HDR_SEQ EDU_CLOB DEGREE UNIVERSITY GRADUATION_DT
1 987654 226
2 514275 266 BA in Communications from Penn State University on 05-27-1986 BA Penn State University 27-MAY-86
3 526541 270 High School Diploma on 06-27-1976 High School Diploma 27-JUN-76
6 526734 321 MS in Information Systems from SU on 06-25-1998 MS SU 25-JUN-98
I can build this using varchar2(4000) in stragg
select distinct a.empl_id, a.hdr_seq,
stragg(degree_type || decode (discipline,NULL,NULL, ' in ' || discipline)
|| decode( University, NULL,NULL,' from ' || University )
|| decode(graduation_dt, NULL,NULL,' on ' || to_char(graduation_dt ,'MM-DD-YYYY'))
) over ( partition by a.hdr_seq) as edu_clob ,
stragg(degree_type)over ( partition by a.hdr_seq)as degree ,
stragg(university) over ( partition by a.hdr_seq) as University ,
stragg ( graduation_dt) over ( partition by a.hdr_seq) as graduation_dt
from rw_edu a,kj_hdr b where a.hdr_seq =b.hdr_seq
But when I use CLOB instead of Varchar2, I get ORA-00932 error - expect - getting CLOB.
As for STRAGG - I used the one from AskTom
http://www.sqlsnippets.com/en/topic-11591.html
I was intending to use this in MERGE and write to the table from within a procedure/function to be called from informatica every night as a part of a batch.
Tried few different ways and saw stragg with Merge is good. Also - Can I use MERGE with Clob too?
The Merge that I tried was
merge into kj_hdr K
using (
select distinct a.empl_id, a.hdr_seq,
stragg(degree_type || decode (discipline,NULL,NULL, ' in ' || discipline)
|| decode( University, NULL,NULL,' from ' || University )
|| decode(graduation_dt, NULL,NULL,' on ' || to_char(graduation_dt ,'MM-DD-YYYY'))
) over ( partition by a.hdr_seq) as edu_clob
from rw_edu a,kj_hdr b where a.hdr_seq =b.hdr_seq ) r
on ( K.hdr_Seq = r.hdr_seq )
when matched then update set K.edu_clob = r.edu_clob
where edu_clob is a clob field. edu_all is a varchar2(4000)
Thank You for your timeHi Frank
Enclosing the SQL for the tables & few records.
KJ_HDR , RW_CERT (0:M certs for any hdr_seq and some fields may be null), RW_EDU (0:M edu info )
every night, i need to append this 'beautified' data into the CLOB which will be used for reports.
At the end, I am enclosing SQL that i tried to do this with CLOBAGG & MERGE using DBMS_CRYPTO. I can loop through in cursor and update the CLOB too I guess..
create table KJ_HDR
hdr_seq NUMBER not null,
empl_id VARCHAR2(12) not null,
eff_st_dt DATE,
place_of_birth VARCHAR2(200),
create_dt DATE,
mobility_status_type VARCHAR2(50),
mobility_avail_dt VARCHAR2(35),
edu_all VARCHAR2(4000),
edu_clob CLOB,
cert_clob CLOB
alter table KJ_HDR
add constraint KJ1 unique (HDR_SEQ)
using index;
create table RW_CERT
cert_seq NUMBER not null,
hdr_seq NUMBER,
empl_id VARCHAR2(12),
eff_st_dt DATE,
cert_type VARCHAR2(75),
cert_name VARCHAR2(100),
cert_flag VARCHAR2(1) default 'Y',
cert_dt DATE,
create_dt DATE
alter table RW_CERT
add constraint RW_CERT_PK primary key (CERT_SEQ)
using index;
create table RW_EDU
edu_seq NUMBER not null,
hdr_seq NUMBER,
empl_id VARCHAR2(12),
degree_type VARCHAR2(50),
discipline VARCHAR2(100),
other VARCHAR2(100),
university VARCHAR2(150),
graduation_dt DATE,
create_dt DATE,
eff_st_dt DATE
alter table RW_EDU
add constraint RW_EDU primary key (EDU_SEQ)
using index;
-- data for kj_hdr
insert into KJ_HDR (
HDR_SEQ,
EMPL_ID,
EFF_ST_DT,
PLACE_OF_BIRTH,
CREATE_DT,
MOBILITY_STATUS_TYPE,
MOBILITY_AVAIL_DT ) values (321,
'567890',
to_date('02/29/2012 00:00','mm/dd/yyyy hh24:mi'),
'Las Vegas, NV, USA',
to_date('02/29/2012 06:11','mm/dd/yyyy hh24:mi'),
'Not looking at this time',
'NA');
insert into KJ_HDR (
HDR_SEQ,
EMPL_ID,
EFF_ST_DT,
PLACE_OF_BIRTH,
CREATE_DT,
MOBILITY_STATUS_TYPE,
MOBILITY_AVAIL_DT ) values (2,
'777555',
to_date('01/19/2012 00:00','mm/dd/yyyy hh24:mi'),
'Worcester',
to_date('01/19/2012 23:42','mm/dd/yyyy hh24:mi'),
Null,
Null);
insert into KJ_HDR (
HDR_SEQ,
EMPL_ID,
EFF_ST_DT,
PLACE_OF_BIRTH,
CREATE_DT,
MOBILITY_STATUS_TYPE,
MOBILITY_AVAIL_DT ) values (3,
'526577',
to_date('01/19/2012 00:00','mm/dd/yyyy hh24:mi'),
'Lowel',
to_date('01/19/2012 23:42','mm/dd/yyyy hh24:mi'),
Null,
Null);
insert into KJ_HDR (
HDR_SEQ,
EMPL_ID,
EFF_ST_DT,
PLACE_OF_BIRTH,
CREATE_DT,
MOBILITY_STATUS_TYPE,
MOBILITY_AVAIL_DT ) values (4,
'622123',
to_date('01/19/2012 00:00','mm/dd/yyyy hh24:mi'),
'India',
to_date('01/19/2012 23:42','mm/dd/yyyy hh24:mi'),
Null,
Null);
insert into KJ_HDR (
HDR_SEQ,
EMPL_ID,
EFF_ST_DT,
PLACE_OF_BIRTH,
CREATE_DT,
MOBILITY_STATUS_TYPE,
MOBILITY_AVAIL_DT ) values (302,
'568193',
to_date('02/28/2012 00:00','mm/dd/yyyy hh24:mi'),
Null,
to_date('02/28/2012 10:28','mm/dd/yyyy hh24:mi'),
'Not looking at this time',
'NA');
insert into KJ_HDR (
HDR_SEQ,
EMPL_ID,
EFF_ST_DT,
PLACE_OF_BIRTH,
CREATE_DT,
MOBILITY_STATUS_TYPE,
MOBILITY_AVAIL_DT ) values (270,
'123456',
to_date('02/27/2012 00:00','mm/dd/yyyy hh24:mi'),
Null,
to_date('02/27/2012 14:04','mm/dd/yyyy hh24:mi'),
'Not looking at this time',
'NA');
insert into KJ_HDR (
HDR_SEQ,
EMPL_ID,
EFF_ST_DT,
PLACE_OF_BIRTH,
CREATE_DT,
MOBILITY_STATUS_TYPE,
MOBILITY_AVAIL_DT ) values (266,
'514275',
to_date('02/27/2012 00:00','mm/dd/yyyy hh24:mi'),
Null,
to_date('02/27/2012 13:55','mm/dd/yyyy hh24:mi'),
'Not looking at this time',
'NA');
insert into KJ_HDR (
HDR_SEQ,
EMPL_ID,
EFF_ST_DT,
PLACE_OF_BIRTH,
CREATE_DT,
MOBILITY_STATUS_TYPE,
MOBILITY_AVAIL_DT ) values (272,
'345234',
to_date('02/27/2012 00:00','mm/dd/yyyy hh24:mi'),
Null,
to_date('02/27/2012 16:37','mm/dd/yyyy hh24:mi'),
'Not looking at this time',
'NA');
insert into KJ_HDR (
HDR_SEQ,
EMPL_ID,
EFF_ST_DT,
PLACE_OF_BIRTH,
CREATE_DT,
MOBILITY_STATUS_TYPE,
MOBILITY_AVAIL_DT ) values (269,
'836989',
to_date('02/27/2012 00:00','mm/dd/yyyy hh24:mi'),
'Phoenix, Arizona, US',
to_date('02/27/2012 14:03','mm/dd/yyyy hh24:mi'),
'Not looking at this time',
'NA');
insert into KJ_HDR (
HDR_SEQ,
EMPL_ID,
EFF_ST_DT,
PLACE_OF_BIRTH,
CREATE_DT,
MOBILITY_STATUS_TYPE,
MOBILITY_AVAIL_DT ) values (273,
'712712',
to_date('02/27/2012 00:00','mm/dd/yyyy hh24:mi'),
'Overbrook, Pennsylvania, USA',
to_date('02/27/2012 16:40','mm/dd/yyyy hh24:mi'),
'Not looking at this time',
'NA');
insert into KJ_HDR (
HDR_SEQ,
EMPL_ID,
EFF_ST_DT,
PLACE_OF_BIRTH,
CREATE_DT,
MOBILITY_STATUS_TYPE,
MOBILITY_AVAIL_DT ) values (144,
'123456',
to_date('02/14/2012 00:00','mm/dd/yyyy hh24:mi'),
'MA',
to_date('02/14/2012 13:05','mm/dd/yyyy hh24:mi'),
'A',
'A');
insert into KJ_HDR (
HDR_SEQ,
EMPL_ID,
EFF_ST_DT,
PLACE_OF_BIRTH,
CREATE_DT,
MOBILITY_STATUS_TYPE,
MOBILITY_AVAIL_DT ) values (226,
'987654',
to_date('02/24/2012 00:00','mm/dd/yyyy hh24:mi'),
Null,
to_date('02/24/2012 14:57','mm/dd/yyyy hh24:mi'),
'Not looking at this time',
'NA');
insert into KJ_HDR (
HDR_SEQ,
EMPL_ID,
EFF_ST_DT,
PLACE_OF_BIRTH,
CREATE_DT,
MOBILITY_STATUS_TYPE,
MOBILITY_AVAIL_DT ) values (1,
'584949',
to_date('01/19/2012 00:00','mm/dd/yyyy hh24:mi'),
'Bankok',
to_date('01/19/2012 00:00','mm/dd/yyyy hh24:mi'),
Null,
Null);
-- insert into RW_CERT
insert into RW_CERT (
CERT_SEQ,
HDR_SEQ,
EMPL_ID,
EFF_ST_DT,
CERT_TYPE,
CERT_NAME,
CERT_FLAG,
CERT_DT,
CREATE_DT) values (245,
272,
'345234',
to_date('02/27/2012 00:00','mm/dd/yyyy hh24:mi'),
'ITIL',
'v3: Foundation',
Null,
to_date('10/01/2009 00:00','mm/dd/yyyy hh24:mi'),
to_date('02/27/2012 16:38','mm/dd/yyyy hh24:mi'),
insert into RW_CERT (
CERT_SEQ,
HDR_SEQ,
EMPL_ID,
EFF_ST_DT,
CERT_TYPE,
CERT_NAME,
CERT_FLAG,
CERT_DT,
CREATE_DT) values (242,
272,
'345234',
to_date('02/27/2012 00:00','mm/dd/yyyy hh24:mi'),
'Microsoft',
'Microsoft Certified Systems Engineer (MCSE)',
Null,
to_date('01/01/1994 00:00','mm/dd/yyyy hh24:mi'),
to_date('02/27/2012 16:37','mm/dd/yyyy hh24:mi'),
insert into RW_CERT (
CERT_SEQ,
HDR_SEQ,
EMPL_ID,
EFF_ST_DT,
CERT_TYPE,
CERT_NAME,
CERT_FLAG,
CERT_DT,
CREATE_DT) values (281,
341,
'988999',
to_date('02/29/2012 00:00','mm/dd/yyyy hh24:mi'),
'American Society for Quanlity',
'Biomedical Auditor',
Null,
to_date('01/01/1950 00:00','mm/dd/yyyy hh24:mi'),
to_date('02/29/2012 15:09','mm/dd/yyyy hh24:mi'),
insert into RW_CERT (
CERT_SEQ,
HDR_SEQ,
EMPL_ID,
EFF_ST_DT,
CERT_TYPE,
CERT_NAME,
CERT_FLAG,
CERT_DT,
CREATE_DT) values (282,
341,
'988999',
to_date('02/29/2012 00:00','mm/dd/yyyy hh24:mi'),
'Human Resources',
'Global Professional in Human Resources (GPHR)',
Null,
to_date('05/01/1950 00:00','mm/dd/yyyy hh24:mi'),
to_date('02/29/2012 15:09','mm/dd/yyyy hh24:mi'),
insert into RW_CERT (
CERT_SEQ,
HDR_SEQ,
EMPL_ID,
EFF_ST_DT,
CERT_TYPE,
CERT_NAME,
CERT_FLAG,
CERT_DT,
CREATE_DT) values (243,
272,
'345234',
to_date('02/27/2012 00:00','mm/dd/yyyy hh24:mi'),
'PMI',
'(PMP) Project Management Professional',
Null,
to_date('07/01/2007 00:00','mm/dd/yyyy hh24:mi'),
to_date('02/27/2012 16:38','mm/dd/yyyy hh24:mi'),
insert into RW_CERT (
CERT_SEQ,
HDR_SEQ,
EMPL_ID,
EFF_ST_DT,
CERT_TYPE,
CERT_NAME,
CERT_FLAG,
CERT_DT,
CREATE_DT) values (283,
341,
'988999',
to_date('02/29/2012 00:00','mm/dd/yyyy hh24:mi'),
'CISSP',
Null,
'1',
to_date('02/01/1950 00:00','mm/dd/yyyy hh24:mi'),
to_date('02/29/2012 15:09','mm/dd/yyyy hh24:mi'),
insert into RW_CERT (
CERT_SEQ,
HDR_SEQ,
EMPL_ID,
EFF_ST_DT,
CERT_TYPE,
CERT_NAME,
CERT_FLAG,
CERT_DT,
CREATE_DT) values (284,
341,
'988999',
to_date('02/29/2012 00:00','mm/dd/yyyy hh24:mi'),
'COMP TIA',
'CompTIA CTP+',
Null,
to_date('06/01/1950 00:00','mm/dd/yyyy hh24:mi'),
to_date('02/29/2012 15:09','mm/dd/yyyy hh24:mi'),
insert into RW_CERT (
CERT_SEQ,
HDR_SEQ,
EMPL_ID,
EFF_ST_DT,
CERT_TYPE,
CERT_NAME,
CERT_FLAG,
CERT_DT,
CREATE_DT) values (244,
272,
'345234',
to_date('02/27/2012 00:00','mm/dd/yyyy hh24:mi'),
'Six Sigma',
'Green Belt',
Null,
to_date('01/01/2010 00:00','mm/dd/yyyy hh24:mi'),
to_date('02/27/2012 16:38','mm/dd/yyyy hh24:mi'),
-- insert into RW_EDU
insert into RW_EDU (
EDU_SEQ,
HDR_SEQ,
EMPL_ID,
DEGREE_TYPE,
DISCIPLINE,
OTHER,
UNIVERSITY,
GRADUATION_DT,
CREATE_DT,
EFF_ST_DT) values (229,
270,
'123456',
'High School Diploma',
Null,
Null,
Null,
to_date('06/27/1976 00:00','mm/dd/yyyy hh24:mi'),
to_date('02/27/2012 14:04','mm/dd/yyyy hh24:mi'),
insert into RW_EDU (
EDU_SEQ,
HDR_SEQ,
EMPL_ID,
DEGREE_TYPE,
DISCIPLINE,
OTHER,
UNIVERSITY,
GRADUATION_DT,
CREATE_DT,
EFF_ST_DT) values (281,
321,
'567890',
'MS',
'Information Systems',
Null,
'SU',
to_date('06/25/1998 00:00','mm/dd/yyyy hh24:mi'),
to_date('02/29/2012 06:11','mm/dd/yyyy hh24:mi'),
insert into RW_EDU (
EDU_SEQ,
HDR_SEQ,
EMPL_ID,
DEGREE_TYPE,
DISCIPLINE,
OTHER,
UNIVERSITY,
GRADUATION_DT,
CREATE_DT,
EFF_ST_DT) values (233,
272,
'345234',
'MBA',
'Business',
Null,
'UMUC',
Null,
to_date('02/27/2012 16:37','mm/dd/yyyy hh24:mi'),
insert into RW_EDU (
EDU_SEQ,
HDR_SEQ,
EMPL_ID,
DEGREE_TYPE,
DISCIPLINE,
OTHER,
UNIVERSITY,
GRADUATION_DT,
CREATE_DT,
EFF_ST_DT) values (287,
327,
'836989',
'BS',
'Journalism',
Null,
'University of Maryland College Park',
to_date('05/01/1987 00:00','mm/dd/yyyy hh24:mi'),
to_date('02/29/2012 11:34','mm/dd/yyyy hh24:mi'),
insert into RW_EDU (
EDU_SEQ,
HDR_SEQ,
EMPL_ID,
DEGREE_TYPE,
DISCIPLINE,
OTHER,
UNIVERSITY,
GRADUATION_DT,
CREATE_DT,
EFF_ST_DT) values (234,
272,
'345234',
'MS',
'Public Policy',
Null,
'Georgetown University',
Null,
to_date('02/27/2012 16:37','mm/dd/yyyy hh24:mi'),
insert into RW_EDU (
EDU_SEQ,
HDR_SEQ,
EMPL_ID,
DEGREE_TYPE,
DISCIPLINE,
OTHER,
UNIVERSITY,
GRADUATION_DT,
CREATE_DT,
EFF_ST_DT) values (225,
266,
'514275',
'BA',
'Communications',
Null,
'Penn State University',
to_date('05/27/1986 00:00','mm/dd/yyyy hh24:mi'),
to_date('02/27/2012 13:55','mm/dd/yyyy hh24:mi'),
insert into RW_EDU (
EDU_SEQ,
HDR_SEQ,
EMPL_ID,
DEGREE_TYPE,
DISCIPLINE,
OTHER,
UNIVERSITY,
GRADUATION_DT,
CREATE_DT,
EFF_ST_DT) values (235,
272,
'345234',
'BS',
'Foreign Service',
Null,
'Georgetown University',
Null,
to_date('02/27/2012 16:37','mm/dd/yyyy hh24:mi'),
insert into RW_EDU (
EDU_SEQ,
HDR_SEQ,
EMPL_ID,
DEGREE_TYPE,
DISCIPLINE,
OTHER,
UNIVERSITY,
GRADUATION_DT,
CREATE_DT,
EFF_ST_DT) values (236,
273,
'712712',
'BS',
'Mechanical Engineering',
Null,
'University of California, Davis',
to_date('06/27/1977 00:00','mm/dd/yyyy hh24:mi'),
to_date('02/27/2012 16:40','mm/dd/yyyy hh24:mi'),
insert into RW_EDU (
EDU_SEQ,
HDR_SEQ,
EMPL_ID,
DEGREE_TYPE,
DISCIPLINE,
OTHER,
UNIVERSITY,
GRADUATION_DT,
CREATE_DT,
EFF_ST_DT) values (186,
226,
'987654',
'BM',
'NOTHING ',
Null,
'SOME PLACE',
Null,
to_date('02/24/2012 14:57','mm/dd/yyyy hh24:mi'),
insert into RW_EDU (
EDU_SEQ,
HDR_SEQ,
EMPL_ID,
DEGREE_TYPE,
DISCIPLINE,
OTHER,
UNIVERSITY,
GRADUATION_DT,
CREATE_DT,
EFF_ST_DT) values (301,
341,
'988999',
'BS',
'Computer Science',
Null,
'Western Illinois University',
to_date('12/01/1999 00:00','mm/dd/yyyy hh24:mi'),
to_date('02/29/2012 15:09','mm/dd/yyyy hh24:mi'),
SQL USED to get the CLOB, ALL fields
select distinct empl_id, hdr_seq, dbms_crypto.hash(edu_clob,1)
from
( select a.empl_id, a.hdr_seq ,
clobagg (degree_type || decode (discipline,NULL,NULL, ' in ' || discipline)
|| decode( University, NULL,NULL,' from ' || University )
|| decode(graduation_dt, NULL,NULL,' on ' || to_char(graduation_dt ,'MM-DD-YYYY'))
) over ( partition by a.hdr_seq) as edu_clob
from rw_edu a,kj_hdr b where a.hdr_seq =b.hdr_seq )
merge into kj_hdr K
using (
select distinct empl_id, hdr_seq , edu_clob from ( select a.empl_id, a.hdr_seq,
clobagg (degree_type || decode (discipline,NULL,NULL, ' in ' || discipline)
|| decode( University, NULL,NULL,' from ' || University )
|| decode(graduation_dt, NULL,NULL,' on ' || to_char(graduation_dt ,'MM-DD-YYYY'))
) over ( partition by a.hdr_seq) as edu_clob
from rw_edu a,kj_hdr b where a.hdr_seq =b.hdr_seq )) r
on ( K.hdr_Seq = r.hdr_seq )
when matched then update set K.edu_clob = r.edu_clob
----- I need distinct rows.
Thanks again for the time.
Regards -
Query help in select Distinct on one column.
CREATE GLOBAL TEMPORARY TABLE Table1 (
ID1 varchar2(100) ,
Name1 varchar2(100),
Name11 varchar2(100)
insert into Table1 values ('a','n1','h3');
insert into Table1 values('b','n2','h2');
insert into Table1 values('a','n3','h1');
insert into Table1 values('c','n4','h5');
insert into Table1 values ('c','n5','h4');
insert into Table1 values('d','n6','h6');
select * from Table1;
ID1,NAME1, NAME11
a, n1, h3
b, n2, h2
a, n3, h1
c, n4, h5
c, n5, h4
d, n6, h6
I am trying to select distinct ID1 and all values associated with it which is max row.I want to result as -
ID1,NAME1, NAME11
a, n3, h1
b, n2, h2
c, n5, h4
d, n6, h6
Can you please help me to write simple query to get above result.
Edited by: 871447 on Jul 25, 2011 9:42 AM
Edited by: 871447 on Jul 25, 2011 9:45 AMHi,
Do a self-join, to combine the two rows for each value of id1 onto one output row.
Make it an outer join, in case there is only one row with a vlaue for id1.
SELECT l.id1
, l.name1
, NVL ( r.name11
, l.name11
) AS name11
FROM table1 l
LEFT OUTER JOIN table1 r ON l.id1 = r.id1
AND l.name1 < r.name1
;Edited by: Frank Kulash on Jul 25, 2011 12:57 PM
Sorry, I mis-read the problem.
Lee's solution, above, assumes that name1 is unique, as it is in your sample data.
What output would you want if that's not the case?
If name1 is not unique, but the combination of (id1, name1) is unique, then you can modify Lee's solution like this:
SELECT *
FROM table1
WHERE (id1, name1) IN (
SELECT id1
, MAX (name1)
FROM table1
GROUP BY id1
;Or, if you can't make any assumptions about uniqueness, you might need something like this:
WITH got_r_num AS
SELECT id1, name1, name11
, ROW_NUMBER () OVER ( PARTITION BY id1
ORDER BY name1 DESC
, name11 DESC
) AS r_num
FROM table1
SELECT id1, name1, name11
FROM got_r_num
WHERE r_num = 1
; -
No distinction between NULL and space
No distinction between NULL and space. When you see the resultset, in PL/SQL developer, you will see that the NULL value is in yellow colour while column data having spaces is in white colour. In the new tool, there is not distinction between the two, so each time we will have to use the NVL function to determine the value in the column, which I would not like to do.
An option in Preferences could be created, so that it was possible to choose as values NULL would be shown, as already it occurs in other tools.
-
So when I enter:
SELECT opened_by from(
SELECT ps."NUMBER",
ps.opened_by,
ps.assignee_name,
ps.closed_by,
listagg(att.type,',') within group(order by att.type) actions,
listagg(att.description_txt,',') within group (order by att.description_txt) descs
from tableps ps
LEFT JOIN activity_txt att ON ps."NUMBER" = att."NUMBER" and att.type in('Assignment','Reassignment')
where open_time between to_date('01-OCT-2012','DD-MON-YYYY') and to_date('31-OCT-2013','DD-MON-YYYY')
and ((ps.opened_by=ps.closed_by) and (ps.closed_by=ps.assignee_name) and (ps.assignee_name=ps.opened_by))
group by ps."NUMBER",ps.opened_by,ps.assignee_name,ps.closed_by
where (actions not like '%Reass%'or actions is null)
and (descs like ('%NONE to '|| opened_by ||'%') or descs is null)
and (descs not like '%,%' or descs is NULL);
All is well in the world...however when I add distinct to the outer select I get the
ORA-01489: result of string concatenation is too long
01489. 00000 - "result of string concatenation is too long"
*Cause: String concatenation result is more than the maximum size.
*Action: Make sure that the result is less than the maximum size.
I don't understand the difference why one would work and one doesn't.I little changed your quesry,
Please try, if you are getting same error, then it means you have very large desciptions in description_txt column.
Pleasech check :
https://forums.oracle.com/thread/2596075
https://forums.oracle.com/message/10601105#10601105
SELECT T."NUMBER",
T.opened_by,
T.assignee_name,
T.closed_by,
listagg(T.type,',') within GROUP(ORDER BY T.type) actions,
listagg(T.description_txt,',') within GROUP (ORDER BY T.description_txt) descs
FROM
(SELECT
ps."NUMBER",
ps.opened_by,
ps.assignee_name,
ps.closed_by,att.type, att.description_txt
FROM tableps ps LEFT JOIN activity_txt att ON ps."NUMBER" = att."NUMBER" AND att.type IN('Assignment','Reassignment')
WHERE open_time BETWEEN to_date('01-OCT-2012','DD-MON-YYYY') AND to_date('31-OCT-2013','DD-MON-YYYY')
AND ((ps.opened_by =ps.closed_by)
AND (ps.closed_by =ps.assignee_name)
AND (ps.assignee_name=ps.opened_by))
and (att.type NOT LIKE '%Reass%' OR att.type IS NULL)
AND (att.description_txt LIKE ('%NONE to '|| opened_by ||'%') OR att.description_txt IS NULL)
AND (att.description_txt NOT LIKE '%,%'OR att.description_txt IS NULL)) T
Group by T."NUMBER",
T.opened_by,
T.assignee_name,
T.closed_by
And carefully read Solomon Yakobson's and Frank Kulash's replies.
Regards
Mahir M. Quluzade -
Removing the Duplicate Values from output without using Keyword DISTINCT
Hi,
I'm running the below query without DISTINCT Keyword and getting Duplicate results. can you please tell me what needs to be done if I want unique values without using Distinct.
select hra.Location_code
,hra.Description
,hra.Address_line_1
,hra.Address_line_2
,hra.Address_line_3
,hra.town_or_city
,hra.Region_1
,hra.Postal_Code
,hra.country
,hra.attribute1
,hra.attribute5
,hra.attribute6
,hra.attribute8
,hra.attribute9
,hra.attribute2
,hra.attribute3
,hra.attribute4
,hra.attribute7
,hra.attribute10
from hr_locations_all hra
,per_all_people_f papf
,per_person_types ppt
, per_person_type_usages_f pptuf
,hr_all_organization_units haou
,hr_all_organization_units haou1
where 1=1
and hra.business_group_id = papf.business_group_id
and hra.business_group_id = ppt.business_group_id
and pptuf.person_id = papf.person_id
and pptuf.person_type_id = ppt.person_type_id
and ppt.system_person_type = 'EMP'
and ((hra.inactive_date is null) or (trunc(hra.inactive_date)>= to_date('01/01/2012','mm/dd/yyyy')))
and to_date('01/01/2012','mm/dd/yyyy') between trunc(pptuf.effective_start_date) and trunc(pptuf.effective_end_date)
and((papf.effective_end_date is null) or (trunc(papf.effective_end_date)>= to_date('01/01/2012','mm/dd/yyyy')))
and ((haou1.date_to is null) or (trunc(haou1.date_to)>= to_date('01/01/2012','mm/dd/yyyy')))
and papf.business_group_id = haou.organization_id
and hra.location_id = haou1.location_id;Hi,
Try using this Code
select hra.Location_code
,hra.Description
,hra.Address_line_1
,hra.Address_line_2
,hra.Address_line_3
,hra.town_or_city
,hra.Region_1
,hra.Postal_Code
,hra.country
,hra.attribute1
,hra.attribute5
,hra.attribute6
,hra.attribute8
,hra.attribute9
,hra.attribute2
,hra.attribute3
,hra.attribute4
,hra.attribute7
,hra.attribute10
from hr_locations_all hra
,per_all_people_f papf,
per_all_assignments_f paaf,
per_person_types ppt
, per_person_type_usages_f pptuf
,hr_all_organization_units haou
--,hr_all_organization_units haou1
where 1=1
and
hra.business_group_id = papf.business_group_id
and hra.business_group_id = ppt.business_group_id
and pptuf.person_id = papf.person_id
and papf.person_id=paaf.person_id
and pptuf.person_type_id = ppt.person_type_id
and ppt.system_person_type = 'EMP'
--and ((hra.inactive_date is null) or (trunc(hra.inactive_date)>= to_date('01/01/2012','mm/dd/yyyy')))
and to_date('01/01/2012','mm/dd/yyyy') between trunc(pptuf.effective_start_date) and trunc(pptuf.effective_end_date)
--and((papf.effective_end_date is null) or (trunc(papf.effective_end_date)>= to_date('01/01/2012','mm/dd/yyyy')))
--and((paaf.effective_end_date is null) or (trunc(paaf.effective_end_date)>= to_date('01/01/2012','mm/dd/yyyy')))
and to_date('01/01/2012','mm/dd/yyyy') between trunc(papf.effective_start_date) and trunc(papf.effective_end_date)
and to_date('01/01/2012','mm/dd/yyyy') between trunc(paaf.effective_start_date) and trunc(paaf.effective_end_date)
--and ((haou1.date_to is null) or (trunc(haou1.date_to)>= to_date('01/01/2012','mm/dd/yyyy')))
--and papf.business_group_id = haou.organization_id
and paaf.location_id=hra.location_id
and paaf.organization_id=haou.organization_id
--and papf.employee_number='1010008830'
and hra.location_id = haou.location_id; -
How to get distinct values from a list and display in a ListView webpart.
Hi,
I have a requirement in which I need to pull unique/distinct values from a custom list and then display it via a listview webpart. Can any one suggest how this can be done.
If possible please share the CAMEL query to fetch distinct values from a custom list.
Thanks,
AnkitHi Ankit,
Is there any particular reason that the values need to be shown in a list view web part? Are you going to use that web part for filtering via web part connections?
I ask because the enterprise site collection features include the SharePoint List Filter web part, which may accomplish what you're looking for.
If you just need to display the values in a grid view, you might have more luck with the JavaScript Client Object Model. Try putting the following in a text file:
<style>
.CustomTableClass{display:table;table-layout:fixed}
.CustomRowClass{display:table-row;}
</style>
<div id="distinct_values_div" class="CustomTableClass">
<img src="/_layouts/loading.gif" />
</div>
<script language="JavaScript" type="text/JavaScript">
var siteUrl = '/sitecollection/web'; //use the actual subsite URL here
var listName = 'mylist'; // use the actual list name here
var field = "Title" // use the actual field you want to display here
var divToUpdate = document.getElementById("distinct_values_div");
var rowClass = "CustomRowClass";
ExecuteOrDelayUntilScriptLoaded(function(){
var clientContext = new SP.ClientContext(siteUrl);
var web = clientContext.get_web();
var lists = web.get_lists();
var list = lists.getByTitle(listName);
var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml('<View><Query></Query><RowLimit>500</RowLimit></View>');
this.collListItem = list.getItems(camlQuery);
clientContext.load(collListItem,"Include ("+field+")");
clientContext.executeQueryAsync(
Function.createDelegate(this, this.onQuerySucceeded),
Function.createDelegate(this, this.onQueryFailed));
},"sp.js");
function onQueryFailed(sender, args){
divToUpdate.innerHTML = 'Unable to retrieve values: '+args.get_message());
function onQuerySucceeded(sender, args){
var allValues = [];
var listItemEnumerator = collListItem.getEnumerator();
divToUpdate.innerHTML = "";
while(listItemEnumerator.moveNext()){
var listItem = listItemEnumerator.get_current();
if(!containsString(allValues,listItem.get_item(field)){
var value = listItem.get_item(field);
allValues.push(value);
var newDiv = document.createElement("div");
newDiv.className = rowClass;
newDiv.innerHTML = value;
divToUpdate.appendChild(newDiv);
function containsString(strArray, text){
var contains = false;
for (var i=0; i<strArray.length; i++){
if(strArray[i]==text){contains = true; break;}
return contains;
</script>
Upload the text file to a library on the site, then add a content editor web part to a page where you want the distinct values to appear. In the content editor web part's properties, edit the Content Link so that it links directly to the text file. This
will cause the JavaScript to run on the page. -
Get distinct values from a coma seperated string variable
Hi ,
I am getting an comma seperated string as in parameter, now i want to get the distinct values from that string and will use those values to pass it to a query.
any helptry this:
sorry about the messiness - it's just quickly copied from some badly formatted code....
TYPE T_FieldArray IS TABLE OF varchar2(255) INDEX BY BINARY_INTEGER;
function SPLIT_CSV_FIELDS (
p_Input_Str in varchar2,
p_Delimiter in varchar2,
p_Quote_Char in varchar2)
return t_fieldarray is
v_FieldArray T_FieldArray;
v_input_str varchar2(4000);
v_field_str varchar2(255);
v_pos number;
e number := 0;
v_delim_str varchar2(3);
cur_pos number;
begin
loop
-- find each delimiter char in string
v_pos := INSTR(v_input_str, p_Delimiter);
-- each time delimiter char is found
if v_pos > 0 then
-- current field value is current string to position prior to delimiter char
v_field_str := UPPER(SUBSTR(v_input_str, 1, v_pos - 1));
-- remove quote char from end of field (if any)
v_field_str := TRIM(TRANSLATE(v_field_str, NVL(p_Quote_Char, p_Delimiter), ' '));
-- increment element number
e := e + 1;
-- get remainder of input string to check
v_input_str := SUBSTR(v_input_str, v_pos + 1, LENGTH(v_input_str) - v_pos);
v_FieldArray(e) := v_field_str;
else
-- increment element number
e := e + 1;
-- last field value is what's left of input string less quote char (if any)
v_field_str := TRIM(TRANSLATE(UPPER(v_input_str), NVL(p_Quote_Char, p_Delimiter), ' '));
v_FieldArray(e) := v_field_str;
exit;
end if;
end loop;
return v_FieldArray;
end; -
"How to get distinct values of sharepoint column using SSRS"
Hi,
I have integrated sharepoint list data to SQL Server reporting services. I am using the below to query sharepoint list data using sql reporting services.
<Query>
<SoapAction>http://schemas.microsoft.com/sharepoint/soap/GetListItems</SoapAction>
<Method Namespace="http://schemas.microsoft.com/sharepoint/soap/" Name="GetListItems">
<Parameters>
<Parameter Name="listName">
<DefaultValue>{GUID of list}</DefaultValue>
</Parameter>
<Parameter Name="viewName">
<DefaultValue>{GUID of listview}</DefaultValue>
</Parameter>
<Parameter Name="rowLimit">
<DefaultValue>9999</DefaultValue>
</Parameter>
</Parameters>
</Method>
<ElementPath IgnoreNamespaces="True">*</ElementPath>
</Query>
By using this query, I am getting a dataset which includes all the columns of sharepoint list. Among these columns, I wanted to display only 2 columns (i.e Region and Sales type) using chart. I have created a Region parameter but when I click preview, the drop down box is giving me all the repeatative values of region like RG1,RG1,RG1,RG2,RG2,RG2,RG2,RG3.......... I wanted to display only distinct values of Region parameter so that whenever end user select region from the parameter drop down, it will display the respective value of Sales type column.
Also when I select only RG1 parameter, it is giving me a chart including the sales type of all the Regions. (it should display me only the sales type of RG1) How can I link these 2 columns so that they will display the values respectively.
I would really appreciate if anyone can help me out with this.
Thanks,
Sam.Hi Sam,
By code, the CAML language doesn’t have any reserved word (or tag) to set this particular filter to remove duplicate results.
In this case, we could use the custom code to get distinct records.
Here are the detailed steps:
1. Create a hidden parameter that gets all the records in one field.
Note: Please create another dataset that is same of the main dataset. This dataset is used for the parameter.
2. Create a function that used to remove the duplicate records.
Here is the code:
Public Shared Function RemoveDups(ByVal items As String) As String
Dim noDups As New System.Collections.ArrayList()
Dim SpStr
SpStr = Split(items ,",")
For i As Integer=0 To Ubound(Spstr)
If Not noDups.Contains(SpStr(i).Trim()) Then
noDups.Add(SpStr(i).Trim())
End If
Next
Dim uniqueItems As String() = New String(noDups.Count-1){}
noDups.CopyTo(uniqueItems)
Return String.Join(",", uniqueItems)
End Function
3. Create another parameter that will be used for filtering the maindata.
Please set the available value to be =Split(Code.RemoveDups(JOIN(Parameters!ISSUE_STATUS_TEMP.Value, ",")), ",")
And the default value to be the value you what such as the first value:
=Split(Code.RemoveDups(JOIN(Parameters!ISSUE_STATUS_TEMP.Value, ",")), ",").(0)
4. Go to the main dataset. Open the property window of this dataset.
5. In the “Filters” tab, set the filter to be:
Expression: <The field to be filter>
Operator: =
Value: =Parameters!Region.Value
The parameter “Region” should be the parameter we created in the step3.
Now, we should get distinct values of SharePoint columns.
If there is anything unclear, please feel free to ask.
Thanks,
Jin
Jin Chen - MSFT -
Get distinct values from plsql array
Hi,
I have declared a variable as below in plsql proc.
type t_itemid is table of varchar2(10);
inserted set of items in to this using a program
now i want distinct values from that array how can i get it.I am using 9i so i cannot use set operator and more over my problem is that i am declaring the variable inside the plsql block . when i tried i am getting the below errors:
SQL> r
1 declare
2 type t_type is table of varchar2(10);
3 v_type t_type;
4 begin
5 v_type := t_type('toys','story','good','good','toys','story','dupe','dupe');
6 for i in (select column_value from table(v_type)) loop
7 dbms_output.put_line(i.column_value);
8 end loop;
9* end;
for i in (select column_value from table(v_type)) loop
ERROR at line 6:
ORA-06550: line 6, column 41:
PLS-00642: local collection types not allowed in SQL statements
ORA-06550: line 6, column 35:
PL/SQL: ORA-22905: cannot access rows from a non-nested table item
ORA-06550: line 6, column 10:
PL/SQL: SQL Statement ignored
ORA-06550: line 7, column 22:
PLS-00364: loop index variable 'I' use is invalid
ORA-06550: line 7, column 1:
PL/SQL: Statement ignored -
CE function to get distinct values from Column table
Hi All,
Could you please let me know the appropriate CE function to get the distinct values from column table.
IT_WORK = SELECT DISTINCT AUFNR FROM :IT_WO_DETAILS;
Thank you.Hi,
If you have 10g, you can use Model( with model performance is better than connect by )
Solution
========================================================================
WITH t AS
(SELECT '0989.726332, 1234.567432, 3453.736379, 3453.736379, 0989.726332, 3453.736379, 1234.567432, 1234.567432, 0989.726332'
txt
FROM DUAL)
SELECT DISTINCT TRIM(CHAINE)
FROM T
MODEL
RETURN UPDATED ROWS
DIMENSION BY (0 POSITION)
MEASURES (CAST( ' ' AS VARCHAR2(50)) AS CHAINE ,txt ,LENGTH(REGEXP_REPLACE(txt,'[^,]+',''))+1 NB_MOT)
RULES
(CHAINE[FOR POSITION FROM 1 TO NVL(NB_MOT[0],1) INCREMENT 1] =
CASE WHEN NB_MOT[0] IS NULL THEN TXT[0] ELSE REGEXP_SUBSTR(txt[0],'[^,]+',1,CV(POSITION)) END );
=========================================================================
Demo
=======================================================================
SQL> WITH t AS
2 (SELECT '0989.726332, 1234.567432, 3453.736379, 3453.736379, 0989.726332, 3453.736379, 123
4.567432, 1234.567432, 0989.726332'
3 txt
4 FROM DUAL)
5 SELECT DISTINCT TRIM(CHAINE)
6 FROM T
7 MODEL
8 RETURN UPDATED ROWS
9 DIMENSION BY (0 POSITION)
10 MEASURES (CAST( ' ' AS VARCHAR2(50)) AS CHAINE ,txt ,LENGTH(REGEXP_REPLACE(txt,'[^,]+',''))+1 NB_MOT)
11 RULES
12 (CHAINE[FOR POSITION FROM 1 TO NVL(NB_MOT[0],1) INCREMENT 1] =
13 CASE WHEN NB_MOT[0] IS NULL THEN TXT[0] ELSE REGEXP_SUBSTR(txt[0],'[^,]+',1,CV(POSITION)) END );
TRIM(CHAINE)
3453.736379
1234.567432
0989.726332
SQL>
========================================================================
Maybe you are looking for
-
Why can't I just use my debit card for adding my child to family share?!
I want to use my child on family share but can't because I don't need or want a credit card, my bank has fraud protection, who actually just called me about fraud because I purchased the newest iPhone! I don't like credit cards. Why can't I just use
-
HT1257 Exporting photos with titles
Exporting photos for use on Windows through the Finder (not through Share) does not allow the titles I have attachged to the photos to be expored along with them. Does anyone know a way that will allow this?
-
How do i uninstall directv app?
does anyone know how to uninstall the directv app that i downloaded from their site? it's supposed to let me watch shows from their site. i can't find the thing anywhere except on my activity monitor where it is listed as NDSPCSHOWSERVER. i can't
-
Use of greater than, less than and ranges in release strategy
Hi, We are using release strategy on purchase order level. We have added purchasing group as one of the characteristics of this release strategy. As we have many purchasing groups in place we want to work with ranges of purchasing groups and also mak
-
Help! I am so close to having my project done. I have used iDVD several times and have never had this problem. I am trying to burn a DVD. I am doing 4:3, double layer disk, NTSC. The GB I am putting on the DVD+R DL is below the maximum you can put on