QoQ UNION distincts
What I am trying to do is UNION 2 result sets and only get the distinct values (obviously). The query being ran is:
<cfquery name="qryUseUnits" dbtype="query">
SELECT OptionDesc,
OptionValue
FROM qryUseUnits
UNION
SELECT Unit AS OptionDesc,
Unit AS OptionValue
FROM qMatSup
ORDER BY OptionDesc
</cfquery>
In the qryUseUnits table, one of the OptionDesc results is "Cubic Feet" where as for qMatSup, the value is "Cubic feet" (notice the difference in case). So when I dump the results of that query, I will get:
Cubic Feet
Cubic feet
Cubic Meters
The collation on the SQL Server is SQL_Latin1_General_CP1_CI_AS, and if I were to run this query directly on the server, I get distinct results for sure. However, with the case being different, CF doesn't seem to consider that distinct. Rather than change my SELECT statements to convert all column to upper- or lower-case, is there something different I can do with the query itself to get distinct values regardless of case?
Well, I got it to work as planned. It was a bit cleaner than I had imagined doing it and it works so that's what matters.
What I ended up doing was creating a list of all the "units" that were returned from qryUseUnits. I'd then use this list to determine which values not to select when doing a UNION to qMatSup.
<cfset arMatUnits = listToArray(uCase(valueList(qryUseUnits.OptionValue)))>
<cfquery name="qryUseUnits" dbtype="query">
SELECT OptionDesc,
OptionValue
FROM qryUseUnits
UNION
SELECT Unit AS OptionDesc,
Unit AS OptionValue
FROM qMatSup
WHERE UPPER(Unit) NOT IN (<cfqueryparam value="#listAppend(arrayToList(arMatUnits), 0)#" list="true" cfsqltype="CF_SQL_VARCHAR">)
</cfquery>
Similar Messages
-
How to eliminate duplicates from record types?
Below code errors out with "Wrong number of arguments in call to MULTISET...." error.
Declare
TYPE ln_x_tab IS RECORD(x1 number
,x2 VARCHAR2(4000)
,x3 VARCHAR2(4000)
,x4 VARCHAR2(4000)
,x5 VARCHAR2(4000)
TYPE ln_x_type IS TABLE OF ln_x_tab INDEX BY BINARY_INTEGER;
ln_x1 ln_x_type;
ln_dist_x1 ln_x_type;
gc_stmt varchar2(4000);
Begin
gc_stmt := ' SELECT x1, x2, x3, x4, x5 FROM table WHERE dynamic_conditions;
EXECUTE IMMEDIATE gc_stmt BULK COLLECT INTO ln_x1;
ln_dist_x1:= ln_x1 MULTISET UNION DISTINCT ln_x1;
End;
I need ln_dist_x1 to have distinct records from table. Please help.I agree with the other posters that it appears this would be better solved with SQL. However, to answer your question (without endorsing the approach), you need to use SQL "object" and "table" types in order compare records for uniqueness (using the MULTISET operators in PL/SQL). So, rather than using locally defined record and table types, you must create their equivalents using CREATE TYPE:
create or replace type ln_x_tab is object (
x1 number
,x2 VARCHAR2(4000)
,x3 VARCHAR2(4000)
,x4 VARCHAR2(4000)
,x5 VARCHAR2(4000)
, map member function toMapString
return varchar2
deterministic
create or replace TYPE ln_x_type IS TABLE OF ln_x_tab;
In order to compare object types (the elements of the table type) you'll need a MAP method defined for the object type, which "maps" the object state to a scalar data-type for comparisons. Depending on your data and its meaning, this could be simple or complex, as the result must be compatible with SQL data-type limitations (e.g. 4000 character-max strings)...
create or replace type body ln_x_tab
is
map member function toMapString
return varchar2
is
result varchar2(4000);
begin
-- Only one possible way to compare for uniqueness; it will depend on your data...
select to_char(self.x1) || ';' ||
to_char(ora_hash(self.x2)) || ';' ||
to_char(ora_hash(self.x3)) || ';' ||
to_char(ora_hash(self.x4)) || ';' ||
to_char(ora_hash(self.x5))
into result
from DUAL;
return result;
end;
end;
Then, your anonymous block would look like (I've added code to return the distinct results back in a REF CURSOR bind variable, which can be easily printed out in SQL*Plus or TOAD etc):
var results refcursor
Declare
ln_x1 ln_x_type;
ln_dist_x1 ln_x_type;
gc_stmt varchar2(4000);
Begin
gc_stmt := ' SELECT ln_x_tab(rownum, 'x2', 'x3', 'x4', 'x5') FROM DUAL connect by rownum <= :n';
EXECUTE IMMEDIATE gc_stmt BULK COLLECT INTO ln_x1 using 10;
ln_dist_x1:= ln_x_type() MULTISET UNION DISTINCT ln_x1;
open :results
for
select value(r)
from table(ln_dist_x1) r;
End;
print results
with the results looking like:
1 x2 x3 x4 x5
2 x2 x3 x4 x5
3 x2 x3 x4 x5
4 x2 x3 x4 x5
5 x2 x3 x4 x5
6 x2 x3 x4 x5
7 x2 x3 x4 x5
8 x2 x3 x4 x5
9 x2 x3 x4 x5
10 x2 x3 x4 x5
Again, I don't endorse this solution, I only offer it to demonstrate how you would use SQL O-R types to get it working.
Gerard -
집합 연산자(UNION, UNION ALL, INTERSECT, MINUS) 사용 예제
제품 : ORACLE SERVER
작성날짜 : 2002-04-12
집합 연산자(UNION, UNION ALL, INTERSECT, MINUS) 사용 예제
=========================================================
Purpose
집합 연산자인 union, union all, intersect, minus 의 사용방법을 알아보자.
Explanation
오라클에서 사용할 수 있는 집합 연산자는 union, union all, intersect,
minus 가 있다.
아래의 table은 예제에서 사용될 테이블이다.
SQL> select * from dept_a;
DEPTNO DNAME LOC
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
50 RND SEOUL
SQL> select * from dept_b;
DEPTNO DNAME LOC
20 RESEARCH DALLAS
30 SALES CHICAGO
60 FNA SEOUL
1. UNION Operator
union은 두 테이블의 자료를 하나의 결과로 가져올 때,
중복된 row가 있을 경우 하나의 row만을 return한다..
select 문 절에 사용하는 distinct 와 같은 효과로 생각할 수 있다.
SQL> select deptno, dname from dept_a
2 union
3 select deptno, dname from dept_b;
DEPTNO DNAME
10 ACCOUNTING
20 RESEARCH
30 SALES
40 OPERATIONS
50 RND
60 FNA
6 rows selected.
2. UNION ALL Operator
union all 은 union이 distinct 를 사용할 때와 달리 중복된
결과를 모두 return한다. 즉, 결과로 나오는 모든 row를 보여주게 된다.
SQL> select deptno, dname from dept_a
2 union all
3 select deptno, dname from dept_b;
DEPTNO DNAME
10 ACCOUNTING
20 RESEARCH
30 SALES
40 OPERATIONS
50 RND
20 RESEARCH
30 SALES
60 FNA
8 rows selected.
3. INTERSECT Operator
intersect 는 두 테이블의 결과중에 겹치는 row만을 return한다.
즉, 교집합된 결과로 생각할 수 있다.
SQL> select deptno, dname from dept_a
2 intersect
3 select deptno, dname from dept_b;
DEPTNO DNAME
20 RESEARCH
30 SALES
4. MINUS Operator
minus operator는 첫번째 테이블에서 두번째 테이블의 데이터를
제외한 나머지 row만 return한다.
SQL> select deptno, dname from dept_a
2 minus
3 select deptno, dname from dept_b;
DEPTNO DNAME
10 ACCOUNTING
40 OPERATIONS
50 RNDDefinitely a bug:
SQL> ALTER SESSION SET NLS_SORT=BINARY_CI
2 /
Session altered.
SQL> ALTER SESSION SET NLS_COMP=LINGUISTIC
2 /
Session altered.
SQL> with utbl as (
2 select chr(ascii('A') + level - 1) letter
3 from dual
4 connect by level < 27
5 ),
6 ltbl as (
7 select chr(ascii('a') + level - 1) letter
8 from dual
9 connect by level < 27
10 )
11 select letter
12 from utbl
13 minus
14 select letter
15 from ltbl
16 /
L
A
B
C
D
E
F
G
H
I
J
K
L
L
M
N
O
P
Q
R
S
T
U
V
L
W
X
Y
Z
26 rows selected.
SQL> with utbl as (
2 select chr(ascii('A') + level - 1) letter
3 from dual
4 connect by level < 27
5 ),
6 ltbl as (
7 select chr(ascii('a') + level - 1) letter
8 from dual
9 connect by level < 27
10 )
11 select * from (
12 select letter
13 from utbl
14 minus
15 select letter
16 from ltbl
17 )
18 /
no rows selected
SQL> SY. -
Nested tables and multiset operators in Oracle 10g
Consider the following scenario:
We have two identical relations R and S defined as:
CREATE TABLE R(
a INTEGER,
b table_type)
NESTED TABLE b STORE as b_1;
CREATE TABLE S(
a INTEGER,
b table_type)
NESTED TABLE b STORE as b_2;
where table_typ is defined as
CREATE TYPE table_typ AS TABLE OF VARCHAR2(8);
Suppose we have two instances of R and S, each having one tuple as follows: R(1,table_typ('a','b')) and S(1,table_typ('b','c')).
I would like to "merge" these two simple instances (e.g., achieve the effect of a simple SELECT * FROM R UNION SELECT * FROM S query) and obtain the following resulting instance: Result(1,table_typ('a','b','c')).
Would this be possible in Oracle 10g? A simple UNION does not work (I got a "inconsistent datatypes: expected - got SCOTT.TABLE_TYP" error). I also took a look at the MULTISET UNION operator over nested tables available in Oracle 10g, but it doesn't seem to get me anywhere. Any help on this would be greatly appreciated.
Thank you,
LauraOracle Database 10g Enterprise Edition Release 10.1.0.2.0 - 64bit Production
With the Partitioning, OLAP and Data Mining options
SQL> CREATE OR REPLACE TYPE table_type AS TABLE OF VARCHAR2 (8);
2 /
Type created.
SQL> CREATE TABLE r(
2 a INTEGER,
3 b table_type)
4 NESTED TABLE b STORE as b_1;
Table created.
SQL> CREATE TABLE s(
2 a INTEGER,
3 b table_type)
4 NESTED TABLE b STORE as b_2;
Table created.
SQL> INSERT INTO r VALUES (1, table_type ('a', 'b'));
1 row created.
SQL> INSERT INTO s VALUES (1, table_type ('b', 'c'));
1 row created.
SQL> COLUMN c FORMAT A10;
SQL> SELECT r.a, r.b MULTISET UNION DISTINCT s.b c
2 FROM r, s
3 WHERE r.a = s.a;
A C
1 TABLE_TYPE('a', 'b', 'c')
SQL> -
Trying to use the following within Apex:
CREATE TYPE location_typ AS OBJECT (
location_id NUMBER(4),
street_address VARCHAR2(40),
postal_code VARCHAR2(12),
city VARCHAR2(30),
state_province VARCHAR2(25));
CREATE TYPE nt_location_typ AS TABLE OF location_typ;
CREATE TYPE country_typ AS OBJECT (
country_id CHAR(2),
country_name VARCHAR2(40),
locations nt_location_typ);
CREATE TYPE nt_country_typ AS TABLE OF country_typ;
CREATE TABLE region_tab (
region_id NUMBER,
region_name VARCHAR2(25),
countries nt_country_typ)
NESTED TABLE countries STORE AS nt_countries_tab (
(PRIMARY KEY (NESTED_TABLE_ID, country_id))
ORGANIZATION INDEX COMPRESS
NESTED TABLE locations STORE AS nt_locations_tab);
Can get Apex to function in the Tabular Report mode by modifying the query to use the correct syntax:
select "REGION_ID",
"REGION_NAME",
c.COUNTRY_ID,
c.COUNTRY_NAME,
l.LOCATION_ID,
l.STREET_ADDRESS, l.POSTAL_CODE,
l.CITY,
l.STATE_PROVINCE
from "#OWNER#"."REGION_TAB", TABLE(COUNTRIES) C, TABLE(LOCATIONS) L
Built a 'Maintenance' form. Put the Region base column on it. Then built a tabular form (with an updateable query) on the same page to access the first level Nest ( countries). Haven't figured out how to actually edit the values yet, but feel comfortable I will.
But - trying to provide editing to the 2nd level nested table elements creates a problem. First, only 1 updateable query can be on a page. Hmmm - so to get around this I guess I have to build a new page that the calling updateable query will access when selecting one of the tabular form elements. Not elegant by any means. Was hoping to provide a blank form on the right side that would be populated by the Location Nested Table values when a select was made on the first level nest. Oh well.
Just curious how anyone has handled this? I could pass stack between pages for sure, but was hoping page regions would be sufficient to handle this.
Any white papers on this? Anything in the DEMO area to use as a template? The default Demo doesn't provide this based on querying user objects.
Thanks,
Dwight TaylorOracle Database 10g Enterprise Edition Release 10.1.0.2.0 - 64bit Production
With the Partitioning, OLAP and Data Mining options
SQL> CREATE OR REPLACE TYPE table_type AS TABLE OF VARCHAR2 (8);
2 /
Type created.
SQL> CREATE TABLE r(
2 a INTEGER,
3 b table_type)
4 NESTED TABLE b STORE as b_1;
Table created.
SQL> CREATE TABLE s(
2 a INTEGER,
3 b table_type)
4 NESTED TABLE b STORE as b_2;
Table created.
SQL> INSERT INTO r VALUES (1, table_type ('a', 'b'));
1 row created.
SQL> INSERT INTO s VALUES (1, table_type ('b', 'c'));
1 row created.
SQL> COLUMN c FORMAT A10;
SQL> SELECT r.a, r.b MULTISET UNION DISTINCT s.b c
2 FROM r, s
3 WHERE r.a = s.a;
A C
1 TABLE_TYPE('a', 'b', 'c')
SQL> -
Regarding Performance Tunning of Mapping & Process Flow
Hi,
i have around 60-70 GB data in Target database.
i need do improve the performance of Mapping and Process flow.
i have used lookup transformation in mapping.
Plz give me some tips for improving performance of Process.
Thanks,Please go through a Performance Tuning Book for Oracle 10gR2.
Most importantly remember that in Oracle 10g, your performace of mappings can be increased manifold by following these steps:
1. Do not design a mapping wherein you load a table and then select from that table to load another table and so on. This is a bad design.
2. Keep mappings as simple as possible. In other words if a mapping is complicated in terms of joins or other operators then split the mapping into more than one parts.
3. Also check that all your source tables should be analyzed using DBMS_STATS. Ensuring this one single step can make your work very easy.
4. Put indexes where you find your predicate has a very high selectivity. Also keep in mind the column ordering of the index.
5. Use Set Based operation, since it is always a good idea to achieve the result by running one single query rather than a loop and multiple inserts.
6. Use APPEND PARALLEL hint while loading the target tables. This will not generate wny redo and save time
7. Please have a recheck while usng some performance intensive operators like UNION, DISTINCT and AGGREGATION
8. When using a sequence operator to load a large table, check that the sequence should be cached with some values.
9. When loading large data HASH JOINS are the most appropriate more often than not. So you can use USE_HASH as the hint for selecting from large tables.
10. Filter out as much unrequired data from a table as soon as possible in the mapping before doing multiple joins.
I am sure there are many more ... the above is just a random list that I could remember now. Please go through Oracle Performance Tuning Guide, Tom Kyte's Oracle Expert One on One. Knowledge of performance tuning will grow with experience. I am also learning each day !!!
Regards
AP -
Case INSENSITIVE Columns on Oracle
Hello Friends,
Good Monday for everyone....
I would like to ask you guys if there is a way to create a case INSENSITIVE Columns on Oracle. I used on Sqlserver before the COLLATE sintax, and I was able to make a columns (just that one) INSENSITIVE.
I'm using oracle 10gr2 on Windows plataform and herte is my nls_parameters. My ideia is to search on this column without the need of performing a function UPPER and LOWER and etc...
NLS_LANGUAGE BRAZILIAN PORTUGUESE
NLS_TERRITORY BRAZIL
NLS_CURRENCY Cr$
NLS_ISO_CURRENCY BRAZIL
NLS_NUMERIC_CHARACTERS ,.
NLS_CALENDAR GREGORIAN
NLS_DATE_FORMAT DD/MM/RR
NLS_DATE_LANGUAGE BRAZILIAN PORTUGUESE
NLS_CHARACTERSET WE8MSWIN1252
NLS_SORT WEST_EUROPEAN
NLS_TIME_FORMAT HH24:MI:SSXFF
NLS_TIMESTAMP_FORMAT DD/MM/RR HH24:MI:SSXFF
NLS_TIME_TZ_FORMAT HH24:MI:SSXFF TZR
NLS_TIMESTAMP_TZ_FORMAT DD/MM/RR HH24:MI:SSXFF TZR
NLS_DUAL_CURRENCY Cr$
NLS_NCHAR_CHARACTERSET AL16UTF16
NLS_COMP BINARY
NLS_LENGTH_SEMANTICS BYTE
NLS_NCHAR_CONV_EXCP FALSE
tks a lot
KeenAPC wrote:
No, they mean a setting which makes "APC" or "apc" match "Apc".
There is nothing to be done on 10g, other than building a function based index on the column in question, so that any UPPER() searches are optimized.
Well, as Kamran Agayev already noted CI is available in 10g too. It also worth mentioning FBI creates a hidden column. Also, your statement
In 11g we have the option to set the NLS_SORT parameter so that any searches are case-insensitive (or indeed accent insensitive). Find out more.
is incomplete. NLS_SORT affects nothing but sort:
SQL> connect scott
Enter password: *****
Connected.
SQL> select * from v$version
2 /
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Prod
PL/SQL Release 10.2.0.4.0 - Production
CORE 10.2.0.4.0 Production
TNS for 32-bit Windows: Version 10.2.0.4.0 - Production
NLSRTL Version 10.2.0.4.0 - Production
SQL> with t as (
2 select 'Max' name from dual union all
3 select 'sam' name from dual union all
4 select 'Joe' name from dual union all
5 select 'max' name from dual union all
6 select 'joe' name from dual union all
7 select 'Sam' name from dual
8 )
9 select name
10 from t
11 order by name
12 /
NAM
Joe
Max
Sam
joe
max
sam
6 rows selected.
SQL> with t as (
2 select 'Max' name from dual union all
3 select 'sam' name from dual union all
4 select 'Joe' name from dual union all
5 select 'max' name from dual union all
6 select 'joe' name from dual union all
7 select 'Sam' name from dual
8 )
9 select name
10 from t
11 where name = 'max'
12 /
NAM
max
SQL> alter session set nls_sort = binary_ci
2 /
Session altered.
SQL> with t as (
2 select 'Max' name from dual union all
3 select 'sam' name from dual union all
4 select 'Joe' name from dual union all
5 select 'max' name from dual union all
6 select 'joe' name from dual union all
7 select 'Sam' name from dual
8 )
9 select name
10 from t
11 order by name
12 /
NAM
Joe
joe
max
Max
Sam
sam
6 rows selected.
SQL> with t as (
2 select 'Max' name from dual union all
3 select 'sam' name from dual union all
4 select 'Joe' name from dual union all
5 select 'max' name from dual union all
6 select 'joe' name from dual union all
7 select 'Sam' name from dual
8 )
9 select name
10 from t
11 where name = 'max'
12 /
NAM
max
SQL> with t as (
2 select 'Max' name from dual union all
3 select 'sam' name from dual union all
4 select 'Joe' name from dual union all
5 select 'max' name from dual union all
6 select 'joe' name from dual union all
7 select 'Sam' name from dual
8 )
9 select name
10 from t
11 where name like 'm%'
12 /
NAM
max
SQL> select 'Max' name from dual union
2 select 'max' name from dual
3 /
NAM
Max
max
SQL> with t as (
2 select 'Max' name from dual union all
3 select 'sam' name from dual union all
4 select 'Joe' name from dual union all
5 select 'max' name from dual union all
6 select 'joe' name from dual union all
7 select 'Sam' name from dual
8 )
9 select distinct name
10 from t
11 /
NAM
sam
Joe
joe
max
Sam
Max
6 rows selected.
SQL> As you can see, NLS_SORT alone works on sort but not on "searches". We also need to set NLS_COMP, which by default is BINARY. Prior to 10g R2 (I am not 100% sure, it could be prior 10g), the only NLS_COMP choice, besides BINARY, was ANSI. However, ANSI does not work with all comparison operators (e.g. does not work for LIKE, UNION, DISTINCT):
SQL> alter session set nls_sort = binary_ci
2 /
Session altered.
SQL> alter session set nls_comp=ansi
2 /
Session altered.
SQL> with t as (
2 select 'Max' name from dual union all
3 select 'sam' name from dual union all
4 select 'Joe' name from dual union all
5 select 'max' name from dual union all
6 select 'joe' name from dual union all
7 select 'Sam' name from dual
8 )
9 select name
10 from t
11 order by name
12 /
NAM
Joe
joe
max
Max
Sam
sam
6 rows selected.
SQL> with t as (
2 select 'Max' name from dual union all
3 select 'sam' name from dual union all
4 select 'Joe' name from dual union all
5 select 'max' name from dual union all
6 select 'joe' name from dual union all
7 select 'Sam' name from dual
8 )
9 select name
10 from t
11 where name = 'max'
12 /
NAM
Max
max
SQL> with t as (
2 select 'Max' name from dual union all
3 select 'sam' name from dual union all
4 select 'Joe' name from dual union all
5 select 'max' name from dual union all
6 select 'joe' name from dual union all
7 select 'Sam' name from dual
8 )
9 select name
10 from t
11 where name like 'm%'
12 /
NAM
max
SQL> select 'Max' name from dual union
2 select 'max' name from dual
3 /
NAM
Max
max
SQL> with t as (
2 select 'Max' name from dual union all
3 select 'sam' name from dual union all
4 select 'Joe' name from dual union all
5 select 'max' name from dual union all
6 select 'joe' name from dual union all
7 select 'Sam' name from dual
8 )
9 select distinct name
10 from t
11 /
NAM
sam
Joe
joe
max
Sam
Max
6 rows selected.
SQL> Starting 10g R2 NLS_COMP can be set to LINGUISTIC, which will also work for LIKE and UNION but not for DISTINCT:
SQL> alter session set nls_sort = binary_ci
2 /
Session altered.
SQL> alter session set nls_comp=linguistic
2 /
Session altered.
SQL> with t as (
2 select 'Max' name from dual union all
3 select 'sam' name from dual union all
4 select 'Joe' name from dual union all
5 select 'max' name from dual union all
6 select 'joe' name from dual union all
7 select 'Sam' name from dual
8 )
9 select name
10 from t
11 order by name
12 /
NAM
Joe
joe
max
Max
Sam
sam
6 rows selected.
SQL> with t as (
2 select 'Max' name from dual union all
3 select 'sam' name from dual union all
4 select 'Joe' name from dual union all
5 select 'max' name from dual union all
6 select 'joe' name from dual union all
7 select 'Sam' name from dual
8 )
9 select name
10 from t
11 where name = 'max'
12 /
NAM
Max
max
SQL> with t as (
2 select 'Max' name from dual union all
3 select 'sam' name from dual union all
4 select 'Joe' name from dual union all
5 select 'max' name from dual union all
6 select 'joe' name from dual union all
7 select 'Sam' name from dual
8 )
9 select name
10 from t
11 where name like 'm%'
12 /
NAM
Max
max
SQL> select 'Max' name from dual union
2 select 'max' name from dual
3 /
NAM
Max
SQL> with t as (
2 select 'Max' name from dual union all
3 select 'sam' name from dual union all
4 select 'Joe' name from dual union all
5 select 'max' name from dual union all
6 select 'joe' name from dual union all
7 select 'Sam' name from dual
8 )
9 select distinct name
10 from t
11 /
NAM
sam
Joe
joe
max
Sam
Max
6 rows selected.
SQL> However even LINGUISTIC does not work with:
• CLOB or NCLOB data types
• Object data types
• Table partitions
• Index-organized tables
SY. -
Nested Tables - Oracle Crashes !
Hello Everyone
You might help me to sleep tonight.
Ok, here is the problem.
I used a nested table to collect data. After collection, I get repeated records in collection result. I tried to operate to get a distinct result operating SQL operation but oracle gives nasty error and kicks me out the session.
HERE is the code :
create or replace package rule_engine
as
type t_course_count is table of number(2);
Procedure main;
end rule_engine;
create or replace package body rule_engine
as
procedure main
is
v_course_count t_course_count:=t_course_count(1,2,3,4);
i t_course_count;
begin
insert into table(i) select * from table(v_course_count);
end main;
end rule_engine;
nullOracle Database 10g Enterprise Edition Release 10.1.0.2.0 - 64bit Production
With the Partitioning, OLAP and Data Mining options
SQL> CREATE OR REPLACE TYPE table_type AS TABLE OF VARCHAR2 (8);
2 /
Type created.
SQL> CREATE TABLE r(
2 a INTEGER,
3 b table_type)
4 NESTED TABLE b STORE as b_1;
Table created.
SQL> CREATE TABLE s(
2 a INTEGER,
3 b table_type)
4 NESTED TABLE b STORE as b_2;
Table created.
SQL> INSERT INTO r VALUES (1, table_type ('a', 'b'));
1 row created.
SQL> INSERT INTO s VALUES (1, table_type ('b', 'c'));
1 row created.
SQL> COLUMN c FORMAT A10;
SQL> SELECT r.a, r.b MULTISET UNION DISTINCT s.b c
2 FROM r, s
3 WHERE r.a = s.a;
A C
1 TABLE_TYPE('a', 'b', 'c')
SQL> -
Only on tempfile used during sql sorts
environment : Entreprise 92010/W2K
My temp tablespace (locally managed and temporary) has 3 tempfile, each with autoextend and maxsize limit.
When i create an index on a big table, my 3 tempfile are used.
But when a big sort occurs during a sql statement, only one tempfile is used and i get an ora-1652.
Why all tempfiles are not used during sorts statements (union, max...) ?
This behavior can be easily tested :
- create a new temp ts with 3 small tempfile, autoextend on but very small maxsize
- alter the user who will do the sorts
- log on as user altered
- create an index on a big table => the 3 tempfiles will grow
- execute a query (max, min, union ,distinct...) => only one tempfile is used.
SQL sort always done in only one file or bug ?
Jean-Fran�ois L�guillierThe 3 tempfile belong to the same ts.
This ts is the temporary ts for my user which executes the sort sql statement.
During execution, i monitor size of the 3 files (from v$tempfile) : only one was used during query and when it reached maxsize, i got ora 1652 but fres space were available in the 2 others tempfile.
When i create a big index, i see changes in bytes for all tempfiles (in v$tempfile).
One of my customer has same problem. He added tempfile to his temp ts but sort statement failed again.
I tested this behavior with 92010/EE with W2K.
I think it's a bug but nothing appears in patchset 9204. -
Nested tables as separate lines in output
I'm working with Adobe forms using transaction SFP from the ABAP Workbench. I'm trying to construct a prototype of an SD invoice, with one internal table having the basic item data, and then a secondary table with further information, such as discounts, taxes, etc. The item number is part of both tables so that they can be related to each other. Using right-click and Create in the context I constructed a loop on the main table, and then under that a loop on the secondary table, with the equal item number as a condition. It all works, but in the output the secondary data comes out on the same line as the main item data, and when I try to drag it down to the next line in the layout, it changes its position in the data view also, so that it's outside the loop and prints only once, over the second main item line. Surely for an invoice or a purchase order it's normal to have one basic item line, and then one or more other lines with various other information for each item. It's very easy in both SAPscript and Smart Forms to have a loop within a loop displaying separate lines, but so far I haven't been able to get it to work with Adobe.
Oracle Database 10g Enterprise Edition Release 10.1.0.2.0 - 64bit Production
With the Partitioning, OLAP and Data Mining options
SQL> CREATE OR REPLACE TYPE table_type AS TABLE OF VARCHAR2 (8);
2 /
Type created.
SQL> CREATE TABLE r(
2 a INTEGER,
3 b table_type)
4 NESTED TABLE b STORE as b_1;
Table created.
SQL> CREATE TABLE s(
2 a INTEGER,
3 b table_type)
4 NESTED TABLE b STORE as b_2;
Table created.
SQL> INSERT INTO r VALUES (1, table_type ('a', 'b'));
1 row created.
SQL> INSERT INTO s VALUES (1, table_type ('b', 'c'));
1 row created.
SQL> COLUMN c FORMAT A10;
SQL> SELECT r.a, r.b MULTISET UNION DISTINCT s.b c
2 FROM r, s
3 WHERE r.a = s.a;
A C
1 TABLE_TYPE('a', 'b', 'c')
SQL> -
Help writing a cash on accounting vat report
Hi
One of our customers need to produce a cash on accounting vat report which SAP 2007 doesn't deal with.
Cash accounting works basically by including all sales invoice and purchase invoices paid or monies received for in a month
I need to be able to see how transactions have been reconcilled for the business partner
I am ok when an invoice has an incoming / outgoing payment linked to it but I need to know for example what happens when a credit note is allocated / reconciled to an invoice
Can anyone help me with the logic / table names please
Many thanks
Regards Andy
Edited by: Rui Pereira on Dec 23, 2008 4:06 PMI have this, but it creates two records. One for parent and one for child. I want the results all to be in one record though:
SELECT "", display_title as child, display_id, parent_id
From dmand_docsys_hier
Where display_id=7 and parent_id=6 and Upper(file_name)="_TESTFILE.PDF" and admin_project_oid=40
UNION distinct
Select display_title as Parent, "", display_id, parent_id
From dmand_docsys_hier
where display_id=6 and admin_project_oid=40
How could I get them in one record instead of two? -
Trigger error -deadlock detected while waiting for resource
with table1 as (
select '1' no,'1' id, 'N' flag,'' result from dual union all
select '2' no,'1' id, 'N' flag,'B' result from dual union all
select '3' no,'1' id, '' flag,'B' result from dual union all
select '4' no,'2' id, 'N' flag,'B' result from dual union all
select '5' no,'2' id, 'N' flag,'B' result from dual
select * from table1
I need to write a trigger with the condition that if Flag is set to 'Y', then all the values for the field 'result' for that particular ID should set a 'A'.
For the above table if I run the below query
update table1
set flag= 'Y' where no =1
The trigger result should be
with table1 as (
select '1' no,'1' id, 'Y' flag,'A' result from dual union all
select '2' no,'1' id, 'N' flag,'A' result from dual union all
select '3' no,'1' id, '' flag,'A' result from dual union all
select '4' no,'2' id, 'N' flag,'B' result from dual union all
select '5' no,'2' id, 'N' flag,'B' result from dual
select * from table1
I wrote the trigger as below...
CREATE OR REPLACE TRIGGER test
BEFORE UPDATE
ON table1 for each row
DECLARE
PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
if :new.flag = 'Y' then
update table1
set result = 'A'
where id = :new.id ;
commit;
end if;
end;
but giving follwing error.
ORA-00060: deadlock detected while waiting for resource
ORA-06512: at "test"
ORA-04088: error during execution of trigger 'test'
Please help to correct my trigger.# Firstly you cannot define trigger using on subquery clause - WITH. e.g. table1.
# You might have used a trick to use PRAGMA AUTONOMOUS TRANSACTION to isolate trigger transaction from the main transaction but the deadlock will certainly going to occur as the main transaction already hold the row level lock which you are trying to update in trigger code.
# We will try to use common technique to capture all the ID whose flag is set as 'Y' in row level trigger and then in statement level trigger after update will update the column - "resut" for the ID.
This is very simple test code for demonostration.
CREATE TABLE T
NO NUMBER,
ID NUMBER,
FLAG VARCHAR2(1),
RESULT VARCHAR2(1)
INSERT INTO T VALUES (1,1,'N',NULL);
INSERT INTO T VALUES (2,1,'N','B');
INSERT INTO T VALUES (3,1,'','B');
INSERT INTO T VALUES (4,2,'N','B');
INSERT INTO T VALUES (5,2,'N','B');
CREATE OR REPLACE PACKAGE PKG_T_MUTATING AS
TYPE IDTABTYPE IS TABLE OF T.ID%TYPE;
T_ID IDTABTYPE := IDTABTYPE();
PROCEDURE GET_UPDATE_ID(P_ID T.ID%TYPE);
PROCEDURE UPD_T;
END PKG_T_MUTATING;
CREATE OR REPLACE PACKAGE BODY PKG_T_MUTATING AS
PROCEDURE GET_UPDATE_ID(P_ID T.ID%TYPE) IS
BEGIN
T_ID.EXTEND;
T_ID(T_ID.COUNT) := P_ID;
DBMS_OUTPUT.PUT_LINE('T_ID ' || T_ID(T_ID.COUNT));
END GET_UPDATE_ID;
PROCEDURE UPD_T IS
V_ID PKG_T_MUTATING.IDTABTYPE := PKG_T_MUTATING.IDTABTYPE();
BEGIN
V_ID := V_ID MULTISET UNION DISTINCT T_ID;
IF V_ID.COUNT > 0 THEN
FORALL i IN 1..V_ID.COUNT
UPDATE T SET RESULT = 'A'
WHERE ID = V_ID(i);
END IF;
-- Cleanup
V_ID.DELETE;
T_ID.DELETE;
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE(DBMS_UTILITY.FORMAT_ERROR_STACK);
END UPD_T;
END PKG_T_MUTATING;
CREATE OR REPLACE TRIGGER TRG_TEST_BU
BEFORE UPDATE OF FLAG ON T FOR EACH ROW
WHEN (NEW.FLAG = 'Y')
BEGIN
pkg_t_mutating.get_update_id(:NEW.ID);
END;
CREATE OR REPLACE TRIGGER TRG_TEST_AU
AFTER UPDATE OF FLAG ON T
BEGIN
PKG_T_MUTATING.UPD_T;
END;
SQL>SELECT * FROM T;
NO ID FLAG RESULT
1 1 Y A
2 1 N B
3 1 B
4 2 N B
5 2 N B
SQL>UPDATE T SET FLAG = 'Y' WHERE NO = 1 AND ID = 1;
1 row updated.
SQL>SELECT * FROM T;
NO ID FLAG RESULT
1 1 Y A
2 1 N A
3 1 A
4 2 N B
5 2 N B
SQL>
{code} -
Is there anyway i could tune this query
Post deleted due to flawed SQL
Edited by: GarryB on Sep 22, 2008 4:54 AMYou could try using subquery factoring for this part of your query:
eg
with UNITS_PAKS_sum as
(SELECT sum(units_pakd) FROM carton_dtl WHERE carton_nbr = '00000999990000007527' AND sku_id = LMP_DEST.SKU_ID AND pkt_ctrl_nbr = '000000039')
add units_paks_sum into your from list
replace that sql with units_pakd (you have it in your columnlist and in your where clause.
There will be a cartesian join, but since the "table" will only have 1 row its ok.
Why are you using union rather than union all. If your two sections are guaranteed to be different use union all. Union is in fact union distinct. it does a sort operation to remove any duplicates. If you don't need to eliminate duplicates use union all -
Hi All,
I have a question on union. is doing a select distinct and a union expensive or select and then union without a distinct?
I know UNION does a distinct internally. Basically I need to know which is costlier?
SELECT DISTINCT SEC_MSTR_ID FROM od_order
UNION
SELECT DISTINCT SEC_MSTR_ID FROM od_order
Explain Plan:
Plan
SELECT STATEMENT CHOOSECost: 2,973 Bytes: 81,756 Cardinality: 13,626
4 SORT UNIQUE Cost: 2,973 Bytes: 81,756 Cardinality: 13,626
3 UNION-ALL
1 TABLE ACCESS FULL TABLE D_OD.OD_ORDER Cost: 1,031 Bytes: 1,118,880 Cardinality: 186,480
2 TABLE ACCESS FULL TABLE D_OD.OD_ORDER Cost: 1,031 Bytes: 1,118,880 Cardinality: 186,480 VS
SELECT SEC_MSTR_ID FROM od_order
UNION
SELECT SEC_MSTR_ID FROM od_order
Explain plan:
Plan
SELECT STATEMENT CHOOSECost: 4,034 Bytes: 2,237,760 Cardinality: 372,960
4 SORT UNIQUE Cost: 4,034 Bytes: 2,237,760 Cardinality: 372,960
3 UNION-ALL
1 TABLE ACCESS FULL TABLE D_OD.OD_ORDER Cost: 1,031 Bytes: 1,118,880 Cardinality: 186,480
2 TABLE ACCESS FULL TABLE D_OD.OD_ORDER Cost: 1,031 Bytes: 1,118,880 Cardinality: 186,480 Which one is costly? Logically I feel both are same?
Thanks,
SaffSolomon:
You might want to try with a bigger table. I can replicate both the different estimates for the number of rows returned, and the cost difference using a larger table.
SQL> select gtnctl_run_no from prregis_t
2 union
3 select gtnctl_run_no from prregis_t;
Execution Plan
Plan hash value: 3806563321
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 7386K| 28M| | 10733 (52)| 00:03:37 |
| 1 | SORT UNIQUE | | 7386K| 28M| 169M| 10733 (52)| 00:03:37 |
| 2 | UNION-ALL | | | | | | |
| 3 | INDEX FULL SCAN| A91034_0_PRREGIS_T | 3693K| 14M| | 40 (0)| 00:00:01 |
| 4 | INDEX FULL SCAN| A91034_0_PRREGIS_T | 3693K| 14M| | 40 (0)| 00:00:01 |
SQL> select distinct gtnctl_run_no from prregis_t
2 union
3 select distinct gtnctl_run_no from prregis_t;
Execution Plan
Plan hash value: 3806563321
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1656 | 6624 | 469 (92)| 00:00:10 |
| 1 | SORT UNIQUE | | 1656 | 6624 | 469 (92)| 00:00:10 |
| 2 | UNION-ALL | | | | | |
| 3 | INDEX FULL SCAN| A91034_0_PRREGIS_T | 3693K| 14M| 40 (0)| 00:00:01 |
| 4 | INDEX FULL SCAN| A91034_0_PRREGIS_T | 3693K| 14M| 40 (0)| 00:00:01 |
----------------------------------------------------------------------------------------My guess would be that the optimizer in generating its cost and cardinality estimates for the distinct query takes the distinct into account, but does not actually do the distinct on each subset and then the final resultset.
John -
Union all-distinct and remove duplicates from nested table?
Hi all,
I need a select that will bulk collect some data in my nested table.
I have two tables from which I need to select all the accounts only once.(remove duplicates).
Tried to search on the forum...but no luck.
I have a table with one column:
create table a1(account_no number);
and a second table with 3 columns.
create table a2 (account_no number, name number, desc varchar2 (100));
I have a nested table like:
table of a2%rowtype;
Can I select from this two table in one select and put in my nested table just one row per account?
if a I have in a 2a row like :
1 'test' 'test2'
2 aaaa aa
and in a1 a row like:
1
I want to put in my nested table just (1, null,null and 2,aaaa, aa)) or (1,test,test2 and 2,aaaa, aa). it does no matter what row from those two I insert.
Second question:
If I use:
BANNER
Oracle9i Release 9.2.0.5.0 - Production
PL/SQL Release 9.2.0.5.0 - Production
CORE 9.2.0.6.0 Production
TNS for 32-bit Windows: Version 9.2.0.5.0 - Production
NLSRTL Version 9.2.0.5.0 - Production
SQL>
what is the best solution to remove duplicates from a neste table like mine?
I thought that I can build another nested table and loop in my first nt and for each row I check in there was the same account in previous lines.
it will be like:
for i in 1....nt_first.count loop
for j in 1..i loop
--check if my line was in previous lines. if it was...do not move it in my second collection
end loop;it is this best option in oracle 9i?I have a table with one column:
create table a1(account_no number);
and a second table with 3 columns.
create table a2 (account_no number, name number, desc varchar2 (100));
all I need are the accounts. the rest ar extra data
that I can ignore in this step. But if it is
available, it is ok to use it.
using one select in this case is is much better that
trying to remove duplicates parsing some nested table
with FOR many times?
Thankshi,
try to use union. Union automatically removes duplicates between two or more tables.
with t1 AS
(select '3300000' account_no FROM DUAL UNION
select '6500000' account_no FROM DUAL union
select '6500000' account_no FROM DUAL union
select '6500000' account_no FROM DUAL union
select '6500000' account_no FROM DUAL
select * from t1ACCOUNT_NO
3300000
6500000
Maybe you are looking for
-
No longer able to drag Outlook emails to Outlook calendar events
I use Outlook 2007 on my PC, and sync it to my iPhone and iPad using iCloud. I used to be able to drag an email to the notes section of an Outlook calendar event, but it looks like this ability/feature is now gone. Can I get this feature back? I ev
-
Dear All, While posting the document in F-51 I would like to calculate the service tax, but when I simulate it goes to the next screen asking for process open item I have checked all the tax setting everything is correct. Please suggest me what has t
-
CVI debugger reports dynamic memory corrupt
Hi, There is a problem most likely between debugger and CVIXML group of functions. When I operate even one of CVI examples involving population of tree control out of XML the following function corrupting heap: CVIXMLGetElementValue (
-
Error Log : Please check what is wrong, stuck since 4-5 days
Hello friends, since 4-5 days i am stuck in acheiving R/3 -> XI -> R/3 scenario. Today i found this Messaging system Monitor, where i can see my requests under Sent Messages -> Synchronous looking at the Audit Log can you please tell me whats going w
-
MM Key Performance Indicators(KPI)
Hello Guru, I have been tasked to develop procedures for employees to be able to get KPI. AS I am new to MM can you please give me any input which transaction in SAP to use or any workaround with SAP. I will really appreciate your input. Thanks