Substring replacement
Hello,
i have a String like this one:
String input="someText 'dothis' anotherText 'second \'Command\' is easy' itgoeson "
and a method
public String handle(String str){
What i want now is to replace input with
String newInput="someText "+handle(dothis)+" anotherText "+handle(second 'Command' is easy)+" itgoeson ";
So how do i handle escaped characters in a fast way ? Is there a way to use a RegEx ?
Thanks for help,
winny
winny wrote:
ok, next try, sorry for my bad explanation.
I have a String str and want to replace all tags with the result of the handle-method invoked by the string.
so for one tag do
String tmp=handle(tag[0]);
str=str.replace(tag[0],tmp);i thought that there might be a way of using RegEx to detect all tags. Because then i just have to invoke the handle method with this tag and replace the tag with the result of the method in the original stringI gues you want something like this:
import java.util.regex.*;
public class Main {
private static int x = 1;
private static String handle(String str){
return String.valueOf(x++);
public static String process(String input){
Pattern p = Pattern.compile("'.*?[^\\\\]'");
Matcher m = p.matcher(input);
while(m.find()) {
String temp = m.group();
input = input.replaceFirst("\\Q"+temp, handle(temp));
m = p.matcher(input);
return input;
public static void main(String[] args) {
String input = "someText 'dothis' anotherText 'second \\'Command\\' is easy' itgoeson";
System.out.println(input);
System.out.println(process(input));
}
Similar Messages
-
How to use string functions (substr or ltrim or replace) in OLAP universe.
cost element (0COSTELMNT) - 10 CHAR
Controlling area (0CO_AREA) - 4 CHAR
[0COSTELMNT].[LEVEL01].[[20COSTELMNT]].[Value]
cOST ELEMENT is compounded/prefixed with Controlling Area. I just want to see cost element without conrolling area in the BO report.
Currenlty BO unierse is build based on bex query. I am able to suppress the compounding object in bex query by chaning controlling area to 'No display'. But still BO Webi report displaying compounded values in the report. (Bex report works as expected)
eg: Current display in reort.
controlling area/cost element.
AB00/2222
AB00/2223
AB00/2224
Wanted like below:
2222
2223
2224
I think by using string fucntions (substring, ltrim or replace etc.), I can get the required result. But I am having issues with syntax. I have used like below.
substr(0COSTELMNT ; 5 ; 10)
substr(0COSTELMNT; 5 ; Length(0COSTELMNT)-5)
substr(0COSTELMNT; Pos(0COSTELMNT;"/")+1;10)
ltrim(0COSTELMNT,'AB00/')
What is the syntax for substring/replace functions in OLAP universe. Technical name of cost element in OLAP universe is [0COSTELMNT].[LEVEL01].[[20COSTELMNT]].[Value].
I want to fix this at universe level not at report level as i am using cost element in filter/variable section of the report. Please provide me syntax for above example.Hi,
In fact SAP BW MDX supports limited string manipulation and only with NAME and UNIQUENAME attributes.
Here are some samples that you can use in universes:
MID([0COSTELMNT].currentmember.NAME,1,4)
LEFT([0COSTELMNT].currentmember.NAME,2)
RIGHT([0COSTELMNT].currentmember.NAME,3)
MID([0COSTELMNT].currentmember.UNIQUENAME ,1,4)
LEFT([0COSTELMNT].currentmember.UNIQUENAME ,2)
RIGHT([0COSTELMNT].currentmember.UNIQUENAME ,3)
Didier -
How to select a substring in oracle up to a more than one specific character
How to select a substring in oracle up to a more than one specific character
for ex : 121.051^NP: FAMILY PRACTICE ( trim the values before ^ )
121.051^*NP: FAMILY PRACTICE (trim the value before *).
with below function I can only get rid of ^ , I want both the specific characters ^ and ^* to be removed at the same time.
SUBSTR(p.phys_sub_grp_2_desc,INSTR(p.phys_sub_grp_2_desc, '^') +1)Another option is to boldly replace 'em:
SQL> with t as (
2 select '121.051^NP: FAMILY PRACTICE' str from dual union
3 select '121.051^*NP: FAMILY PRACTICE' from dual
4 )
5 --
6 -- actuel query:
7 --
8 select substr( replace(str, '*')
9 , instr(replace(str, '*'), '^')+1
10 ) str
11 from t;
STR
NP: FAMILY PRACTICE
NP: FAMILY PRACTICE
2 rows selected. -
Replace function and '-' character
Hello,
How can I use '-' character in a REPLACE function?
create or replace procedure zd authid current_user as
begin
execute immediate ' create table select ZDK
Replace(SO_HEADER.ZDNUMBER,'' - '','' '') from so_header';
end zd;
Thanks a lot,Hm. I don't see that you want to replace the minus "-". If you truely ment the underscore "_" then you are right. Sometimes it must be escaped since it has the special meaning of "any single character" (same as the ? wildcard for microsoft users). However this is only true for the LIKE operator. Not for the REPLACE function.
examples (non dynamic)
select SUBSTR(Replace('123\456\789\', '\'),7,7) from dual;
789
select SUBSTR(Replace('123_456_789_', '_'),7,7) from dual;
789The escape keyword in not allowed anywhere inside the replace function.
What was your intended input and output?
Just a recommendation. You don't need to specify the third paramater if you just want to remove the search string.
And your insert statement is not dynamic. If you don't create the table dynamically then you can simply write the insert statement inside pl/sql without the need to make it dynamic. This would make testing and debugging much easier!
Edited by: Sven W. on Jul 27, 2011 7:56 PM -
Possible bug with replace on clobs?
I couldn't find this documented anywhere, and wanted to check if I had data corruption or if there indeed is a bug with replace on long clobs.
Best I can figure, if you are replacing before the 32768 border and a previous replace in that clob moves the new location to be after 32768, then your clob gets clobbered in that area.
I'd like to know if this is a verifiable bug so that I feel better about having written my own replace using instr/substr.
Oracle 10g (10.2.0.1.0)
Test procedure:
======================================
declare
vclob clob;
tempc1 clob;
tempc2 clob;
pos number;
ch char(1);
begin
vclob := rpad('*', 32749, '*') || '****12345./~\.12345*' || rpad('*', 10000, '*');
for vi in 1..5 loop
ch := to_char(vi);
tempc1 := vclob;
pos := instr(tempc1, ch);
while (pos > 0) loop
tempc1 := substr(tempc1, 1, pos-1) || 'BUGS' || substr(tempc1, pos+1);
pos := instr(tempc1, ch, pos+1);
end loop;
tempc2 := vclob;
pos := instr(tempc2, ch);
while (pos > 0) loop
tempc2 := substr(tempc2, 1, pos-1) || 'BUGGY' || substr(tempc2, pos+1);
pos := instr(tempc2, ch, pos+1);
end loop;
dbms_output.put_line('Replace ' || ch || ' at ' ||
instr(vclob, ch) || ' and ' ||
instr(vclob, ch, instr(vclob, ch)+1));
dbms_output.put_line(': 32750 32760 32770 32780');
dbms_output.put_line(': 67890123456789012345678901234567890');
dbms_output.put_line('Original: ' || substr(vclob, 32746, 50));
dbms_output.put_line(ch || '->BUGS : ' ||
substr(replace(vclob, ch, 'BUGS'), 32746, 50));
dbms_output.put_line('Correct : ' || substr(tempc1, 32746, 50));
dbms_output.put_line(ch || '->BUGGY: ' ||
substr(replace(vclob, ch, 'BUGGY'), 32746, 50));
dbms_output.put_line('Correct : ' || substr(tempc2, 32746, 50));
end loop;
end;
/======================================
Output: (changed slightly for formatting)
======================================
Replace 1 at 32754 and 32764
: _______ 32750 ___ 32760 ___ 32770 ___ 32780
: _______ 67890123456789012345678901234567890
Original: ********12345./~\.12345***************************
1->BUGS : ********BUGS2345./~\.BUGS2345*********************
Correct : ********BUGS2345./~\.BUGS2345*********************
1->BUGGY: ********BUGGY2345./~\.BUGGY2345*******************
Correct : ********BUGGY2345./~\.BUGGY2345*******************
Replace 2 at 32755 and 32765
: _______ 32750 ___ 32760 ___ 32770 ___ 32780
: _______ 67890123456789012345678901234567890
Original: ********12345./~\.12345***************************
2->BUGS : ********1BUGS345./~\.1BUGS345*********************
Correct : ********1BUGS345./~\.1BUGS345*********************
2->BUGGY: ********1BUGGY345./~\.¿¿¿5************************
Correct : ********1BUGGY345./~\.1BUGGY345*******************
Replace 3 at 32756 and 32766
: _______ 32750 ___ 32760 ___ 32770 ___ 32780
: _______ 67890123456789012345678901234567890
Original: ********12345./~\.12345***************************
3->BUGS : ********12BUGS45./~\.1¿¿5*************************
Correct : ********12BUGS45./~\.12BUGS45*********************
3->BUGGY: ********12BUGGY45./~\.¿¿¿5************************
Correct : ********12BUGGY45./~\.12BUGGY45*******************
Replace 4 at 32757 and 32767
: _______ 32750 ___ 32760 ___ 32770 ___ 32780
: _______ 67890123456789012345678901234567890
Original: ********12345./~\.12345***************************
4->BUGS : ********123BUGS5./~\.1¿¿5*************************
Correct : ********123BUGS5./~\.123BUGS5*********************
4->BUGGY: ********123BUGGY5./~\.¿¿¿5************************
Correct : ********123BUGGY5./~\.123BUGGY5*******************
Replace 5 at 32758 and 32768
: _______ 32750 ___ 32760 ___ 32770 ___ 32780
: _______ 67890123456789012345678901234567890
Original: ********12345./~\.12345***************************
5->BUGS : ********1234BUGS./~\.1234BUGS*********************
Correct : ********1234BUGS./~\.1234BUGS*********************
5->BUGGY: ********1234BUGGY./~\.1234BUGGY*******************
Correct : ********1234BUGGY./~\.1234BUGGY*******************======================================Correct me if I'm wrong. What this lines does (if there isn't a space between the two single-quotes) is removing the string represented by xmlnsVal from the string xmlDoc. I've been using this method in some situations.
But I don't know why it won't work either. However, isn't it necessary to do conversion from CLOB to varchar2 before calling replace? Maybe the implicit conversion isn't so reliable. I've seen someone did the following:
-- clobvar is CLOB
-- stringvar is varchar2(4000)
stringvar := cast(clobvar as varchar2(4000)); -- not testedAfter that you can use stringvar in your replace function.
Or alternately, if exists in 9i, you can try the function regexp_replace() instead. Good luck. -
Hello everyone,
I'm having a big problem that I can't figure out why ...
look at the following select that is executed ok...
SQL> select max(cgc) from clientes;
MAX(CGC)
999.984.838-91
but when I use replace, on the following select, Oracle extends the line that separats the header from the data....look
SQL> select REPLACE(REPLACE(REPLACE(CLIENTES.CGC,'.',''),'/',''),'-','')
2 from clientes;
REPLACE(REPLACE(REPLACE(CLIENT
61235123000104
94406790000153
88626098000138
12272753000720
30333686000101
96494042000103
23282150172
01814062000108
05923334000150
33013137000130
REPLACE(REPLACE(REPLACE(CLIENT
00123077000159
06110864000142
why does Oracle insert more "-" just above the first row????
and then on delphi 5 it "guess" that the column isn't varchar2(1 as it is, it "guesses" that the column is MEMO.
I tried as well substr and format as you can see below
SQL> select substr(REPLACE(teste.aaa,'l','p'),1,2) as teste_replace from teste;
TESTE_REPLACE
aa
Tim, the format doesn't work as well, I'm sure it seems to be a parameter or a enviroment configuration, take a look..
SQL> col aaa for a3
SQL> select replace(teste.aaa,'a','7') from teste;
REPLACE(TESTE.AAA,'A','7')
77l
And if I connect to another instance, on the same sql plus, look
SQL> conn fernando/*****@oracle2004
SQL> select replace(teste.aaa,'a','7') from teste;
REP
771
It works, I'm wondering which configuration could be....
Anyone can please help me out ?
Cheerscursor_sharing
SIMILAR
SQL> select table_name from dict where rownum = 1;
TABLE_NAME
ALL_ALL_TABLES
SQL> select replace(table_name, '_', ' ') from dict suspect_cursor_sharing where rownum = 1;
REPLACE(TABLE_NAME,'_','')
ALL ALL TABLES
SQL> select sql_text from v$sqlarea where lower(sql_text) like '%suspect_cursor_sharing%';
SQL_TEXT
select replace(table_name, :"SYS_B_0", :"SYS_B_1") from dict suspect_cursor_sharing where rownum = :"SYS_B_2"With bind variables Oracle can not distinguish maximum length of string after replace. So it treat such expresions as varchar2(4000) -
To replace "\" with "/" in a string using FrameMaker API
How to replace "\folder1\folder2\folder3" with "folder1/folder2/folder3" using framemaker API ?
Hi Asha,
Here is a function that I use for substring replacement, using all FDK library functions. If you use standard C libraries instead, you could probably reduce this to a line or two.
To use it, you would send something like:
path = F_StrCopyString("\\folder1\\folder2\\folder3");
strReplace(path, "\\", "/", False);
There might be better ways to do this. I'm not really that much of a programmer.
Russ
//returns the index of the first change, or -1 if no changes.
IntT ws_StrReplace(StringT *mainString,
StringT searchString,
StringT replaceString,
IntT considerCase)
StringT strBuf,
returnString,
appendString;
IntT i,
firstIndex = -1;
//if the search string is empty, there is nothing to do.
if(F_StrIsEmpty(searchString))
returnString = F_StrCopyString(*mainString);
else
//otherwise, initialize the buffer
returnString = F_StrCopyString("");
for(i = 0; i < F_StrLen(*mainString); i++)
strBuf = F_StrCopyString(*mainString);
//Truncate the string from the beginning
F_StrReverse(strBuf, 10000);
F_StrTrunc(strBuf, (F_StrLen(strBuf) - i));
F_StrReverse(strBuf, 10000);
//and lop it down to the size of the search string
if(F_StrLen(strBuf) > F_StrLen(searchString))
F_StrTrunc(strBuf, F_StrLen(searchString));
//if they are the same, we are doing the replacement
if((considerCase && F_StrCmp(strBuf, searchString) == 0) ||
(!considerCase && F_StrICmp(strBuf, searchString) == 0))
appendString = F_StrCopyString(replaceString);
//set the return value
if(firstIndex < 0) firstIndex = i;
//jimmy the loop so we step past the length of the replacement
//string the next time around
i += F_StrLen(searchString) - 1;
//otherwise, we are just appending 1 character on.
else
F_StrTrunc(strBuf, 1);
appendString = F_ApiCopyString(strBuf);
//now, concatenate
//rciReturnString = F_Realloc(rciReturnString,
//F_StrLen(rciReturnString) + F_StrLen(rciAppendString), NO_DSE);
returnString = (StringT) F_Realloc(returnString,
(F_StrLen(returnString) + F_StrLen(appendString))*sizeof(StringT), NO_DSE);
F_StrCat(returnString, appendString);
F_ApiDeallocateString(&strBuf);
F_ApiDeallocateString(&appendString);
} //end main else
//all done
F_ApiDeallocateString(mainString);
*mainString = F_StrCopyString(returnString);
F_ApiDeallocateString(&returnString);
return firstIndex; -
Regexp_replace: longest repetitive substring in a string
hello
is it possible to write a regexp_replace to replace longest consecutive substring that repats itself in a string with just once instance of this substring? for example:
1,[2],[2],3 -> 1,[2],3
1,[2,3],[2,3],4 -> 1,[2,3],4
1,2,3,4,[2,3,4,5],[2,3,4,5],6 -> 1,2,3,4,[2,3,4,5],6if there were a few equivalent cases a first one would be picked:
1,[2,3],[2,3],4,5,4,5,6 -> 1,[2,3],4,5,4,5,6I would appreciate any help and suggestions if this is doable.
thank you
create table t( s varchar2(50) );
insert into t values('1,2,2,3');
insert into t values('1,2,3,2,3,4');
insert into t values('1,2,3,4,2,3,4,5,2,3,4,5,6');
insert into t values('1,2,3,2,3,4,5,4,5,6');Hi,
Interesting problem!
943276 wrote:
hello
is it possible to write a regexp_replace to replace longest consecutive substring that repats itself in a string with just once instance of this substring?Another way of saying that would be "Find the shortest string s1 such that s1 is s with a repating substring replaced by just one instance of itself." If we can generate all possible s1's, then we just need to find the shortest one (or one of the shortest, in case of a tie).
create table t( s varchar2(50) );
insert into t values('1,2,2,3'); ...Thanks for posting the CREATE TABLE and INSERT statements; that's very helpful.
Don't forget to say which version of Oracle you're using. The query below works in Oracle 10.1 and up.
Here's one way in pure SQL:
WITH cntr AS
SELECT LEVEL AS n
FROM (
SELECT MAX (LENGTH (s)) AS max_length_s
FROM t
CONNECT BY LEVEL < max_length_s
, got_new_s AS
SELECT t.s
, SUBSTR ( t.s
, 1
, c.n - 1
) || REGEXP_REPLACE ( SUBSTR (t.s, c.n)
, '^(.+)\1'
, '\1'
) AS new_s
, c.n
FROM t
JOIN cntr c ON c.n < LENGTH (t.s)
SELECT s
, MIN (new_s) KEEP ( DENSE_RANK FIRST ORDER BY LENGTH (new_s)
, n
) AS shortest
FROM got_new_s
GROUP BY s
ORDER BY s
;The first sub-query is a Counter Table . that just produces the integers 1, 2, 3, ... counting fromn 1 to the length of the longest string, minus 1.
Got_new_s is the interesting part. In got_new_s, we see if the substring starting at position n starts with a repeating pattern, and, if so, replace it. By combining all possible values of n to s, we get all possible replacements.
The main query is just a matter of finding the shortest of those replacements.
As Dan said, this really a job for PL/SQL. It would probebly be easier to maintain as well as more efficient in PL/SQL.
Edited by: Frank Kulash on Jun 30, 2012 4:07 AM
Added c.n to SELECT clause of got_new_s, after Paulie (below).
Ouptut:
S SHORTEST
1,2,2,3 1,2,3
1,2,3,2,3,4 1,2,3,4
1,2,3,2,3,4,5,4,5,6 1,2,3,4,5,4,5,6
1,2,3,4,2,3,4,5,2,3,4,5,6 1,2,3,4,2,3,4,5,6 -
Hi all,
I have a performance issue in the below code,where i am trying to insert the data from table_stg into target_tab and in parent_tab tables and then to child tables via cursor with bulk collect .the target_tab and parent_tab are huge tables and have a row wise trigger enabled on it .the trigger is mandatory . This timetaken for this block to execute is 5000 seconds.Now my requirement is to reduce it to 5 to 10 mins.
can someone please guide me here.Its bit urgent .Awaiting for your response.
declare
vmax_Value NUMBER(5);
vcnt number(10);
id_val number(20);
pc_id number(15);
vtable_nm VARCHAR2(100);
vstep_no VARCHAR2(10);
vsql_code VARCHAR2(10);
vsql_errm varchar2(200);
vtarget_starttime timestamp;
limit_in number :=10000;
idx number(10);
cursor stg_cursor is
select
DESCRIPTION,
SORT_CODE,
ACCOUNT_NUMBER,
to_number(to_char(CORRESPONDENCE_DATE,'DD')) crr_day,
to_char(CORRESPONDENCE_DATE,'MONTH') crr_month,
to_number(substr(to_char(CORRESPONDENCE_DATE,'DD-MON-YYYY'),8,4)) crr_year,
PARTY_ID,
GUID,
PAPERLESS_REF_IND,
PRODUCT_TYPE,
PRODUCT_BRAND,
PRODUCT_HELD_ID,
NOTIFICATION_PREF,
UNREAD_CORRES_PERIOD,
EMAIL_ID,
MOBILE_NUMBER,
TITLE,
SURNAME,
POSTCODE,
EVENT_TYPE,
PRIORITY_IND,
SUBJECT,
EXT_PRD_ID_TX,
EXT_PRD_HLD_ID_TX,
EXT_SYS_ID,
EXT_PTY_ID_TX,
ACCOUNT_TYPE_CD,
COM_PFR_TYP_TX,
COM_PFR_OPT_TX,
COM_PFR_RSN_CD
from table_stg;
type rec_type is table of stg_rec_type index by pls_integer;
v_rt_all_cols rec_type;
BEGIN
vstep_no := '0';
vmax_value := 0;
vtarget_starttime := systimestamp;
id_val := 0;
pc_id := 0;
success_flag := 0;
vstep_no := '1';
vtable_nm := 'before cursor';
OPEN stg_cursor;
vstep_no := '2';
vtable_nm := 'After cursor';
LOOP
vstep_no := '3';
vtable_nm := 'before fetch';
--loop
FETCH stg_cursor BULK COLLECT INTO v_rt_all_cols LIMIT limit_in;
vstep_no := '4';
vtable_nm := 'after fetch';
--EXIT WHEN v_rt_all_cols.COUNT = 0;
EXIT WHEN stg_cursor%NOTFOUND;
FOR i IN 1 .. v_rt_all_cols.COUNT
LOOP
dbms_output.put_line(upper(v_rt_all_cols(i).event_type));
if (upper(v_rt_all_cols(i).event_type) = upper('System_enforced')) then
vstep_no := '4.1';
vtable_nm := 'before seq sel';
select PC_SEQ.nextval into pc_id from dual;
vstep_no := '4.2';
vtable_nm := 'before insert corres';
INSERT INTO target1_tab
(ID,
PARTY_ID,
PRODUCT_BRAND,
SORT_CODE,
ACCOUNT_NUMBER,
EXT_PRD_ID_TX,
EXT_PRD_HLD_ID_TX,
EXT_SYS_ID,
EXT_PTY_ID_TX,
ACCOUNT_TYPE_CD,
COM_PFR_TYP_TX,
COM_PFR_OPT_TX,
COM_PFR_RSN_CD,
status)
VALUES
(pc_id,
v_rt_all_cols(i).party_id,
decode(v_rt_all_cols(i).product_brand,'LTB',2,'HLX',1,'HAL',1,'BOS',3,'VER',4,0),
v_rt_all_cols(i).sort_code,
'XXXX'||substr(trim(v_rt_all_cols(i).ACCOUNT_NUMBER),length(trim(v_rt_all_cols(i).ACCOUNT_NUMBER))-3,4),
v_rt_all_cols(i).EXT_PRD_ID_TX,
v_rt_all_cols(i).EXT_PRD_HLD_ID_TX,
v_rt_all_cols(i).EXT_SYS_ID,
v_rt_all_cols(i).EXT_PTY_ID_TX,
v_rt_all_cols(i).ACCOUNT_TYPE_CD,
v_rt_all_cols(i).COM_PFR_TYP_TX,
v_rt_all_cols(i).COM_PFR_OPT_TX,
v_rt_all_cols(i).COM_PFR_RSN_CD,
NULL);
vstep_no := '4.3';
vtable_nm := 'after insert corres';
else
select COM_SEQ.nextval into id_val from dual;
vstep_no := '6';
vtable_nm := 'before insertcomm';
if (upper(v_rt_all_cols(i).event_type) = upper('REMINDER')) then
vstep_no := '6.01';
vtable_nm := 'after if insertcomm';
insert into parent_tab
(ID ,
CTEM_CODE,
CHA_CODE,
CT_CODE,
CONTACT_POINT_ID,
SOURCE,
RECEIVED_DATE,
SEND_DATE,
RETRY_COUNT)
values
(id_val,
lower(v_rt_all_cols(i).event_type),
decode(v_rt_all_cols(i).product_brand,'LTB',2,'HLX',1,'HAL',1,'BOS',3,'VER',4,0),
'Email',
v_rt_all_cols(i).email_id,
'IADAREMINDER',
systimestamp,
systimestamp,
0);
else
vstep_no := '6.02';
vtable_nm := 'after else insertcomm';
insert into parent_tab
(ID ,
CTEM_CODE,
CHA_CODE,
CT_CODE,
CONTACT_POINT_ID,
SOURCE,
RECEIVED_DATE,
SEND_DATE,
RETRY_COUNT)
values
(id_val,
lower(v_rt_all_cols(i).event_type),
decode(v_rt_all_cols(i).product_brand,'LTB',2,'HLX',1,'HAL',1,'BOS',3,'VER',4,0),
'Email',
v_rt_all_cols(i).email_id,
'CORRESPONDENCE',
systimestamp,
systimestamp,
0);
END if;
vstep_no := '6.11';
vtable_nm := 'before chop';
if (v_rt_all_cols(i).ACCOUNT_NUMBER is not null) then
v_rt_all_cols(i).ACCOUNT_NUMBER := 'XXXX'||substr(trim(v_rt_all_cols(i).ACCOUNT_NUMBER),length(trim(v_rt_all_cols(i).ACCOUNT_NUMBER))-3,4);
insert into child_tab
(COM_ID,
KEY,
VALUE)
values
(id_val,
'IB.Correspondence.AccountNumberMasked',
v_rt_all_cols(i).ACCOUNT_NUMBER);
end if;
vstep_no := '6.1';
vtable_nm := 'before stateday';
if (v_rt_all_cols(i).crr_day is not null) then
insert into child_tab
(COM_ID,
KEY,
VALUE)
values
(id_val,
--'IB.Correspondence.Date.Day',
'IB.Crsp.Date.Day',
v_rt_all_cols(i).crr_day);
end if;
vstep_no := '6.2';
vtable_nm := 'before statemth';
if (v_rt_all_cols(i).crr_month is not null) then
insert into child_tab
(COM_ID,
KEY,
VALUE)
values
(id_val,
--'IB.Correspondence.Date.Month',
'IB.Crsp.Date.Month',
v_rt_all_cols(i).crr_month);
end if;
vstep_no := '6.3';
vtable_nm := 'before stateyear';
if (v_rt_all_cols(i).crr_year is not null) then
insert into child_tab
(COM_ID,
KEY,
VALUE)
values
(id_val,
--'IB.Correspondence.Date.Year',
'IB.Crsp.Date.Year',
v_rt_all_cols(i).crr_year);
end if;
vstep_no := '7';
vtable_nm := 'before type';
if (v_rt_all_cols(i).product_type is not null) then
insert into child_tab
(COM_ID,
KEY,
VALUE)
values
(id_val,
'IB.Product.ProductName',
v_rt_all_cols(i).product_type);
end if;
vstep_no := '9';
vtable_nm := 'before title';
if (trim(v_rt_all_cols(i).title) is not null) then
insert into child_tab
(COM_ID,
KEY,
VALUE )
values
(id_val,
'IB.Customer.Title',
trim(v_rt_all_cols(i).title));
end if;
vstep_no := '10';
vtable_nm := 'before surname';
if (v_rt_all_cols(i).surname is not null) then
insert into child_tab
(COM_ID,
KEY,
VALUE)
values
(id_val,
'IB.Customer.LastName',
v_rt_all_cols(i).surname);
end if;
vstep_no := '12';
vtable_nm := 'before postcd';
if (trim(v_rt_all_cols(i).POSTCODE) is not null) then
insert into child_tab
(COM_ID,
KEY,
VALUE)
values
(id_val,
'IB.Customer.Addr.PostCodeMasked',
substr(replace(v_rt_all_cols(i).POSTCODE,' ',''),length(replace(v_rt_all_cols(i).POSTCODE,' ',''))-2,3));
end if;
vstep_no := '13';
vtable_nm := 'before subject';
if (trim(v_rt_all_cols(i).SUBJECT) is not null) then
insert into child_tab
(COM_ID,
KEY,
VALUE)
values
(id_val,
'IB.Correspondence.Subject',
v_rt_all_cols(i).subject);
end if;
vstep_no := '14';
vtable_nm := 'before inactivity';
if (trim(v_rt_all_cols(i).UNREAD_CORRES_PERIOD) is null or
trim(v_rt_all_cols(i).UNREAD_CORRES_PERIOD) = '3' or
trim(v_rt_all_cols(i).UNREAD_CORRES_PERIOD) = '6' or
trim(v_rt_all_cols(i).UNREAD_CORRES_PERIOD) = '9') then
insert into child_tab
(COM_ID,
KEY,
VALUE)
values
(id_val,
'IB.Correspondence.Inactivity',
v_rt_all_cols(i).UNREAD_CORRES_PERIOD);
end if;
vstep_no := '14.1';
vtable_nm := 'after notfound';
end if;
vstep_no := '15';
vtable_nm := 'after notfound';
END LOOP;
end loop;
vstep_no := '16';
vtable_nm := 'before closecur';
CLOSE stg_cursor;
vstep_no := '17';
vtable_nm := 'before commit';
DELETE FROM table_stg;
COMMIT;
vstep_no := '18';
vtable_nm := 'after commit';
EXCEPTION
WHEN OTHERS THEN
ROLLBACK;
success_flag := 1;
vsql_code := SQLCODE;
vsql_errm := SUBSTR(sqlerrm,1,200);
error_logging_pkg.inserterrorlog('samp',vsql_code,vsql_errm, vtable_nm,vstep_no);
RAISE_APPLICATION_ERROR (-20011, 'samp '||vstep_no||' SQLERRM:'||SQLERRM);
end;
ThanksIts bit urgent
NO - it is NOT urgent. Not to us.
If you have an urgent problem you need to hire a consultant.
I have a performance issue in the below code,
Maybe you do and maybe you don't. How are we to really know? You haven't posted ANYTHING indicating that a performance issue exists. Please read the FAQ for how to post a tuning request and the info you need to provide. First and foremost you have to post SOMETHING that actually shows that a performance issue exists. Troubleshooting requires FACTS not just a subjective opinion.
where i am trying to insert the data from table_stg into target_tab and in parent_tab tables and then to child tables via cursor with bulk collect .the target_tab and parent_tab are huge tables and have a row wise trigger enabled on it .the trigger is mandatory . This timetaken for this block to execute is 5000 seconds.Now my requirement is to reduce it to 5 to 10 mins.
Personally I think 5000 seconds (about 1 hr 20 minutes) is very fast for processing 800 trillion rows of data into parent and child tables. Why do you think that is slow?
Your code has several major flaws that need to be corrected before you can even determine what, if anything, needs to be tuned.
This code has the EXIT statement at the beginning of the loop instead of at the end
FETCH stg_cursor BULK COLLECT INTO v_rt_all_cols LIMIT limit_in;
vstep_no := '4';
vtable_nm := 'after fetch';
--EXIT WHEN v_rt_all_cols.COUNT = 0;
EXIT WHEN stg_cursor%NOTFOUND;
The correct place for the %NOTFOUND test when using BULK COLLECT is at the END of the loop; that is, the last statement in the loop.
You can use a COUNT test at the start of the loop but ironically you have commented it out and have now done it wrong. Either move the NOTFOUND test to the end of the loop or remove it and uncomment the COUNT test.
WHEN OTHERS THEN
ROLLBACK;
That basically says you don't even care what problem occurs or whether the problem is for a single record of your 10,000 in the collection. You pretty much just throw away any stack trace and substitute your own message.
Your code also has NO exception handling for any of the individual steps or blocks of code.
The code you posted also begs the question of why you are using NAME=VALUE pairs for child data rows? Why aren't you using a standard relational table for this data?
As others have noted you are using slow-by-slow (row by row processing). Let's assume that PL/SQL, the bulk collect and row-by-row is actually necessary.
Then you should be constructing the parent and child records into collections and then inserting them in BULK using FORALL.
1. Create a collection for the new parent rows
2. Create a collection for the new child rows
3. For each set of LIMIT source row data
a. empty the parent and child collections
b. populate those collections with new parent/child data
c. bulk insert the parent collection into the parent table
d. bulk insert the child collection into the child table
And unless you really want to either load EVERYTHING or abandon everything you should use bulk exception handling so that the clean data gets processed and only the dirty data gets rejected. -
Need Help in Breaking a big view into multiple small views or tuning the vw
Hi
I have the following view can some one help me in breaking the view in small views or any recommendations for tuning it.
CODE
CREATE OR REPLACE FORCE VIEW "CRUVPD"."PX16_CHK_VW_SUMMARY_VW" ("CIDN", "BATCH_NUMBER", "BUSINESS_UNIT", "CHECK_VOUCHER_NUMBER", "CHECK_VOUCHER_CODE", "CHECKVIEW_CLOCK_NUMBER", "COMPANY_CHECKVIEW_HOME_DEPT", "PERIOD_END_DATE", "FEDERAL_TAX", "GROSS_PAY"
, "HOME_DEPARTMENT", "HOME_DEPARTMENT_DESC", "LIVED_LOCAL_TAX_CODE", "LIVED_STATE_TAX_CODE", "LIVED_LOCAL_TAX", "LIVED_STATE_TAX", "MEDICARE_TAX", "NET_PAY", "DEPARTMENT_WORKED_IN", "PAY_TO_COMPANY_INDICATOR", "PAY_DATE", "PAYROLL_NUMBER", "SCHOOL_DISTRIC
T_TAX", "CHECKVIEW_SCHOOL_DISTRICT", "SOCIAL_SECURITY_TAX", "SUI_SDI_TAX", "SUI_SDI_TAX_CODE", "VOID_CHECK_INDICATOR", "WEEK_NUMBER", "WORKED_LOCAL_TAX_CODE", "WORKED_STATE_TAX_CODE", "WORKED_LOCAL_TAX", "WORKED_STATE_TAX", "YEAR", "COMPANY_CODE", "FILE_N
UMBER", "FIRST_NAME", "LAST_NAME", "LAST_NAME_FIRST_NAME", "SOCIAL_SECURITY_NUMBER", "STATUS", "OVERTIME_EARNINGS", "OVERTIME_HOURS", "REGULAR_EARNINGS", "REGULAR_HOURS", "VIEWPK", "HOME_COST_NUMBER", "TAX_FREQUENCY", "COMPANY_COST_NUMBER", "COST_NUMBER_W
ORKED_IN", "DISTRIBUTION_NUMBER", "TOTAL_DEDUCTIONS_AMOUNT", "TOTAL_HOURS_AMOUNT", "TOTAL_MEMO_AMOUNT", "TOTAL_OTHER_EARNINGS", "TOTAL_OTHER_HOURS", "CHECK_SEQ_NO", "JOINKEY", "CHECK_REVERSAL_INDICATOR") AS
with user_security_homedept
AS
(select /*+ INLINE */ distinct cg.cidn,co_code,asso.oid,asso.name,department_Access ,t2.column_value dep,cg.oid
from px16_cocodegroup cg ,
px16_associate asso ,
px16_securityobject so,
px16_cocodegrp_securitygrp cs,
px16_security_group sg ,
TABLE(f_str2tbl_px16(cg.department_access)) t2
where cg.USEROID = asso.OID
and cg.co_code = substr(so.name,8,3)
and upper(asso.name) = upper(sys_context('payx_r16_app_context', 'app_userid'))
and cg.oid = cs.cocodegroupoid
and cs.securitygroupoid = sg.oid
and cg.cidn = asso.cidn
and cg.cidn = so.cidn
and cg.cidn = cs.cidn
and cs.cidn = sg.cidn
order by 2,1
user_security_cost_no
AS
(select /*+ INLINE */
cg.cidn,co_code,count(distinct cd.code)cost_no,cd.code
from px16_cocodegroup cg ,
px16_associate asso ,
px16_securityobject so,
px16_cocodegrp_securitygrp cs,
px16_security_group sg ,
px16_customaccessdetail cd
where cg.USEROID = asso.OID
and cg.co_code = substr(so.name,8,3)
and upper(asso.name) = upper(sys_context('payx_r16_app_context', 'app_userid'))
and cg.oid = cs.cocodegroupoid
and cs.securitygroupoid = sg.oid
and cg.oid = cd.cocodegroupoid(+)
and cg.cidn = cd.cidn(+)
and cg.cidn = asso.cidn
and cg.cidn = so.cidn
and cg.cidn = cs.cidn
and cs.cidn = sg.cidn
group by cg.cidn,co_code,cd.code
order by 2,1
super_user_check as
(SELECT
distinct a.cidn su_cidn,1 as su_user
FROM
px16_LINK LN
, px16_userprofile up
, px16_ASSOCIATE a
, px16_pcp_user pu
WHERE
a.oid = pu.oid
AND pu.userprofileoid = up.oid
AND LN.parentoid = up.oid
AND a.active = 1
AND a.cidn=pu.cidn
AND pu.cidn=up.cidn
AND ln.cidn=up.cidn
AND upper(a.name) = upper(sys_context('payx_r16_app_context', 'app_userid'))
AND upper(up.name) = upper('Super user')
nonsuper_user_check as
SELECT distinct a.cidn s_cidn , 1 as non_user
FROM
px16_LINK LN
, px16_userprofile up
, px16_ASSOCIATE a
, px16_pcp_user pu
WHERE
a.oid = pu.oid
AND pu.userprofileoid = up.oid
AND LN.parentoid = up.oid
AND a.active = 1
AND a.cidn=pu.cidn
AND pu.cidn=up.cidn
AND ln.cidn=up.cidn
AND upper(a.name) = upper(sys_context('payx_r16_app_context', 'app_userid'))
AND LN.childoid IN ( 'SYS:5:7478')
SELECT distinct
cidn
,batch_number Batch_Number
, business_unit Business_Unit
, check_voucher_number Check_Voucher_Number
, check_voucher_code Check_Voucher_Code
, clock_number CheckView_Clock_Number
, company_code_or_dept Company_CheckView_Home_Dept
, period_end_date Period_End_Date
, TO_NUMBER(REPLACE(SUBSTR(taxes_and_rates, 1, (INSTR(taxes_and_rates, '~', 1, 1) -1)), CHR(155), NULL)) Federal_Tax
, gross_pay Gross_Pay
, home_department Home_Department
, home_department_descr Home_Department_Desc
, SUBSTR(REPLACE(SUBSTR(taxes_and_rates, (INSTR(taxes_and_rates, '~', 1, 1) +1)
, INSTR(taxes_and_rates, '~', 1, 2) - (INSTR(taxes_and_rates, '~', 1, 1) +1)), CHR(155), NULL), 1, 32) Lived_Local_Tax_Code
, SUBSTR(REPLACE(SUBSTR(taxes_and_rates, (INSTR(taxes_and_rates, '~', 1, 2) +1)
, INSTR(taxes_and_rates, '~', 1, 3) - (INSTR(taxes_and_rates, '~', 1, 2) +1)), CHR(155), NULL), 1, 32) Lived_State_Tax_Code
, TO_NUMBER(REPLACE(SUBSTR(taxes_and_rates, (INSTR(taxes_and_rates, '~', 1, 3) +1)
, INSTR(taxes_and_rates, '~', 1, 4) - (INSTR(taxes_and_rates, '~', 1, 3) +1)), CHR(155), NULL)) Lived_Local_Tax
, TO_NUMBER(REPLACE(SUBSTR(taxes_and_rates, (INSTR(taxes_and_rates, '~', 1, 4) +1)
, INSTR(taxes_and_rates, '~', 1, 5) - (INSTR(taxes_and_rates, '~', 1, 4) +1)), CHR(155), NULL)) Lived_State_Tax
, TO_NUMBER(REPLACE(SUBSTR(taxes_and_rates, (INSTR(taxes_and_rates, '~', 1, 5) +1)
, INSTR(taxes_and_rates, '~', 1, 6) - (INSTR(taxes_and_rates, '~', 1, 5) +1)), CHR(155), NULL)) Medicare_Tax
, net_pay Net_Pay
, department_paid Department_Worked_In
, to_pay_indicator Pay_to_Company_Indicator
, pay_date Pay_Date
, payroll_number Payroll_Number
, TO_NUMBER(REPLACE(SUBSTR(taxes_and_rates, (INSTR(taxes_and_rates, '~', 1, 6) +1)
, INSTR(taxes_and_rates, '~', 1, 7) - (INSTR(taxes_and_rates, '~', 1, 6) +1)), CHR(155), NULL)) School_District_Tax
, SUBSTR(REPLACE(SUBSTR(taxes_and_rates, (INSTR(taxes_and_rates, '~', 1, 7) +1)
, INSTR(taxes_and_rates, '~', 1, 8) - (INSTR(taxes_and_rates, '~', 1, 7) +1)), CHR(155), NULL), 1, 32) CheckView_School_District
, TO_NUMBER(REPLACE(SUBSTR(taxes_and_rates, (INSTR(taxes_and_rates, '~', 1, 8) +1)
, INSTR(taxes_and_rates, '~', 1, 9) - (INSTR(taxes_and_rates, '~', 1, 8) +1)), CHR(155), NULL)) Social_Security_Tax
, TO_NUMBER(REPLACE(SUBSTR(taxes_and_rates, (INSTR(taxes_and_rates, '~', 1, 9) +1)
, INSTR(taxes_and_rates, '~', 1, 10) - (INSTR(taxes_and_rates, '~', 1, 9) +1)), CHR(155), NULL)) SUI_SDI_Tax
, SUBSTR(REPLACE(SUBSTR(taxes_and_rates, (INSTR(taxes_and_rates, '~', 1, 10) +1)
, INSTR(taxes_and_rates, '~', 1, 11) - (INSTR(taxes_and_rates, '~', 1, 10) +1)), CHR(155), NULL), 1, 32) SUI_SDI_Tax_Code
, void_check_indicator Void_Check_Indicator
, week_number Week_Number
, SUBSTR(REPLACE(SUBSTR(taxes_and_rates, (INSTR(taxes_and_rates, '~', 1, 11) +1)
, INSTR(taxes_and_rates, '~', 1, 12) - (INSTR(taxes_and_rates, '~', 1, 11) +1)), CHR(155), NULL), 1, 32) Worked_Local_Tax_Code
, SUBSTR(REPLACE(SUBSTR(taxes_and_rates, (INSTR(taxes_and_rates, '~', 1, 12) +1)
, INSTR(taxes_and_rates, '~', 1, 13) - (INSTR(taxes_and_rates, '~', 1, 12) +1)), CHR(155), NULL), 1, 32) Worked_State_Tax_Code
, TO_NUMBER(REPLACE(SUBSTR(taxes_and_rates, (INSTR(taxes_and_rates, '~', 1, 13) +1)
, INSTR(taxes_and_rates, '~', 1, 14) - (INSTR(taxes_and_rates, '~', 1, 13) +1)), CHR(155), NULL)) Worked_Local_Tax
, TO_NUMBER(REPLACE(SUBSTR(taxes_and_rates, (INSTR(taxes_and_rates, '~', 1, 14) +1)
, INSTR(taxes_and_rates, '~', 1, 15) - (INSTR(taxes_and_rates, '~', 1, 14) +1)), CHR(155), NULL)) Worked_State_Tax
, year Year
, company_code Company_Code
, file_number File_Number
, first_name First_Name
, last_name Last_Name
, name Last_Name_First_Name
, ssn Social_Security_Number
, status Status
, TO_NUMBER(REPLACE(SUBSTR(taxes_and_rates, (INSTR(taxes_and_rates, '~', 1, 15) +1)
, INSTR(taxes_and_rates, '~', 1, 16) - (INSTR(taxes_and_rates, '~', 1, 15) +1)), CHR(155), NULL)) Overtime_Earnings
, TO_NUMBER(REPLACE(SUBSTR(taxes_and_rates, (INSTR(taxes_and_rates, '~', 1, 16) +1)
, INSTR(taxes_and_rates, '~', 1, 17) - (INSTR(taxes_and_rates, '~', 1, 16) +1)), CHR(155), NULL)) Overtime_Hours
, TO_NUMBER(REPLACE(SUBSTR(taxes_and_rates, (INSTR(taxes_and_rates, '~', 1, 17) +1)
, INSTR(taxes_and_rates, '~', 1, 18) - (INSTR(taxes_and_rates, '~', 1, 17) +1)), CHR(155), NULL)) Regular_Earnings
, TO_NUMBER(REPLACE(SUBSTR(taxes_and_rates, (INSTR(taxes_and_rates, '~', 1, 18) +1)
, INSTR(taxes_and_rates, '~', 1, 19) - (INSTR(taxes_and_rates, '~', 1, 18) +1)), CHR(155), NULL)) Regular_Hours
, (company_code || '/' || ssn || '/' || file_number || '/' || TO_CHAR(payroll_number) || '/'
|| TO_CHAR(year) || '/' || TO_CHAR(week_number) || '/' || check_voucher_number
|| '/' || to_char(check_seq_num) || '/' || TO_CHAR(distribution_number)) Viewpk
, home_costnumber_desc Home_Cost_Number
, tax_frequency Tax_Frequency
, co_chkv_home_cost_no Company_Cost_Number
, cost_no_worked_in Cost_Number_Worked_In
, distribution_number Distribution_Number
, TO_NUMBER(REPLACE(SUBSTR(taxes_and_rates, (INSTR(taxes_and_rates, '~', 1, 19) +1)
, INSTR(taxes_and_rates, '~', 1, 20) - (INSTR(taxes_and_rates, '~', 1, 19) +1)), CHR(155), NULL)) Total_Deductions_Amount
, NVL(TO_NUMBER(REPLACE(SUBSTR(taxes_and_rates, (INSTR(taxes_and_rates, '~', 1, 20) +1)
, INSTR(taxes_and_rates, '~', 1, 21) - (INSTR(taxes_and_rates, '~', 1, 20) +1)), CHR(155), NULL)), 0) Total_Hours_Amount
, NVL(TO_NUMBER(REPLACE(SUBSTR(taxes_and_rates, (INSTR(taxes_and_rates, '~', 1, 21) +1)
, INSTR(taxes_and_rates, '~', 1, 22) - (INSTR(taxes_and_rates, '~', 1, 21) +1)), CHR(155), NULL)), 0) Total_Memo_Amount
, NVL(TO_NUMBER(REPLACE(SUBSTR(taxes_and_rates, (INSTR(taxes_and_rates, '~', 1, 22) +1)
, INSTR(taxes_and_rates, '~', 1, 23) - (INSTR(taxes_and_rates, '~', 1, 22) +1)), CHR(155), NULL)), 0) Total_Other_Earnings
, TO_NUMBER(REPLACE(SUBSTR(taxes_and_rates, (INSTR(taxes_and_rates, '~', 1, 23) +1)), CHR(155), NULL)) Total_Other_Hours
, check_seq_num Check_Seq_No
, (NVL(company_code, '~') || CHR(155) || NVL(file_number, '~') || CHR(155) || NVL(ssn, '~') || CHR(155) || NVL(TO_CHAR(year), '~') || CHR(155)
|| NVL(TO_CHAR(week_number), '~') || CHR(155) || NVL(TO_CHAR(payroll_number), '~')
|| CHR(155) || NVL(check_voucher_number, '~') || CHR(155) || NVL(TO_CHAR(check_seq_num), '~') || CHR(155) || NVL(TO_CHAR(distribution_number), '~')) Joinkey
, chk_reverse Check_Reversal_Indicator
FROM
SELECT
ch.cidn cidn
/*BATCH NUMBER*/
, ch.batch_nb batch_number
, /*BUSINESS UNIT*/
(select asso.description
from px16_appointment ap,
px16_jobposition jp,
px16_corporation co,
px16_associate asso,
px16_payrollagreement pa,
px16_payrollgroup pg
where
ch.cidn = pg.cidn
AND ch.cidn = pa.cidn
AND pa.cidn = pg.cidn
AND pa.cidn = ap.cidn
AND em.cidn = ap.cidn
AND ap.cidn = jp.cidn
and jp.cidn = co.cidn
and co.cidn = asso.cidn
and ch.co_code=pg.co_code
and ch.file_nb=pa.file_number
and pa.cocodeoid=pg.oid
and pa.appointmentoid=ap.oid
and em.oid=ap.employmentoid
and ap.jobpositionoid=jp.oid
and jp.corporationoid=co.oid
and co.oid=asso.oid) business_unit
, /*CHECK/VOUCHER NUMBER*/
ch.check_nb check_voucher_number
, /*CHECK/VOUCHER CODE*/
SUBSTR(f_type_px16(ch.cidn,ch.chkvchcodeoid, 'NAME'), 1, 255) check_voucher_code
, /*CLOCK NUMBER*/
ch.clock_id clock_number
, /* COMPANY CODE OR DEPT*/
ch.co_code||'/'||substr(ch.home_dept_code,1,20) company_code_or_dept
, /*PERIOD END DATE*/
ch.payroll_ending_date period_end_date
, /*GROSS PAY*/
NVL(chd.gross_pay_amt,0) gross_pay
, /*HOME DEPARTMENT*/
ch.home_dept_code home_department
, /*HOME DEPARTMENT DESCRIPTION*/
(select ty.description
from px16_type ty,px16_securityobject sc
where
ch.cidn = sc.cidn
and ty.cidn in ('COMMON', ch.cidn)
and ch.home_dept_code=ty.name
and ty.category='T_CO_DEPT'
and ty.securityoid=sc.oid
and ch.co_code=substr(sc.name,8)) home_department_descr
, /*NET PAY*/
nvl(chd.net_pay_amt,0) net_pay
, /*DEPARTMENT PAID*/
-- ch.paid_in_debt_code department_paid
chd.worked_in_dept department_paid
, /*TO PAY INDICATOR*/
decode(to_char(ch.pay_to_co),'1','Y','0','N',to_char(ch.pay_to_co)) to_pay_indicator
, /*PAY DATE*/
ch.pay_date pay_date
, /*PAYROLL NUMBER*/
to_char(ch.payroll_nb) payroll_number
, /*VOID CHECK INDICATOR*/
decode(to_char(ch.void_flag),'1','Y','0','N',to_char(ch.void_flag)) void_check_indicator
, /*WEEK NUMBER*/
TO_number(ch.week) week_number
, /*YEAR*/
to_char(ch.year) year
, /*COMPANY CODE*/
ch.co_code company_code
, /*FILE NUMBER*/
LPAD(ch.file_nb,6,0) file_number
, /*FIRST NAME*/
pe.first_name first_name
, /*LAST NAME*/
pe.last_name last_name
, /*NAME*/
pe.last_name||', '||pe.first_name name
, /*SSN*/
payx_r16_principal_info.masked_ssn(pe.unique_id, ch.cidn) ssn
, /*STATUS*/
(SELECT SUBSTR(f_type_px16(ap.cidn,ap.currentstatusoid, 'DESC'), 1, 255)
from
px16_appointment ap,
/*context co_ap,*/
px16_payrollagreement pa,
px16_payrollgroup pg
where
pg.cidn=ch.cidn
and pa.cidn=ch.cidn
and ap.cidn=pa.cidn
and ap.cidn = em.cidn
and ap.employmentoid=em.oid
and ap.active=1
and ap.oid=pa.appointmentoid
and lpad(to_char(pa.file_number),6,0)=ch.file_nb
and pa.cocodeoid=pg.oid
and pg.co_code=ch.co_code) status
-- FED TAX
-- , LIVED LOCAL TAX CODE, LIVED STATE TAX CODE, LIVED LOCAL TAX, LIVED STATE TAX, MEDICARE TAX
-- , SCHOOL DISTRICT TAX, SCHOOL DISTRICT, SOCIAL SECURITY TAX, SUI SDI TAX, SUI SDI TAX CODE
-- , WORKED LOCAL TAX CODE, WORKED STATE TAX CODE, WORKED LOCAL TAX, WORKED STATE TAX
-- , OVERTIME EARNINGS, OVERTIME HOURS, REGULAR EARNINGS, REGULAR HOURS
NVL (
(SELECT
TO_CHAR(NVL(SUM(DECODE(ci.histtypeoid, 'SYS:4:3709', DECODE(ci.taxcodeoid, 'SYS:4:2982', NVL(ci.amount,0), 0), 0) ), 0)) || '~'
|| NVL(MAX(DECODE(ci.histtypeoid, 'SYS:4:3709', DECODE(ci.taxcodeoid, 'SYS:4:2984', ci.code, NULL), NULL)), CHR(155)) || '~'
|| NVL(MAX(DECODE(ci.histtypeoid, 'SYS:4:3709', DECODE(ci.taxcodeoid, 'SYS:4:2987', DECODE(ci.code,'XX',null,ci.code), NULL), NULL)), CHR(155)) || '~'
|| TO_CHAR(NVL(SUM(DECODE(ci.histtypeoid, 'SYS:4:3709', DECODE(ci.taxcodeoid, 'SYS:4:2984', NVL(ci.amount,0), 0), 0) ), 0)) || '~'
|| TO_CHAR(NVL(SUM(DECODE(ci.histtypeoid, 'SYS:4:3709', DECODE(ci.taxcodeoid, 'SYS:4:2987', NVL(ci.amount,0), 0), 0) ), 0)) || '~'
|| TO_CHAR(NVL(SUM(DECODE(ci.histtypeoid, 'SYS:4:3709', DECODE(ci.taxcodeoid, 'SYS:4:4118', NVL(ci.amount,0), 0), 0) ), 0)) || '~'
|| TO_CHAR(NVL(SUM(DECODE(ci.histtypeoid, 'SYS:4:3709', DECODE(ci.taxcodeoid, 'SYS:4:4114', NVL(ci.amount,0), 0), 0) ), 0)) || '~'
|| NVL(MAX(DECODE(ci.histtypeoid, 'SYS:4:3709', DECODE(ci.taxcodeoid, 'SYS:4:4114', ci.code, NULL), NULL)), CHR(155)) || '~'
|| TO_CHAR(NVL(SUM(DECODE(ci.histtypeoid, 'SYS:4:3709', DECODE(ci.taxcodeoid, 'SYS:4:2988', NVL(ci.amount,0), 0), 0) ), 0)) || '~'
|| TO_CHAR(NVL(SUM(DECODE(ci.histtypeoid, 'SYS:4:3709', DECODE(ci.taxcodeoid, 'SYS:4:2989', NVL(ci.amount,0), 0), 0) ), 0)) || '~'
|| NVL(MAX(DECODE(ci.histtypeoid, 'SYS:4:3709', DECODE(ci.taxcodeoid, 'SYS:4:2989', ci.code, NULL), NULL)), CHR(155)) || '~'
|| NVL(MAX(DECODE(ci.histtypeoid, 'SYS:4:3709', DECODE(ci.taxcodeoid, 'SYS:4:2983', ci.code, NULL), NULL)), CHR(155)) || '~'
|| NVL(MAX(DECODE(ci.histtypeoid, 'SYS:4:3709', DECODE(ci.taxcodeoid, 'SYS:4:2986', ci.code, NULL), NULL)), CHR(155)) || '~'
|| TO_CHAR(NVL(SUM(DECODE(ci.histtypeoid, 'SYS:4:3709', DECODE(ci.taxcodeoid, 'SYS:4:2983', NVL(ci.amount,0), 0), 0) ), 0)) || '~'
|| TO_CHAR(NVL(SUM(DECODE(ci.histtypeoid, 'SYS:4:3709', DECODE(ci.taxcodeoid, 'SYS:4:2986', NVL(ci.amount,0), 0), 0) ), 0)) || '~'
|| TO_CHAR(NVL(SUM(DECODE(ci.histtypeoid, 'SYS:4:3713', NVL(ci.amount,0), 0)), 0)) || '~'
|| TO_CHAR(NVL(SUM(DECODE(ci.histtypeoid, 'SYS:4:3727', NVL(ci.amount,0), 0)), 0)) || '~'
|| TO_CHAR(NVL(SUM(DECODE(ci.histtypeoid, 'SYS:4:3715', NVL(ci.amount,0), 0)), 0)) || '~'
|| TO_CHAR(NVL(SUM(DECODE(ci.histtypeoid, 'SYS:4:3716', NVL(ci.amount,0), 0)), 0)) || '~'
-- R16 columns.
-- Total Deductions Amount === Other Deductions on UI screen.
|| TO_CHAR(NVL(SUM(DECODE(chcat.name, 'DeductionHistory'
, DECODE(NVL(ci.statutory_ded, 0), 0
, DECODE(ci.taxcodeoid, NULL
, DECODE(ci.code, NULL, 0, NVL(ci.amount,0)), 0), 0), 0)), 0)) || '~' -- "Total Deductions Amount"
|| TO_CHAR(NVL(SUM(DECODE(chcat.name, 'OvertimeHours', NVL(ci.amount,0)
, 'AdditionalHours', NVL(ci.amount,0), 'RegularHours', NVL(ci.amount,0), 0)), 0)) || '~' -- "Total Hours Amount"
|| TO_CHAR(NVL(SUM(DECODE(chcat.name, 'Memo', NVL(ci.amount,0), 0)), 0)) || '~' -- "Total Memo Amount"
|| TO_CHAR(NVL(SUM(DECODE(chcat.name, 'AdditionalEarnings', NVL(ci.amount,0), 0)), 0)) || '~' -- "Total Other Earnings"
|| TO_CHAR(NVL(SUM(DECODE(chcat.name, 'AdditionalHours', NVL(ci.amount,0), 0)), 0)) -- "Total Other Hours"
FROM
px16_checkhistoryitem ci
, px16_sys_type chcat
WHERE
ci.cidn=chd.cidn
AND ci.checkhistorydistributionoid = chd.oid
AND chcat.category = 'CheckHistoryItem'
AND chcat.oid = ci.histtypeoid
-- AND ci.histtypeoid IN ('SYS:4:3713', 'SYS:4:3727', 'SYS:4:3715', 'SYS:4:3716', 'SYS:4:3709')
), '0' || '~' || CHR(155) || '~' || CHR(155)
|| '0~0~0~0~' || CHR(155) || '~0~0~' || CHR(155) || '~' || CHR(155) || '~'
|| CHR(155) || '~0~0~0~0~0~0'
) taxes_and_rates
, ch.check_seq_num check_seq_num
, ch.home_cost_number home_costnumber_desc
, SUBSTR(f_type_px16(ch.cidn,ch.payfrequencyoid, 'NAME'), 1, 255) tax_frequency
, (ch.co_code || '/' || ch.home_cost_number) co_chkv_home_cost_no
, chd.worked_in_cost_number cost_no_worked_in
, chd.distribution_number distribution_number
, DECODE(NVL(ch.reversed_flag, 0), 1, 'Y', 'N') chk_reverse
FROM
px16_checkhistory ch
, px16_employment em
, px16_person pe
, px16_payrollgroup pg
, px16_checkhistory_dist chd
, px16_appointment ap
WHERE
ch.cidn = em.cidn
and em.cidn = pe.cidn
and pg.cidn = ch.cidn
and ch.cidn = chd.cidn
and ap.cidn(+) = em.cidn
and ch.employmentoid=em.oid
AND em.personoid=pe.oid
AND pg.co_code = ch.co_code
AND ch.active = 1
AND ch.oid = chd.checkhistoryoid
AND ap.employmentoid(+) = em.oid
AND DECODE(ap.oid, NULL, 1, NVL((SELECT 1 FROM px16_payrollagreement pa
WHERE
pa.cidn = ap.cidn
and pa.cidn = ch.cidn
and pa.cidn = pg.cidn
and pa.appointmentoid = ap.oid
AND pa.file_number = ch.file_nb
AND pa.cocodeoid = pg.oid), 0)) = 1
and ch.cidn in (select distinct s_cidn from nonsuper_user_check)
AND ( sys_context('payx_r16_app_context', 'app_role') in ('ADP', 'CSR')
or (exists (select 1 from super_user_check where su_cidn =ch.cidn))
or (ch.cidn,ch.co_code,ch.home_dept_code) in (select cidn,co_code,dep from user_security_homedept)
or (ch.cidn,ch.co_code,ch.home_cost_number) in (select cidn,co_code,code from user_security_cost_no)
or ( exists(select co_code from user_security_homedept where cidn=ch.cidn and co_code = ch.co_code and dep is null)
and exists(select co_code from user_security_cost_no where cidn=ch.cidn and co_code = ch.co_code and cost_no = 0) )
Explain plan
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)|
| 0 | SELECT STATEMENT | | 1 | 7519 | 99 (2)|
| 1 | VIEW | PX16_CHK_VW_SUMMARY_VW | 1 | 7519 | |
| 2 | SORT UNIQUE | | 1 | 445 | 78 (0)|
|* 3 | FILTER | | | | |
| 4 | NESTED LOOPS OUTER | | 1 | 445 | 63 (2)|
| 5 | NESTED LOOPS | | 1 | 414 | 58 (2)|
| 6 | NESTED LOOPS | | 1 | 362 | 53 (2)|
| 7 | NESTED LOOPS | | 1 | 331 | 48 (3)|
| 8 | NESTED LOOPS | | 1 | 306 | 43 (3)|
| 9 | NESTED LOOPS | | 1 | 253 | 38 (3)|
| 10 | NESTED LOOPS | | 1 | 120 | 23 (5)|
| 11 | NESTED LOOPS | | 1 | 79 | 18 (6)|
| 12 | NESTED LOOPS | | 1 | 53 | 13 (8)|
|* 13 | INDEX FAST FULL SCAN | USERPROFILE_GG_U | 5 | 110 | 11 (0)|
|* 14 | INDEX RANGE SCAN | UQ_LINK | 1 | 31 | |
| 15 | TABLE ACCESS BY INDEX ROWID | PCP_USER | 1 | 26 | 6 (17)|
|* 16 | INDEX RANGE SCAN | XIF3PCP_USER | 1 | | |
|* 17 | TABLE ACCESS BY INDEX ROWID | ASSOCIATE | 1 | 41 | 6 (17)|
|* 18 | INDEX UNIQUE SCAN | ASSOCIATE_GG_U | 1 | | |
|* 19 | TABLE ACCESS BY INDEX ROWID | CHECKHISTORY | 1 | 133 | 16 (7)|
|* 20 | INDEX RANGE SCAN | J_CO_CODE | 13 | | 2 (0)|
| 21 | TABLE ACCESS BY INDEX ROWID | CHECKHISTORYDISTRIBUTION | 1 | 53 | 6 (17)|
|* 22 | INDEX RANGE SCAN | TMP_IDX11 | 1 | | |
| 23 | TABLE ACCESS BY INDEX ROWID | PAYROLLGROUP | 1 | 25 | 6 (17)|
|* 24 | INDEX RANGE SCAN | PAYROLLGROUP_IDX2 | 1 | | |
| 25 | TABLE ACCESS BY INDEX ROWID | EMPLOYMENT | 1 | 31 | 6 (17)|
|* 26 | INDEX UNIQUE SCAN | EMPLOYMENT_GG_U | 1 | | |
| 27 | TABLE ACCESS BY INDEX ROWID | PERSON | 1 | 52 | 6 (17)|
|* 28 | INDEX UNIQUE SCAN | PERSON_GG_U | 1 | | |
| 29 | TABLE ACCESS BY INDEX ROWID | APPOINTMENT | 1 | 31 | 6 (17)|
|* 30 | INDEX RANGE SCAN | XIF12APPOINTMENT | 1 | | |
|* 31 | FILTER | | | | |
|* 32 | TABLE ACCESS BY INDEX ROWID | PAYROLLAGREEMENT | 1 | 34 | 21 (5)|
|* 33 | INDEX RANGE SCAN | UQ_FILE_NO_COCODE | 1 | | 3 (0)|
|* 34 | FILTER | | | | |
| 35 | NESTED LOOPS | | 1 | 130 | 27 (4)|
| 36 | NESTED LOOPS | | 1 | 89 | 22 (5)|
| 37 | NESTED LOOPS | | 1 | 63 | 17 (6)|
|* 38 | TABLE ACCESS BY INDEX ROWID | USERPROFILE | 1 | 41 | 16 (7)|
|* 39 | INDEX RANGE SCAN | XIF1USERPROFILE | 1 | | 2 (0)|
|* 40 | INDEX RANGE SCAN | LINK_IDX2 | 1 | 22 | |
| 41 | TABLE ACCESS BY INDEX ROWID | PCP_USER | 1 | 26 | 6 (17)|
|* 42 | INDEX RANGE SCAN | XIF3PCP_USER | 1 | | |
|* 43 | TABLE ACCESS BY INDEX ROWID | ASSOCIATE | 1 | 41 | 6 (17)|
|* 44 | INDEX UNIQUE SCAN | ASSOCIATE_GG_U | 1 | | |
|* 45 | FILTER | | | | |
| 46 | NESTED LOOPS | | 1 | 144 | 48 (3)|
| 47 | MERGE JOIN CARTESIAN | | 1 | 142 | 37 (3)|
| 48 | NESTED LOOPS | | 1 | 116 | 32 (4)|
| 49 | NESTED LOOPS | | 1 | 96 | 31 (4)|
| 50 | NESTED LOOPS | | 1 | 72 | 26 (4)|
|* 51 | TABLE ACCESS BY INDEX ROWID | COCODEGROUP | 1 | 34 | 21 (5)|
|* 52 | INDEX RANGE SCAN | XIF1COCODEGROUP | 9 | | 2 (0)|
|* 53 | TABLE ACCESS BY INDEX ROWID | ASSOCIATE | 1 | 38 | 6 (17)|
|* 54 | INDEX UNIQUE SCAN | ASSOCIATE_GG_U | 1 | | |
|* 55 | INDEX RANGE SCAN | COSEC_IDX_GG | 1 | 24 | 1 (0)|
|* 56 | INDEX UNIQUE SCAN | SECURITY_GROUP_GG_U | 1 | 20 | |
| 57 | BUFFER SORT | | 1 | 26 | 35 (0)|
|* 58 | INDEX RANGE SCAN | UQ_SECURITYOBJECT | 1 | 26 | 1 (0)|
|* 59 | COLLECTION ITERATOR PICKLER FETCH | F_STR2TBL_PX16 | | | |
|* 60 | FILTER | | | | |
| 61 | SORT GROUP BY | | 1 | 183 | 66 (0)|
| 62 | NESTED LOOPS | | 1 | 183 | 51 (2)|
| 63 | NESTED LOOPS | | 1 | 163 | 50 (2)|
|* 64 | HASH JOIN OUTER | | 1 | 139 | 45 (3)|
| 65 | NESTED LOOPS | | 1 | 96 | 42 (3)|
|* 66 | HASH JOIN | | 1 | 58 | 37 (3)|
| 67 | TABLE ACCESS BY INDEX ROWID | SECURITYOBJECT | 13 | 338 | 16 (7)|
|* 68 | INDEX RANGE SCAN | SECURITYOBJECT_IDX1 | 13 | | 2 (0)|
| 69 | TABLE ACCESS BY INDEX ROWID | COCODEGROUP | 9 | 288 | 21 (5)|
|* 70 | INDEX RANGE SCAN | XIF1COCODEGROUP | 1 | | 2 (0)|
|* 71 | TABLE ACCESS BY INDEX ROWID | ASSOCIATE | 1 | 38 | 6 (17)|
|* 72 | INDEX UNIQUE SCAN | ASSOCIATE_GG_U | 1 | | |
|* 73 | TABLE ACCESS FULL | CUSTOMACCESSDETAIL | 9 | 387 | 2 (0)|
|* 74 | INDEX RANGE SCAN | COSEC_IDX_GG | 1 | 24 | 1 (0)|
|* 75 | INDEX UNIQUE SCAN | SECURITY_GROUP_GG_U | 1 | 20 | |
| 76 | VIEW | | 1 | 2032 | |
| 77 | SORT UNIQUE | | 1 | 144 | 63 (0)|
|* 78 | FILTER | | | | |
| 79 | NESTED LOOPS | | 1 | 144 | 48 (3)|
| 80 | NESTED LOOPS | | 1 | 142 | 37 (3)|
| 81 | NESTED LOOPS | | 1 | 104 | 32 (4)|
| 82 | NESTED LOOPS | | 1 | 84 | 31 (4)|
| 83 | NESTED LOOPS | | 1 | 60 | 26 (4)|
|* 84 | TABLE ACCESS BY INDEX ROWID | COCODEGROUP | 1 | 34 | 21 (5)|
|* 85 | INDEX RANGE SCAN | XIF1COCODEGROUP | 9 | | 2 (0)|
|* 86 | INDEX RANGE SCAN | UQ_SECURITYOBJECT | 1 | 26 | 1 (0)|
|* 87 | INDEX RANGE SCAN | COSEC_IDX_GG | 1 | 24 | 1 (0)|
|* 88 | INDEX UNIQUE SCAN | SECURITY_GROUP_GG_U | 1 | 20 | |
|* 89 | TABLE ACCESS BY INDEX ROWID | ASSOCIATE | 1 | 38 | 6 (17)|
|* 90 | INDEX UNIQUE SCAN | ASSOCIATE_GG_U | 1 | | |
|* 91 | COLLECTION ITERATOR PICKLER FETCH| F_STR2TBL_PX16 | | | |
| 92 | VIEW | | 1 | 43 | |
|* 93 | FILTER | | | | |
| 94 | SORT GROUP BY | | 1 | 183 | 55 (0)|
|* 95 | FILTER | | | | |
| 96 | NESTED LOOPS | | 1 | 183 | 40 (3)|
| 97 | NESTED LOOPS | | 1 | 163 | 39 (3)|
|* 98 | HASH JOIN OUTER | | 1 | 139 | 34 (3)|
| 99 | NESTED LOOPS | | 1 | 96 | 31 (4)|
| 100 | NESTED LOOPS | | 1 | 58 | 26 (4)|
|*101 | TABLE ACCESS BY INDEX ROWID | COCODEGROUP | 1 | 32 | 21 (5)|
|*102 | INDEX RANGE SCAN | XIF1COCODEGROUP | 9 | | 2 (0)|
|*103 | INDEX RANGE SCAN | UQ_SECURITYOBJECT | 1 | 26 | 1 (0)|
|*104 | TABLE ACCESS BY INDEX ROWID | ASSOCIATE | 1 | 38 | 6 (17)|
|*105 | INDEX UNIQUE SCAN | ASSOCIATE_GG_U | 1 | | |
|*106 | TABLE ACCESS FULL | CUSTOMACCESSDETAIL | 9 | 387 | 2 (0)|
|*107 | INDEX RANGE SCAN | COSEC_IDX_GG | 1 | 24 | 1 (0)|
|*108 | INDEX UNIQUE SCAN | SECURITY_GROUP_GG_U | 1 | 20 | |
Predicate Information (identified by operation id):
3 - filter(DECODE("SYS_ALIAS_19"."OID",NULL,1,NVL( (SELECT /*+ */ 1 FROM "PAYX_R16"."PAYROLLAGREEMENT"
"PX16_PAYROLLAGREEMENT" WHERE :B1='C69C1Y' AND :B2=:B3 AND :B4=:B5 AND
"PX16_PAYROLLAGREEMENT"."FILE_NUMBER"=TO_NUMBER(:B6) AND "PX16_PAYROLLAGREEMENT"."COCODEOID"=:B7 AND
"PX16_PAYROLLAGREEMENT"."CIDN"=:B8 AND "PX16_PAYROLLAGREEMENT"."APPOINTMENTOID"=:B9),0))=1 AND
(SYS_CONTEXT('payx_r16_app_context','app_role')='ADP' OR
SYS_CONTEXT('payx_r16_app_context','app_role')='CSR' OR EXISTS (SELECT /*+ */ 0 FROM
"PAYX_R16"."PCP_USER" "PX16_PCP_USER","PAYX_R16"."ASSOCIATE" "PX16_ASSOCIATE","PAYX_R16"."USERPROFILE"
"PX16_USERPROFILE","PAYX_R16"."LINK" "PX16_LINK" WHERE :B10='C69C1Y' AND
"PX16_LINK"."PARENTOID"="PX16_USERPROFILE"."OID" AND "PX16_LINK"."CIDN"='C69C1Y' AND
"PX16_LINK"."CIDN"=:B11 AND "PX16_USERPROFILE"."CIDN"='C69C1Y' AND UPPER("PX16_USERPROFILE"."NAME")='SUPER
USER' AND "PX16_USERPROFILE"."CIDN"=:B12 AND "PX16_ASSOCIATE"."CIDN"=:B13 AND
"PX16_ASSOCIATE"."OID"="PX16_PCP_USER"."OID" AND "PX16_ASSOCIATE"."ACTIVE"=1 AND
UPPER("PX16_ASSOCIATE"."NAME")=UPPER(SYS_CONTEXT('payx_r16_app_context','app_userid')) AND
"PX16_PCP_USER"."USERPROFILEOID"="PX16_USERPROFILE"."OID" AND "PX16_PCP_USER"."CIDN"='C69C1Y' AND
"PX16_PCP_USER"."USERPROFILEOID" IS NOT NULL AND "PX16_PCP_USER"."CIDN"=:B14) OR EXISTS (SELECT /*+ */ 0
FROM TABLE("CRUVPD"."F_STR2TBL_PX16"("PX16_COCODEGROUP"."DEPARTMENT_ACCESS"))
"KOKBF$","PAYX_R16"."SECURITY_GROUP" "PX16_SECURITY_GROUP","PAYX_R16"."COCODEGROUP_SECURITYGROUP"
"PX16_COCODEGRP_SECURITYGRP","PAYX_R16"."SECURITYOBJECT" "PX16_SECURITYOBJECT","PAYX_R16"."ASSOCIATE"
"PX16_ASSOCIATE","PAYX_R16"."COCODEGROUP" "PX16_COCODEGROUP" WHERE :B15='C69C1Y' AND
"PX16_COCODEGROUP"."CIDN"=:B16 AND "PX16_COCODEGROUP"."CO_CODE"=:B17 AND "PX16_ASSOCIATE"."CIDN"='C69C1Y'
AND "PX16_COCODEGROUP"."USEROID"="PX16_ASSOCIATE"."OID" AND
UPPER("PX16_ASSOCIATE"."NAME")=UPPER(SYS_CONTEXT('payx_r16_app_context','app_userid')) AND
"PX16_ASSOCIATE"."CIDN"=:B18 AND "PX16_SECURITYOBJECT"."CIDN"='C69C1Y' AND
SUBSTR("PX16_SECURITYOBJECT"."NAME",8,3)=:B19 AND "PX16_SECURITYOBJECT"."CIDN"=:B20 AND
"PX16_COCODEGROUP"."OID"="PX16_COCODEGRP_SECURITYGRP"."COCODEGROUPOID" AND
"PX16_COCODEGRP_SECURITYGRP"."CIDN"=:B21 AND "PX16_COCODEGRP_SECURITYGRP"."CIDN"='C69C1Y' AND
"PX16_SECURITY_GROUP"."CIDN"='C69C1Y' AND "PX16_COCODEGRP_SECURITYGRP"."SECURITYGROUPOID"="PX16_SECURITY_GR
OUP"."OID" AND "PX16_SECURITY_GROUP"."CIDN"=:B22 AND VALUE(KOKBF$)=:B23) OR EXISTS (SELECT /*+ */ 0 FROM
"PAYX_R16"."CUSTOMACCESSDETAIL" "PX16_CUSTOMACCESSDETAIL","PAYX_R16"."SECURITY_GROUP"
"PX16_SECURITY_GROUP","PAYX_R16"."COCODEGROUP_SECURITYGROUP"
"PX16_COCODEGRP_SECURITYGRP","PAYX_R16"."SECURITYOBJECT" "PX16_SECURITYOBJECT","PAYX_R16"."ASSOCIATE"
"PX16_ASSOCIATE","PAYX_R16"."COCODEGROUP" "PX16_COCODEGROUP" WHERE "PX16_COCODEGROUP"."CIDN"='C69C1Y' AND
"PX16_COCODEGROUP"."CIDN"="PX16_SECURITYOBJECT"."CIDN" AND
"PX16_COCODEGROUP"."CO_CODE"=SUBSTR("PX16_SECURITYOBJECT"."NAME",8,3) AND "PX16_ASSOCIATE"."CIDN"='C69C1Y'
AND "PX16_COCODEGROUP"."USEROID"="PX16_ASSOCIATE"."OID" AND
UPPER("PX16_ASSOCIATE"."NAME")=UPPER(SYS_CONTEXT('payx_r16_app_context','app_userid')) AND
"PX16_COCODEGROUP"."CIDN"="PX16_ASSOCIATE"."CIDN" AND "PX16_SECURITYOBJECT"."CIDN"='C69C1Y' AND
"PX16_COCODEGROUP"."OID"="PX16_COCODEGRP_SECURITYGRP"."COCODEGROUPOID" AND
"PX16_COCODEGROUP"."CIDN"="PX16_COCODEGRP_SECURITYGRP"."CIDN" AND
"PX16_COCODEGRP_SECURITYGRP"."CIDN"='C69C1Y' AND "PX16_SECURITY_GROUP"."CIDN"='C69C1Y' AND
"PX16_COCODEGRP_SECURITYGRP"."SECURITYGROUPOID"="PX16_SECURITY_GROUP"."OID" AND
"PX16_COCODEGRP_SECURITYGRP"."CIDN"="PX16_SECURITY_GROUP"."CIDN" AND
"PX16_COCODEGROUP"."CIDN"="PX16_CUSTOMACCESSDETAIL"."CIDN"(+) AND
"PX16_COCODEGROUP"."OID"="PX16_CUSTOMACCESSDETAIL"."COCODEGROUPOID"(+) AND
"PX16_CUSTOMACCESSDETAIL"."CIDN"(+)='C69C1Y' GROUP BY
"PX16_COCODEGROUP"."CIDN","PX16_COCODEGROUP"."CO_CODE","PX16_CUSTOMACCESSDETAIL"."CODE" HAVING
"PX16_COCODEGROUP"."CIDN"=:B24 AND "PX16_COCODEGROUP"."CO_CODE"=:B25 AN)
13 - filter("PX16_USERPROFILE"."CIDN"='C69C1Y')
14 - access("PX16_LINK"."CIDN"='C69C1Y' AND "PX16_LINK"."CHILDOID"='SYS:5:7478' AND
"PX16_LINK"."PARENTOID"="PX16_USERPROFILE"."OID")
filter("PX16_LINK"."CIDN"="PX16_USERPROFILE"."CIDN")
16 - access("PX16_PCP_USER"."CIDN"='C69C1Y' AND "PX16_PCP_USER"."USERPROFILEOID"="PX16_USERPROFILE"."OID"
filter("PX16_PCP_USER"."USERPROFILEOID" IS NOT NULL AND
"PX16_PCP_USER"."CIDN"="PX16_USERPROFILE"."CIDN")
17 - filter("PX16_ASSOCIATE"."ACTIVE"=1 AND UPPER("PX16_ASSOCIATE"."NAME")=UPPER(SYS_CONTEXT('payx_r16_ap
p_context','app_userid')))
18 - access("PX16_ASSOCIATE"."OID"="PX16_PCP_USER"."OID" AND "PX16_ASSOCIATE"."CIDN"='C69C1Y')
filter("PX16_ASSOCIATE"."CIDN"="PX16_PCP_USER"."CIDN")
19 - filter("SYS_ALIAS_32"."ACTIVE"=1)
20 - access("SYS_ALIAS_32"."CIDN"='C69C1Y')
filter("SYS_ALIAS_32"."CIDN"="PX16_ASSOCIATE"."CIDN")
22 - access("SYS_ALIAS_15"."CIDN"='C69C1Y' AND "SYS_ALIAS_32"."OID"="SYS_ALIAS_15"."CHECKHISTORYOID")
filter("SYS_ALIAS_32"."CIDN"="SYS_ALIAS_15"."CIDN")
24 - access("SYS_ALIAS_21"."CIDN"='C69C1Y' AND "SYS_ALIAS_21"."CO_CODE"="SYS_ALIAS_32"."CO_CODE")
filter("SYS_ALIAS_21"."CIDN"="SYS_ALIAS_32"."CIDN")
26 - access("SYS_ALIAS_32"."EMPLOYMENTOID"="SYS_ALIAS_11"."OID" AND "SYS_ALIAS_11"."CIDN"='C69C1Y')
filter("SYS_ALIAS_32"."CIDN"="SYS_ALIAS_11"."CIDN")
28 - access("SYS_ALIAS_11"."PERSONOID"="PX16_PERSON"."OID" AND "PX16_PERSON"."CIDN"='C69C1Y')
filter("SYS_ALIAS_11"."CIDN"="PX16_PERSON"."CIDN")
30 - access("SYS_ALIAS_19"."CIDN"(+)='C69C1Y' AND "SYS_ALIAS_19"."EMPLOYMENTOID"(+)="SYS_ALIAS_11"."OID")
filter("SYS_ALIAS_19"."CIDN"(+)="SYS_ALIAS_11"."CIDN")
31 - filter(:B1='C69C1Y' AND :B2=:B3 AND :B4=:B5)
32 - filter("PX16_PAYROLLAGREEMENT"."APPOINTMENTOID"=:B1)
33 - access("PX16_PAYROLLAGREEMENT"."CIDN"=:B1 AND "PX16_PAYROLLAGREEMENT"."COCODEOID"=:B2 AND
"PX16_PAYROLLAGREEMENT"."FILE_NUMBER"=TO_NUMBER(:B3))
34 - filter(:B1='C69C1Y')
38 - filter(UPPER("PX16_USERPROFILE"."NAME")='SUPER USER')
39 - access("PX16_USERPROFILE"."CIDN"='C69C1Y')
filter("PX16_USERPROFILE"."CIDN"=:B1)
40 - access("PX16_LINK"."CIDN"='C69C1Y' AND "PX16_LINK"."PARENTOID"="PX16_USERPROFILE"."OID")
filter("PX16_LINK"."CIDN"=:B1)
42 - access("PX16_PCP_USER"."CIDN"='C69C1Y' AND "PX16_PCP_USER"."USERPROFILEOID"="PX16_USERPROFILE"."OID"
filter("PX16_PCP_USER"."USERPROFILEOID" IS NOT NULL AND "PX16_PCP_USER"."CIDN"=:B1)
43 - filter("PX16_ASSOCIATE"."ACTIVE"=1 AND UPPER("PX16_ASSOCIATE"."NAME")=UPPER(SYS_CONTEXT('payx_r16_ap
p_context','app_userid')))
44 - access("PX16_ASSOCIATE"."OID"="PX16_PCP_USER"."OID" AND "PX16_ASSOCIATE"."CIDN"=:B1)
45 - filter(:B1='C69C1Y')
51 - filter("PX16_COCODEGROUP"."CO_CODE"=:B1)
52 - access("PX16_COCODEGROUP"."CIDN"=:B1)
53 - filter(UPPER("PX16_ASSOCIATE"."NAME")=UPPER(SYS_CONTEXT('payx_r16_app_context','app_userid')))
54 - access("PX16_COCODEGROUP"."USEROID"="PX16_ASSOCIATE"."OID" AND "PX16_ASSOCIATE"."CIDN"='C69C1Y')
filter("PX16_ASSOCIATE"."CIDN"=:B1)
55 - access("PX16_COCODEGROUP"."OID"="PX16_COCODEGRP_SECURITYGRP"."COCODEGROUPOID" AND
"PX16_COCODEGRP_SECURITYGRP"."CIDN"='C69C1Y')
filter("PX16_COCODEGRP_SECURITYGRP"."CIDN"=:B1 AND "PX16_COCODEGRP_SECURITYGRP"."CIDN"='C69C1Y')
56 - access("PX16_COCODEGRP_SECURITYGRP"."SECURITYGROUPOID"="PX16_SECURITY_GROUP"."OID" AND
"PX16_SECURITY_GROUP"."CIDN"='C69C1Y')
filter("PX16_SECURITY_GROUP"."CIDN"=:B1)
58 - access("PX16_SECURITYOBJECT"."CIDN"='C69C1Y')
filter(SUBSTR("PX16_SECURITYOBJECT"."NAME",8,3)=:B1 AND "PX16_SECURITYOBJECT"."CIDN"=:B2)
59 - filter(VALUE(KOKBF$)=:B1)
60 - filter("PX16_COCODEGROUP"."CIDN"=:B1 AND "PX16_COCODEGROUP"."CO_CODE"=:B2 AND
"PX16_CUSTOMACCESSDETAIL"."CODE"=:B3)
64 - access("PX16_COCODEGROUP"."OID"="PX16_CUSTOMACCESSDETAIL"."COCODEGROUPOID"(+) AND
"PX16_COCODEGROUP"."CIDN"="PX16_CUSTOMACCESSDETAIL"."CIDN"(+))
66 - access("PX16_COCODEGROUP"."CO_CODE"=SUBSTR("PX16_SECURITYOBJECT"."NAME",8,3) AND
"PX16_COCODEGROUP"."CIDN"="PX16_SECURITYOBJECT"."CIDN")
68 - access("PX16_SECURITYOBJECT"."CIDN"='C69C1Y')
70 - access("PX16_COCODEGROUP"."CIDN"='C69C1Y')
71 - filter(UPPER("PX16_ASSOCIATE"."NAME")=UPPER(SYS_CONTEXT('payx_r16_app_context','app_userid')))
72 - access("PX16_COCODEGROUP"."USEROID"="PX16_ASSOCIATE"."OID" AND "PX16_ASSOCIATE"."CIDN"='C69C1Y')
filter("PX16_COCODEGROUP"."CIDN"="PX16_ASSOCIATE"."CIDN")
73 - filter("PX16_CUSTOMACCESSDETAIL"."CIDN"(+)='C69C1Y')
74 - access("PX16_COCODEGROUP"."OID"="PX16_COCODEGRP_SECURITYGRP"."COCODEGROUPOID" AND
"PX16_COCODEGRP_SECURITYGRP"."CIDN"='C69C1Y')
filter("PX16_COCODEGROUP"."CIDN"="PX16_COCODEGRP_SECURITYGRP"."CIDN" AND
"PX16_COCODEGRP_SECURITYGRP"."CIDN"='C69C1Y')
75 - access("PX16_COCODEGRP_SECURITYGRP"."SECURITYGROUPOID"="PX16_SECURITY_GROUP"."OID" AND
"PX16_SECURITY_GROUP"."CIDN"='C69C1Y')
filter("PX16_COCODEGRP_SECURITYGRP"."CIDN"="PX16_SECURITY_GROUP"."CIDN")
78 - filter('C69C1Y'=:B1)
84 - filter("PX16_COCODEGROUP"."CO_CODE"=:B1)
85 - access("PX16_COCODEGROUP"."CIDN"='C69C1Y')
86 - access("PX16_SECURITYOBJECT"."CIDN"='C69C1Y')
filter(SUBSTR("PX16_SECURITYOBJECT"."NAME",8,3)=:B1 AND
"PX16_COCODEGROUP"."CIDN"="PX16_SECURITYOBJECT"."CIDN")
87 - access("PX16_COCODEGROUP"."OID"="PX16_COCODEGRP_SECURITYGRP"."COCODEGROUPOID" AND
"PX16_COCODEGRP_SECURITYGRP"."CIDN"='C69C1Y')
filter("PX16_COCODEGROUP"."CIDN"="PX16_COCODEGRP_SECURITYGRP"."CIDN" AND
"PX16_COCODEGRP_SECURITYGRP"."CIDN"='C69C1Y')
88 - access("PX16_COCODEGRP_SECURITYGRP"."SECURITYGROUPOID"="PX16_SECURITY_GROUP"."OID" AND
"PX16_SECURITY_GROUP"."CIDN"='C69C1Y')
filter("PX16_COCODEGRP_SECURITYGRP"."CIDN"="PX16_SECURITY_GROUP"."CIDN")
89 - filter(UPPER("PX16_ASSOCIATE"."NAME")=UPPER(SYS_CONTEXT('payx_r16_app_context','app_userid')))
90 - access("PX16_COCODEGROUP"."USEROID"="PX16_ASSOCIATE"."OID" AND "PX16_ASSOCIATE"."CIDN"='C69C1Y')
filter("PX16_COCODEGROUP"."CIDN"="PX16_ASSOCIATE"."CIDN")
91 - filter(VALUE(KOKBF$) IS NULL)
93 - filter(COUNT(DISTINCT "PX16_CUSTOMACCESSDETAIL"."CODE")=0)
95 - filter('C69C1Y'=:B1)
98 - access("PX16_COCODEGROUP"."OID"="PX16_CUSTOMACCESSDETAIL"."COCODEGROUPOID"(+) AND
"PX16_COCODEGROUP"."CIDN"="PX16_CUSTOMACCESSDETAIL"."CIDN"(+))
101 - filter("PX16_COCODEGROUP"."CO_CODE"=:B1)
102 - access("PX16_COCODEGROUP"."CIDN"='C69C1Y')
103 - access("PX16_SECURITYOBJECT"."CIDN"='C69C1Y')
filter(SUBSTR("PX16_SECURITYOBJECT"."NAME",8,3)=:B1 AND
"PX16_COCODEGROUP"."CIDN"="PX16_SECURITYOBJECT"."CIDN")
104 - filter(UPPER("PX16_ASSOCIATE"."NAME")=UPPER(SYS_CONTEXT('payx_r16_app_context','app_userid')))
105 - access("PX16_COCODEGROUP"."USEROID"="PX16_ASSOCIATE"."OID" AND "PX16_ASSOCIATE"."CIDN"='C69C1Y')
filter("PX16_COCODEGROUP"."CIDN"="PX16_ASSOCIATE"."CIDN")
106 - filter("PX16_CUSTOMACCESSDETAIL"."CIDN"(+)='C69C1Y')
107 - access("PX16_COCODEGROUP"."OID"="PX16_COCODEGRP_SECURITYGRP"."COCODEGROUPOID" AND
"PX16_COCODEGRP_SECURITYGRP"."CIDN"='C69C1Y')
filter("PX16_COCODEGROUP"."CIDN"="PX16_COCODEGRP_SECURITYGRP"."CIDN" AND
"PX16_COCODEGRP_SECURITYGRP"."CIDN"='C69C1Y')
108 - access("PX16_COCODEGRP_SECURITYGRP"."SECURITYGROUPOID"="PX16_SECURITY_GROUP"."OID" AND
"PX16_SECURITY_GROUP"."CIDN"='C69C1Y')
filter("PX16_COCODEGRP_SECURITYGRP"."CIDN"="PX16_SECURITY_GROUP"."CIDN")
277 rows selected.
Really need advice on it.Without formatting using [ PRE ] and [ /PRE ] tags it is nearly impossible to read much less provide help.
But what is it you hope to accomplish by breaking it up into smaller views?
Improvements in ease of maintenance will likely be offset by poorer performance. -
Plz help me on below issue.
Hi all,
Below procedure used to generate monthly report.Now it's taking more than 12 hr's for 1 month data.Could you please some one give me new idea for re write the procedure or any tips for reducing time.As it is procedure i can't create explain plan.
Below code 1/4 of the procedure.I unable to post more than this.
Database Version :10.2.0.3.0
/* Formatted on 10/8/2009 3:03:59 PM (QP5 v5.115.810.9015) */
CREATE OR REPLACE PROCEDURE "SP_MONTHLY_DUMP" (
AD_FROM_DT IN DATE DEFAULT NULL ,
AD_TO_DT IN DATE DEFAULT NULL
IS
LS_REP_FILE UTL_FILE.FILE_TYPE;
LS_RESTART_FLAG VARCHAR2 (20) := NULL;
LS_RESUME_FLAG VARCHAR2 (20) := NULL;
LS_RESTART_POSITION VARCHAR2 (500) := NULL;
LN_CNT NUMBER := NULL;
LN_DATE_CNT NUMBER := NULL;
TYPE RES_TYPE_DET_ID IS RECORD (
TEST_SESSION_ID TEST_SESSION.TEST_SESSION_ID%TYPE,
TEST_TYPE_ID TEST_TYPE.TEST_TYPE_ID%TYPE,
TEST_DETAIL_ID TEST_SESSION_DETAIL.TEST_DETAIL_ID%TYPE,
TEST_SESSION_DETAIL_ID TEST_SESSION_DETAIL.TEST_SESSION_DETAIL_ID%TYPE
TYPE TY_TYPE_DET_ID
IS
TABLE OF RES_TYPE_DET_ID
INDEX BY BINARY_INTEGER;
TB_TYPE_DET_ID TY_TYPE_DET_ID;
TYPE RES_QUEST_ID
IS
RECORD (QUESTION_ID COMPANINON_STUDENT_RESPONSE.QUESTION_ID%TYPE);
TYPE TY_QUEST_ID
IS
TABLE OF RES_QUEST_ID
INDEX BY BINARY_INTEGER;
TB_QUEST_ID TY_QUEST_ID;
TYPE RES_PROMPT_ID IS RECORD (
WRITEPLACER_PROMPTS_ID WRITEPLACER_ESSAY_RESPONSE.WRITEPLACER_PROMPTS_ID%TYPE,
WRITEPLACER_STATUS_ID WRITEPLACER_ESSAY_RESPONSE.WRITEPLACER_STATUS_ID%TYPE,
WRITEPLACER_PROMPT_TYPE WRITEPLACER_PROMPTS.WRITEPLACER_PROMPT_TYPE%TYPE,
STATUS_TYPE WRITEPLACER_PKT_SUBMISSION.STATUS_TYPE%TYPE
TYPE TY_PROMPTS_ID
IS
TABLE OF RES_PROMPT_ID
INDEX BY BINARY_INTEGER;
TV_PROMPTS_ID TY_PROMPTS_ID;
TYPE RES_RESPONSE_ID
IS
RECORD (ITEM_RESPONSE_ID CAT_ITEM_USER_RESPONSE.ITEM_RESPONSE_ID%TYPE);
TYPE TY_RESPONSE_ID
IS
TABLE OF RES_RESPONSE_ID
INDEX BY BINARY_INTEGER;
TV_RESPONSE_ID TY_RESPONSE_ID;
TYPE TY_COMMA_TBL
IS
TABLE OF VARCHAR2 (4000)
INDEX BY PLS_INTEGER;
TV_COMMA_TBL TY_COMMA_TBL;
TV_POOL_TBL TY_COMMA_TBL;
TYPE TY_COUNT_TBL
IS
TABLE OF VARCHAR2 (4000)
INDEX BY PLS_INTEGER;
TV_COUNT_TBL TY_COUNT_TBL;
BEGIN
/* DATE RANGE MANUPULATION IF THE INPUT PARAMETERS IS NULL*/
IF AD_FROM_DT IS NULL AND AD_TO_DT IS NULL
THEN
SELECT TRUNC (TRUNC (SYSDATE, 'MM') - 1, 'MM'),
TRUNC (SYSDATE, 'MM') - 1
INTO LD_FROM_DT, LD_TO_DT
FROM DUAL;
ELSE
LD_FROM_DT := AD_FROM_DT;
LD_TO_DT := AD_TO_DT;
END IF;
DBMS_OUTPUT.PUT_LINE( 'THE REPORT GENERATED FOR THE DATE RANGE FROM'
|| LD_FROM_DT
|| 'TO'
|| LD_TO_DT);
LS_DT_FORMAT := 'DD-MON-YY';
LS_REP_FILE_NM :=
'MONTHLY_DATA_DUMP'
|| '_'
|| TO_CHAR (LD_FROM_DT, 'YYYYMM')
|| '_'
|| TO_CHAR (LD_TO_DT, 'YYYYMM')
|| '_'
|| TO_CHAR (SYSDATE, 'DDMONYY_HH24MISS')
|| '.CSV';
DBMS_OUTPUT.PUT_LINE ('REPORT NAME IS ' || LS_REP_FILE_NM);
LS_REP_FILE :=
UTL_FILE.FOPEN ('EXTRACT_DIR',
LS_REP_FILE_NM,
'W',
32767);
SELECT (TO_DATE (LD_TO_DT, LS_DT_FORMAT)
- TO_DATE (LD_FROM_DT, LS_DT_FORMAT))
+ 1
INTO LN_DATE_CNT
FROM DUAL;
FOR LN_DT_CNT IN 1 .. LN_DATE_CNT
LOOP
DBMS_OUTPUT.PUT_LINE ('LD_FROM_DT -' || LD_FROM_DT);
TB_TYPE_DET_ID.DELETE;
SELECT D.TEST_SESSION_ID TEST_SESSION_ID,
C.TEST_TYPE_ID TEST_TYPE_ID,
A.TEST_DETAIL_ID TEST_DETAIL_ID,
A.TEST_SESSION_DETAIL_ID TEST_SESSION_DETAIL_ID
BULK COLLECT
INTO TB_TYPE_DET_ID
FROM TEST_SESSION_DETAIL A,
TEST_DETAIL B,
TEST_TYPE C,
TEST_SESSION D
WHERE C.TEST_TYPE_ID = B.TEST_TYPE_ID
AND A.TEST_SESSION_STATUS_ID = 3
AND C.TEST_TYPE_ID IN (1, 2, 6)
AND B.TEST_DETAIL_ID = A.TEST_DETAIL_ID
AND D.TEST_SESSION_ID = A.TEST_SESSION_ID
--AND A.TEST_SESSION_DETAIL_ID IN (320050,2710987,50660,1553303,1267843)
AND TRUNC (A.TEST_END_DATE) >=
TO_DATE (LD_FROM_DT, LS_DT_FORMAT)
AND TRUNC (A.TEST_END_DATE) <=
TO_DATE (LD_FROM_DT, LS_DT_FORMAT)
ORDER BY D.TEST_SESSION_ID, A.TEST_SESSION_DETAIL_ID;
FOR TEST_TYP_ID_CNT IN NVL (TB_TYPE_DET_ID.FIRST, 1) .. NVL (
TB_TYPE_DET_ID.LAST,
0
LOOP
LS_DETAILS := NULL;
LS_DETAILS1 := NULL;
LS_DETAILS2 := NULL;
LS_DETAILS3 := NULL;
LS_DETAILS4 := NULL;
LS_BG := NULL;
BG1 := NULL;
BG2 := NULL;
BG3 := NULL;
BG4 := NULL;
BG5 := NULL;
BG6 := NULL;
BG7 := NULL;
BG8 := NULL;
BG9 := NULL;
BG10 := NULL;
BG11 := NULL;
BG12 := NULL;
BG13 := NULL;
LS_OP1 := NULL;
LS_OP2 := NULL;
LS_OP3 := NULL;
LS_BR := NULL;
LS_FINAL := NULL;
LS_DETAILS5 := NULL;
LS_SCORE1 := NULL;
LS_SCORE2 := NULL;
LS_SCORE3 := NULL;
LS_DET := NULL;
LS_COMP := NULL;
LS_COMP_1 := NULL;
LS_COMP_2 := NULL;
LS_COMP_3 := NULL;
LS_COMP_4 := NULL;
LS_COMP_A := NULL;
LS_DETAILS4_A := NULL;
LS_FINAL_1 := NULL;
LS_SCORE2_A := NULL;
LS_SCORE3_A := NULL;
LS_DETAILS5_A := NULL;
LS_CNT := NULL;
LN_COUNT := NULL;
LS_OP_1 := NULL;
LS_OP_2 := NULL;
LS_OP_3 := NULL;
LS_OP_4 := NULL;
/*PROCESSING THE TEST SESSION WHICH HAS CAT,WRITEPLACER,COMPANION TEST ASMINISTERED */
BEGIN
/*RETRIEVING THE STUDENT INFORMATION */
SELECT NVL (SUBSTR (REPLACE (A.STUDENT_ID, '^', '*'), 1, 20),
|| '^'
|| NVL (
SUBSTR (REPLACE (A.FIRST_NAME, '^', '*'), 1, 100),
|| '^'
|| NVL (
SUBSTR (TRANSLATE (A.LAST_NAME, ',^', '-*'),
1,
100),
|| '^'
|| SUBSTR (REPLACE (A.MIDDLE_NAME, '^', '*'), 1, 1)
|| '^'
|| NVL (SUBSTR (C.INSTITUTION_ID_DISPLAY, 1, 6), ' ')
|| '^'
|| NVL (SUBSTR (C.INSTITUTION_ID_DISPLAY, 1, 10), ' ')
|| '^'
|| NVL (TO_CHAR (A.DOB, 'yyyymmdd'), ' ')
INTO LS_DETAILS
FROM STUDENT A, INSTITUTION C, TEST_SESSION B
WHERE A.INSTITUTION_ID = C.INSTITUTION_ID
AND B.TEST_SESSION_ID =
TB_TYPE_DET_ID (TEST_TYP_ID_CNT).TEST_SESSION_ID
AND A.STUDENT_ID_PK = B.STUDENT_ID_PK;
EXCEPTION
WHEN NO_DATA_FOUND
THEN
LS_DETAILS := '^' || '^' || '^' || '^' || '^' || '^';
WHEN OTHERS
THEN
Sp_Insert_Error_Log (
LS_OBJECT_NAME,
SYSDATE,
'OTHERS_1',
'WHEN OTHERS TRIGGERED' || '-' || SQLERRM
END;
/* FETCHING THE STANDARD BACKGROUND QUESTION RESPONSE*/
FOR BG_QES_CUR
IN (SELECT DISTINCT BG_QUESTION_SEQUENCE, BG_QUESTION_CODE
FROM STANDARD_BG_QUESTION_CODE
UNION
SELECT 13, 'b13'
FROM ITEM
WHERE UIN = 'SBG013'
ORDER BY BG_QUESTION_SEQUENCE)
LOOP
BEGIN
LS_BG := NULL;
SELECT NVL (SUBSTR (MAX (H.BG_RESPONSE_NUMBER), 1, 2), '-3')
INTO LS_BG
FROM BG_QUESTION_USER_RESPONSE G,
STANDARD_BG_QUESTION_CODE H,
BG_SESSION_DETAIL I,
TEST_SESSION B
WHERE G.ITEM_ID = H.ITEM_ID
AND H.BG_REPONSE_TEXT = G.RESPONSE_KEY
AND G.BG_SESSION_DETAIL_ID = I.BG_SESSION_DETAIL_ID
AND I.TEST_SESSION_ID = B.TEST_SESSION_ID
AND H.BG_QUESTION_CODE = BG_QES_CUR.BG_QUESTION_CODE
AND B.TEST_SESSION_ID =
TB_TYPE_DET_ID (
TEST_TYP_ID_CNT
).TEST_SESSION_ID;
IF BG_QES_CUR.BG_QUESTION_CODE = 'b1'
THEN
BG2 := NVL (LS_BG, '-3');
ELSIF BG_QES_CUR.BG_QUESTION_CODE = 'b2'
THEN
BG1 := NVL (LS_BG, '-3');
ELSIF BG_QES_CUR.BG_QUESTION_CODE = 'b3'
THEN
BG3 := NVL (LS_BG, '-3');
ELSIF BG_QES_CUR.BG_QUESTION_CODE = 'b4'
THEN
BG4 := NVL (LS_BG, '-3');
ELSIF BG_QES_CUR.BG_QUESTION_CODE = 'b5'
THEN
BG5 := NVL (LS_BG, '-3');
ELSIF BG_QES_CUR.BG_QUESTION_CODE = 'b6'
THEN
BG6 := NVL (LS_BG, '-3');
ELSIF BG_QES_CUR.BG_QUESTION_CODE = 'b7'
THEN
BG7 := NVL (LS_BG, '-3');
ELSIF BG_QES_CUR.BG_QUESTION_CODE = 'b8'
THEN
BG8 := NVL (LS_BG, '-3');
ELSIF BG_QES_CUR.BG_QUESTION_CODE = 'b9'
THEN
BG9 := NVL (LS_BG, '-3');
ELSIF BG_QES_CUR.BG_QUESTION_CODE = 'b10'
THEN
BG10 := NVL (LS_BG, '-3');
ELSIF BG_QES_CUR.BG_QUESTION_CODE = 'b11'
THEN
BG11 := NVL (LS_BG, '-3');
ELSIF BG_QES_CUR.BG_QUESTION_CODE = 'b12'
THEN
BG12 := NVL (LS_BG, '-3');
END IF;
LS_DETAILS1 :=
BG12
|| '^'
|| BG11
|| '^'
|| BG1
|| '^'
|| BG2
|| '^'
|| BG7
|| '^'
|| BG10
|| '^'
|| BG9
|| '^'
|| BG8
|| '^'
|| BG4
|| '^'
|| BG5
|| '^'
|| BG6
|| '^'
|| BG3;
EXCEPTION
WHEN NO_DATA_FOUND
THEN
LS_DETAILS1 := ' ';
WHEN OTHERS
THEN
Sp_Insert_Error_Log (
LS_OBJECT_NAME,
SYSDATE,
'OTHERS_2',
'WHEN OTHERS TRIGGERED' || '-' || SQLERRM
END;
END LOOP;
BEGIN
/*FETCHING THE RESPONSE FOR MAJOR BACKGROUND QUESTION */
BG13 := 'x';
SELECT CASE
WHEN RESPONSE_KEY = 'Undecided'
THEN
'0'
WHEN RESPONSE_KEY = 'I choose not to answer'
THEN
'1'
WHEN RESPONSE_KEY NOT IN
('Undecided', 'I choose not to answer')
THEN
(SELECT REPLACE (MAJOR_CODE, '^', '*')
FROM MAJOR
WHERE MAJOR_ID = RESPONSE_KEY)
END
INTO BG13
FROM BG_QUESTION_USER_RESPONSE B,
ITEM I,
BG_SESSION_DETAIL G,
TEST_SESSION T
WHERE B.ITEM_ID = I.ITEM_ID
AND B.BG_SESSION_DETAIL_ID = G.BG_SESSION_DETAIL_ID
AND G.TEST_SESSION_ID = T.TEST_SESSION_ID
AND B.ITEM_ID IN (SELECT ITEM_ID
FROM ITEM
WHERE UIN = 'SBG013')
AND G.BG_SESSION_DETAIL_ID IN
(SELECT MAX (BG_SESSION_DETAIL_ID)
FROM BG_SESSION_DETAIL
WHERE TEST_SESSION_ID =
TB_TYPE_DET_ID (
TEST_TYP_ID_CNT
).TEST_SESSION_ID);
EXCEPTION
WHEN NO_DATA_FOUND
THEN
BG13 := 'x';
WHEN OTHERS
THEN
Sp_Insert_Error_Log (
LS_OBJECT_NAME,
SYSDATE,
'OTHERS_3'
|| TB_TYPE_DET_ID (TEST_TYP_ID_CNT).TEST_SESSION_ID,
'WHEN OTHERS TRIGGERED' || '-' || SQLERRM
END;
IF BG13 = 'x'
THEN
LS_BG_1 := -3;
LS_DETAILS2 := LS_DETAILS1 || '^' || LS_BG_1;
ELSE
LS_DETAILS2 := LS_DETAILS1 || '^' || BG13;
END IF;
/* RETRIEVING THE DATA SPECIFIC TO COMPANION TEST*/
IF TB_TYPE_DET_ID (TEST_TYP_ID_CNT).TEST_TYPE_ID = 6
THEN
BEGIN
SELECT NVL (SUBSTR (B.TEST_SESSION_ID, 1, 6), ' ') || '^'
|| NVL (SUBSTR (D.TEST_SESSION_DETAIL_ID, 1, 15),
|| '^'
|| NVL (
TRANSLATE (
SUBSTR (C.BRANCHING_PROFILE_NAME, 1, 50),
',^',
|| '^'
|| NVL (TO_CHAR (D.TEST_START_DATE, 'yyyymmdd'), ' ')
|| '^'
|| NVL (TO_CHAR (D.TEST_END_DATE, 'yyyymmdd'), ' ')
|| '^'
|| NVL (SUBSTR (A.TEST_ALIAS, 1, 50), ' ')
INTO LS_DET
FROM TEST_DETAIL A,
TEST_SESSION B,
BRANCHING_PROFILE C,
TEST_SESSION_DETAIL D
WHERE A.TEST_DETAIL_ID = D.TEST_DETAIL_ID
AND B.TEST_SESSION_ID = D.TEST_SESSION_ID
AND A.TEST_TYPE_ID =
TB_TYPE_DET_ID (TEST_TYP_ID_CNT).TEST_TYPE_ID
AND B.TEST_SESSION_ID =
TB_TYPE_DET_ID (
TEST_TYP_ID_CNT
).TEST_SESSION_ID
AND B.BRANCHING_PROFILE_ID = C.BRANCHING_PROFILE_ID
AND D.TEST_DETAIL_ID =
TB_TYPE_DET_ID (TEST_TYP_ID_CNT).TEST_DETAIL_ID
AND D.TEST_SESSION_DETAIL_ID =
TB_TYPE_DET_ID (
TEST_TYP_ID_CNT
).TEST_SESSION_DETAIL_ID;
EXCEPTION
WHEN NO_DATA_FOUND
THEN
LS_DETAILS3 := '^' || '^' || '^' || '^' || '^';
WHEN OTHERS
THEN
Sp_Insert_Error_Log (
LS_OBJECT_NAME,
SYSDATE,
'OTHERS_4',
'WHEN OTHERS TRIGGERED' || '-' || SQLERRM
END;
LS_DETAILS3 := LS_DET;
BEGIN
/*RETRIVING THE SCORE DATA FOR COMPANION TEST */
SELECT NVL (SUBSTR (A.COMPANION_FORM, 1, 1), ' ')
|| '^'
|| '^'
|| '^'
|| '^'
|| '^'
|| '^'
|| '^'
|| '^'
|| '^'
|| '^'
|| '^'
|| '^'
|| '^'
|| '^'
|| CASE
WHEN A.SCORE < 20
THEN
20
WHEN A.SCORE > 120
THEN
120
WHEN A.SCORE >= 20 AND A.SCORE <= 120
THEN
ROUND (A.SCORE)
END
|| '^'
|| CASE
WHEN A.SCORE < 20
THEN
20
WHEN A.SCORE > 120
THEN
120
WHEN A.SCORE >= 20 AND A.SCORE <= 120
THEN
ROUND (A.SCORE, 7)
END
|| '^'
|| '^'
|| '^'
|| '^'
|| '^'
|| '^'
|| CASE
WHEN A.SCORE < 20
THEN
20
WHEN A.SCORE > 120
THEN
120
WHEN A.SCORE >= 20 AND A.SCORE <= 120
THEN
ROUND (A.SCORE, 2)
END
INTO LS_COMP
FROM TEST_SESSION_DETAIL A, TEST_SESSION B
WHERE A.TEST_SESSION_ID =
TB_TYPE_DET_ID (TEST_TYP_ID_CNT).TEST_SESSION_ID
AND A.TEST_SESSION_ID = B.TEST_SESSION_ID
AND A.TEST_DETAIL_ID =
TB_TYPE_DET_ID (TEST_TYP_ID_CNT).TEST_DETAIL_ID
AND A.TEST_SESSION_DETAIL_ID =
TB_TYPE_DET_ID (
TEST_TYP_ID_CNT
).TEST_SESSION_DETAIL_ID;
/* THE QUESTIONS ADMINSTERED IN EACH TEST SESSION IS FETCHED*/
TB_QUEST_ID.DELETE;
SELECT QUESTION_ID
BULK COLLECT
INTO TB_QUEST_ID
FROM TEST_SESSION_DETAIL A,
TEST_SESSION B,
COMPANINON_STUDENT_RESPONSE C
WHERE A.TEST_SESSION_ID =
TB_TYPE_DET_ID (TEST_TYP_ID_CNT).TEST_SESSION_ID
AND A.TEST_DETAIL_ID = C.TEST_DETAIL_ID
AND A.TEST_SESSION_DETAIL_ID =
C.TEST_SESSION_DETAIL_ID
AND A.TEST_SESSION_ID = B.TEST_SESSION_ID
AND A.TEST_DETAIL_ID =
TB_TYPE_DET_ID (TEST_TYP_ID_CNT).TEST_DETAIL_ID
AND A.TEST_SESSION_DETAIL_ID =
TB_TYPE_DET_ID (
TEST_TYP_ID_CNT
).TEST_SESSION_DETAIL_ID
ORDER BY COMPANINON_STUDENT_RESPONSE_ID;
FOR TB_QUEST_ID_CNT IN NVL (TB_QUEST_ID.FIRST, 1) .. NVL (
TB_QUEST_ID.LAST,
0
LOOP
/*THE RESPONSE KEY, IS_CORRECT FLAG FOR EACH QUESTION INEACH SESSION IS FETCHED */
BEGIN
SELECT NVL (SUBSTR (C.RESPONSE_KEY, 1, 1), ' ')
INTO LS_COMP_1
FROM TEST_SESSION_DETAIL A,
TEST_SESSION B,
COMPANINON_STUDENT_RESPONSE C
WHERE A.TEST_SESSION_ID =
TB_TYPE_DET_ID (
TEST_TYP_ID_CNT
).TEST_SESSION_ID
AND A.TEST_DETAIL_ID = C.TEST_DETAIL_ID
AND A.TEST_SESSION_DETAIL_ID =
C.TEST_SESSION_DETAIL_ID
AND A.TEST_SESSION_ID = B.TEST_SESSION_ID
AND C.QUESTION_ID =
TB_QUEST_ID (TB_QUEST_ID_CNT).QUESTION_ID
AND A.TEST_DETAIL_ID =
TB_TYPE_DET_ID (
TEST_TYP_ID_CNT
).TEST_DETAIL_ID
AND A.TEST_SESSION_DETAIL_ID =
TB_TYPE_DET_ID (
TEST_TYP_ID_CNT
).TEST_SESSION_DETAIL_ID;
EXCEPTION
WHEN NO_DATA_FOUND
THEN
LS_COMP_1 := ' ';
WHEN OTHERS
THEN
Sp_Insert_Error_Log (
LS_OBJECT_NAME,
SYSDATE,
'OTHERS_5',
'WHEN OTHERS TRIGGERED' || '-' || SQLERRM
END;
BEGIN
SELECT NVL (SUBSTR (C.IS_CORRECT, 1, 1), ' ')
INTO LS_COMP_3
FROM TEST_SESSION_DETAIL A,
TEST_SESSION B,
COMPANINON_STUDENT_RESPONSE C
WHERE A.TEST_SESSION_ID =
TB_TYPE_DET_ID (
TEST_TYP_ID_CNT
).TEST_SESSION_ID
AND A.TEST_DETAIL_ID = C.TEST_DETAIL_ID
AND A.TEST_SESSION_DETAIL_ID =
C.TEST_SESSION_DETAIL_ID
AND A.TEST_SESSION_ID = B.TEST_SESSION_ID
AND C.QUESTION_ID =
TB_QUEST_ID (TB_QUEST_ID_CNT).QUESTION_ID
AND A.TEST_DETAIL_ID =
TB_TYPE_DET_ID (
TEST_TYP_ID_CNT
).TEST_DETAIL_ID
AND A.TEST_SESSION_DETAIL_ID =
TB_TYPE_DET_ID (
TEST_TYP_ID_CNT
).TEST_SESSION_DETAIL_ID;
EXCEPTION
WHEN NO_DATA_FOUND
THEN
LS_COMP_3 := ' ';
WHEN OTHERS
THEN
Sp_Insert_Error_Log (
LS_OBJECT_NAME,
SYSDATE,
'OTHERS_6',
'WHEN OTHERS TRIGGERED' || '-' || SQLERRM
END;
LS_COMP_2 := LS_COMP_2 || '^' || LS_COMP_1;
LS_COMP_4 := LS_COMP_4 || '^' || LS_COMP_3;
END LOOP;user575115 wrote:
I'm using toad could you please advice how to use profiler .This link may help you,
http://www.toadworld.com/Default.aspx?tabid=67&EntryID=76
Twinkle -
Help! Changing attachment path in SQL database
Changing paths in the dbo.dlnk table isn't too difficult, but I came accross something that has me stumped.
Rather than a straight forward path such as \\servername\documents\ there are many that have a URL in the path such as http://servername/exponline/attachmentframe.jsp?filename=83089.pdf&fullpath=%5C%5Cservername%5Cimagetool%5Carchive%5Chce%5C78%5C83089.pdf&dk=h8Tjf4FcM7Km%2BpwH637w6w%3D%3D
Does anyone have a sql script that will filter out the url crud and leave a simple path.
You can see the path in there, it's \\servername\imagetool\archive\hce\78\5C83089.pdfSELECT SUBSTRING(REPLACE(SUBSTRING(@path,
PATINDEX('%fullpath=%', @path) + 9,
255), '%5c', '\'), 1,
PATINDEX('%&dk=%',
REPLACE(SUBSTRING(@path,
PATINDEX('%fullpath=%',
@path) + 9, 255),
'%5c', '\')) - 1) AS [absolute_path]
,[description]
,[master_key]
,[parent_key]
,[cr_external_key]
INTO #temp
FROM ATTACHMENT_PATHS
UPDATE attachment_paths
SET ATTACHMENT_PATHS.absolute_path = #temp.absolute_path
FROM ATTACHMENT_PATHS
INNER JOIN #temp ON ATTACHMENT_PATHS.master_key = #temp.master_key
WHERE ATTACHMENT_PATHS.absolute_path LIKE '%/exponloine/%' -
Is this a bug? What do I do?
Hi all,
I am running an update of a table with 2 columns from 9.2.0.8 to 8.1.7.4 over database link.
First column (number) is updated, but second appears to be NULL. ?!
I've tried to do it from 8.1.7 to 9.2, but with the same result.
Then I've tried to create a table on 8.1.7 side and insert data from 9.2 into it first, but .... same: NULL values for char colums.
Is it a bug?
What else can I try?
Thanks,
EugeneThanks all for replies.
This is the oddest thing and that is why I was asking you if it's a bug. It worked this time and you will laugh at me.
Here is what I've done:
============
9.2 DB
============
select * from v$version;
BANNER
Oracle9i Enterprise Edition Release 9.2.0.8.0 - Production
PL/SQL Release 9.2.0.8.0 - Production
CORE 9.2.0.8.0 Production
TNS for 32-bit Windows: Version 9.2.0.8.0 - Production
NLSRTL Version 9.2.0.8.0 - Production
desc macys_store_names;
Name Null? Type
PH00_PKT_CTL_NBR NOT NULL NUMBER(6)
STORE_NAME CHAR(25)
truncate table macys_store_names;
Table truncated.
select count(*) macys_rec_num
2 from phpick00@db817
3 where ph00_soldto like 'MACYS%'
4 and ph00_pkt_stat_flg = ' ';
MACYS_REC_NUM
1292
insert into macys_store_names
2 SELECT ph00_pkt_ctl_nbr,
3 substr(defa_cust_store_name,1,25) store_name
4 FROM sales_order A,
5 customer_store b,
6 (
7 select ph00_pkt_ctl_nbr,
8 '81' business_unit_id,
9 SUBSTR(ph00_order,1,1) sales_order_prefix,
10 LTRIM(SUBSTR(REPLACE((ph00_order||ph00_order_sfx),' ',''),2),0) sales_order_numb
er
11 from phpick00@db817
12 where ph00_soldto like 'MACYS%'
13 and ph00_pkt_stat_flg = ' '
14 ) c
15 WHERE A.business_unit_id = b.business_unit_id AND
16 A.customer_id = b.customer_id AND
17 A.customer_store_id = b.customer_store_id AND
18 a.business_unit_id = c.business_unit_id
19 and a.sales_order_prefix = c.sales_order_prefix
20 and a.sales_order_number = c.sales_order_number;
1292 rows created.
commit;
Commit complete.
select * from macys_store_names where rownum < 10;
PH00_PKT_CTL_NBR STORE_NAME
567384 Fort Steuben
567385 Fort Steuben
567386 Chesterfield MO
567387 Chesterfield MO
567388 Mid Rivers
567389 Mid Rivers
567390 White Oaks
567391 White Oaks
567392 Market Place IL
9 rows selected.
update phpick00@db817 a
2 set ph00_mark_for = (select store_name
3 from macys_store_names b
4 where a.ph00_pkt_ctl_nbr = b.ph00_pkt_ctl_nbr)
5 ,ph00_lm_user_id = 'MACYS_STOR'
6 ,ph00_dlm = sysdate
7 where ph00_pkt_ctl_nbr in
8 (select ph00_pkt_ctl_nbr from macys_store_names);
1292 rows updated.
commit;
============
8.1.7 DB
============
select * from v$version;
BANNER
Oracle8i Enterprise Edition Release 8.1.7.4.1 - Production
PL/SQL Release 8.1.7.4.0 - Production
CORE 8.1.7.2.1 Production
TNS for 32-bit Windows: Version 8.1.7.4.0 - Production
NLSRTL Version 3.4.1.0.0 - Production
select ph00_pkt_ctl_nbr, ph00_mark_for
2 from phpick00
3 where ph00_pkt_ctl_nbr in
4 (select ph00_pkt_ctl_nbr from macys_store_names@db92)
5 and rownum < 10
6 ;
PH00_PKT_CTL_NBR PH00_MARK_FOR
566781 Queens
566782 Queens
566783 Brooklyn
566784 Brooklyn
566785 Herald Square
566786 Herald Square
566787 Westfarms Mall
566788 Westfarms Mall
566789 Manhasset
9 rows selected.
Thanks,
Eugene
Edited by: epipko on Oct 19, 2009 10:40 AM
Edited by: epipko on Oct 19, 2009 10:44 AM -
Introduction to regular expressions ...
I'm well aware that there are already some articles on that topic, some people asked me to share some of my knowledge on this topic. Please take a look at this first part and let me know if you find this useful. If yes, I'm going to continue on writing more parts using more and more complicated expressions - if you have questions or problems that you think could be solved through regular expression, please post them.
Introduction
Oracle has always provided some character/string functions in its PL/SQL command set, such as SUBSTR, REPLACE or TRANSLATE. With 10g, Oracle finally gave us, the users, the developers and of course the DBAs regular expressions. However, regular expressions, due to their sometimes cryptic rules, seem to be overlooked quite often, despite the existence of some very interesing use cases. Beeing one of the advocates of regular expression, I thought I'll give the interested audience an introduction to these new functions in several installments.
Having fun with regular expressions - Part 1
Oracle offers the use of regular expression through several functions: REGEXP_INSTR, REGEXP_SUBSTR, REGEXP_REPLACE and REGEXP_LIKE. The second part of each function already gives away its purpose: INSTR for finding a position inside a string, SUBSTR for extracting a part of a string, REPLACE for replacing parts of a string. REGEXP_LIKE is a special case since it could be compared to the LIKE operator and is therefore usually used in comparisons like IF statements or WHERE clauses.
Regular expressions excel, in my opinion, in search and extraction of strings, using that for finding or replacing certain strings or check for certain formatting criterias. They're not very good at formatting strings itself, except for some special cases I'm going to demonstrate.
If you're not familiar with regular expression, you should take a look at the definition in Oracle's user guide Using Regular Expressions With Oracle Database, and please note that there have been some changes and advancements in 10g2. I'll provide examples, that should work on both versions.
Some of you probably already encountered this problem: checking a number inside a string, because, for whatever reason, a column was defined as VARCHAR2 and not as NUMBER as one would have expected.
Let's check for all rows where column col1 does NOT include an unsigned integer. I'll use this SELECT for demonstrating different values and search patterns:
WITH t AS (SELECT '456' col1
FROM dual
UNION
SELECT '123x'
FROM dual
UNION
SELECT 'x123'
FROM dual
UNION
SELECT 'y'
FROM dual
UNION
SELECT '+789'
FROM dual
UNION
SELECT '-789'
FROM dual
UNION
SELECT '159-'
FROM dual
UNION
SELECT '-1-'
FROM dual
SELECT t.col1
FROM t
WHERE NOT REGEXP_LIKE(t.col1, '^[0-9]+$')
;Let's take a look at the 2nd argument of this REGEXP function: '^[0-9]+$'. Translated it would mean: start at the beginning of the string, check if there's one or more characters in the range between '0' and '9' (also called a matching character list) until the end of this string. "^", "[", "]", "+", "$" are all Metacharacters.
To understand regular expressions, you have to "think" in regular expressions. Each regular expression tries to "fit" an available string into its pattern and returns a result beeing successful or not, depending on the function. The "art" of using regular expressions is to construct the right search pattern for a certain task. Using functions like TRANSLATE or REPLACE did already teach you using search patterns, regular expressions are just an extension to this paradigma. Another side note: most of the search patterns are placeholders for single characters, not strings.
I'll take this example a bit further. What would happen if we would remove the "$" in our example? "$" means: (until the) end of a string. Without this, this expression would only search digits from the beginning until it encounters either another character or the end of the string. So this time, '123x' would be removed from the SELECTION since it does fit into the pattern.
Another change: we will keep the "$" but remove the "^". This character has several meanings, but in this case it declares: (start from the) beginning of a string. Without it, the function will search for a part of a string that has only digits until the end of the searched string. 'x123' would now be removed from our selection.
Now there's a question: what happens if I remove both, "^" and "$"? Well, just think about it. We now ask to find any string that contains at least one or more digits, so both '123x' and 'x123' will not show up in the result.
So what if I want to look for signed integer, since "+" is also used for a search expression. Escaping is the name of the game. We'll just use '^\+[0-9]+$' Did you notice the "\" before the first "+"? This is now a search pattern for the plus sign.
Should signed integers include negative numbers as well? Of course they should, and I'll once again use a matching character list. In this list, I don't need to do escaping, although it is possible. The result string would now look like this: '^[+-]?[0-9]+$'. Did you notice the "?"? This is another metacharacter that changes the placeholder for plus and minus to an optional placeholder, which means: if there's a "+" or "-", that's ok, if there's none, that's also ok. Only if there's a different character, then again the search pattern will fail.
Addendum: From this on, I found a mistake in my examples. If you would have tested my old examples with test data that would have included multiple signs strings, like "--", "-+", "++", they would have been filtered by the SELECT statement. I mistakenly used the "*" instead of the "?" operator. The reason why this is a bad idea, can also be found in the user guide: the "*" meta character is defined as 0 to multiple occurrences.
Looking at the values, one could ask the question: what about the integers with a trailing sign? Quite simple, right? Let's just add another '[+-] and the search pattern would look like this: '^[+-]?[0-9]+[+-]?$'.
Wait a minute, what happened to the row with the column value "-1-"?
You probably already guessed it: the new pattern qualifies this one also as a valid string. I could now split this pattern into several conditions combined through a logical OR, but there's something even better: a logical OR inside the regular expression. It's symbol is "|", the pipe sign.
Changing the search pattern again to something like this '^[+-]?[0-9]+$|^[0-9]+[+-]?$' [1] would return now the "-1-" value. Do I have to duplicate the same elements like "^" and "$", what about more complicated, repeating elements in future examples? That's where subexpressions/grouping comes into play. If I want only certain parts of the search pattern using an OR operator, we can put those inside round brackets. '^([+-]?[0-9]+|[0-9]+[+-]?)$' serves the same purpose and allows for further checks without duplicating the whole pattern.
Now looking for integers is nice, but what about decimal numbers? Those may be a bit more complicated, but all I have to do is again to think in (meta) characters. I'll just use an example where the decimal point is represented by ".", which again needs escaping, since it's also the place holder in regular expressions for "any character".
Valid decimals in my example would be ".0", "0.0", "0.", "0" (integer of course) but not ".". If you want, you can test it with the TO_NUMBER function. Finding such an unsigned decimal number could then be formulated like this: from the beginning of a string we will either allow a decimal point plus any number of digits OR at least one digits plus an optional decimal point followed by optional any number of digits. Think about it for a minute, how would you formulate such a search pattern?
Compare your solution to this one:
'^(\.[0-9]+|[0-9]+(\.[0-9]*)?)$'
Addendum: Here I have to use both "?" and "*" to make sure, that I can have 0 to many digits after the decimal point, but only 0 to 1 occurrence of this substrings. Otherwise, strings like "1.9.9.9" would be possible, if I would write it like this:
'^(\.[0-9]+|[0-9]+(\.[0-9]*)*)$'Some of you now might say: Hey, what about signed decimal numbers? You could of course combine all the ideas so far and you will end up with a very long and almost unreadable search pattern, or you start combining several regular expression functions. Think about it: Why put all the search patterns into one function? Why not split those into several steps like "check for a valid decimal" and "check for sign".
I'll just use another SELECT to show what I want to do:
WITH t AS (SELECT '0' col1
FROM dual
UNION
SELECT '0.'
FROM dual
UNION
SELECT '.0'
FROM dual
UNION
SELECT '0.0'
FROM dual
UNION
SELECT '-1.0'
FROM dual
UNION
SELECT '.1-'
FROM dual
UNION
SELECT '.'
FROM dual
UNION
SELECT '-1.1-'
FROM dual
SELECT t.*
FROM t
;From this select, the only rows I need to find are those with the column values "." and "-1.1-". I'll start this with a check for valid signs. Since I want to combine this with the check for valid decimals, I'll first try to extract a substring with valid signs through the REGEXP_SUBSTR function:
NVL(REGEXP_SUBSTR(t.col1, '^([+-]?[^+-]+|[^+-]+[+-]?)$'), ' ')Remember the OR operator and the matching character collections? But several "^"? Some of the meta characters inside a search pattern can have different meanings, depending on their positions and combination with other meta characters. In this case, the pattern translates into: from the beginning of the string search for "+" or "-" followed by at least another character that is not "+" or "-". The second pattern after the "|" OR operator does the same for a sign at the end of the string.
This only checks for a sign but not if there also only digits and a decimal point inside the string. If the search string fails, for example when we have more than one sign like in the "-1.1-", the function returns NULL. NULL and LIKE don't go together very well, so we'll just add NVL with a default value that tells the LIKE to ignore this string, in this case a space.
All we have to do now is to combine the check for the sign and the check for a valid decimal number, but don't forget an option for the signs at the beginning or end of the string, otherwise your second check will fail on the signed decimals. Are you ready?
Does your solution look a bit like this?
WHERE NOT REGEXP_LIKE(NVL(REGEXP_SUBSTR(t.col1,
'^([+-]?[^+-]+|[^+-]+[+-]?)$'),
'^[+-]?(\.[0-9]+|[0-9]+(\.[0-9]*)?)[+-]?$'
)Now the optional sign checks in the REGEXP_LIKE argument can be added to both ends, since the SUBSTR won't allow any string with signs on both ends. Thinking in regular expression again.
Continued in Introduction to regular expressions ... continued.
C.
Fixed some embarrassing typos ... and mistakes.
cdExcellent write up CD. Very nice indeed. Hopefully you'll be completing parts 2 and 3 some time soon. And with any luck, your article will encourage others to do the same....I know there's a few I'd like to see and a few I'd like to have a go at writing too :-)
-
Issue with query for AR transactions posted to GL
Hi all,
I'm using Oracle R12.1.3.
I have a report similar to Account Analysis Report which displays Transactions posted to GL.
I have the following issue:
In the result of the report if an AR transaction has 2 lines or more I get multiplication of them. So my question is how can I identify which AR transaction line is linked to GL line number?
Here is my query:
SELECT DISTINCT GJH.JE_HEADER_ID,
GJL.JE_LINE_NUM,
PARTY.PARTY_NAME CUSTOMER_VENDOR,
RCT.TRX_NUMBER TRANS_NUMBER,
SUBSTR(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(SUBSTR(CTL.DESCRIPTION, 1, 2000), CHR(13), ''), CHR(10), ''), CHR(9), ''), CHR(11), ''), CHR(12), ''), 1, 100) DESCRIPTION,
NVL(xal.entered_dr, 0) - NVL(xal.entered_cr, 0) amount,
CTL.*
FROM GL.GL_JE_HEADERS GJH,
GL.GL_JE_LINES GJL,
GL.GL_CODE_COMBINATIONS GCC,
GL.GL_PERIODS GLP,
GL.GL_IMPORT_REFERENCES IMP,
XLA.XLA_AE_LINES XAL,
XLA.XLA_AE_HEADERS XAH,
XLA.XLA_EVENTS XE,
XLA.XLA_TRANSACTION_ENTITIES XTE,
RA_CUSTOMER_TRX_ALL RCT,
HZ_PARTIES PARTY,
AR.HZ_CUST_ACCOUNTS CA,
GL_CODE_COMBINATIONS_KFV CC,
AR.RA_CUSTOMER_TRX_LINES_ALL CTL,
AR.RA_CUST_TRX_LINE_GL_DIST_ALL CTLD
WHERE 1 = 1
AND GJH.JE_HEADER_ID = GJL.JE_HEADER_ID
-- AND GJL.STATUS || '' = 'P'
AND GCC.CODE_COMBINATION_ID = CTLD.CODE_COMBINATION_ID
AND GJH.PERIOD_NAME = GLP.PERIOD_NAME
AND RCT.CUSTOMER_TRX_ID = CTLD.CUSTOMER_TRX_ID
AND CTLD.CUSTOMER_TRX_LINE_ID = CTL.CUSTOMER_TRX_LINE_ID
AND ctld.customer_trx_id = RCT.CUSTOMER_TRX_ID
-- AND GLP.ADJUSTMENT_PERIOD_FLAG <> 'Y'
AND GJH.JE_SOURCE = 'Receivables'
AND GJL.JE_HEADER_ID = IMP.JE_HEADER_ID
AND GJL.JE_LINE_NUM = IMP.JE_LINE_NUM
AND IMP.GL_SL_LINK_ID = XAL.GL_SL_LINK_ID
AND IMP.GL_SL_LINK_TABLE = XAL.GL_SL_LINK_TABLE
AND XAL.APPLICATION_ID = XAH.APPLICATION_ID
AND XAL.AE_HEADER_ID = XAH.AE_HEADER_ID
AND XAH.APPLICATION_ID = XE.APPLICATION_ID
AND XAH.EVENT_ID = XE.EVENT_ID
AND XE.APPLICATION_ID = XTE.APPLICATION_ID
AND XTE.APPLICATION_ID = 222
AND XE.ENTITY_ID = XTE.ENTITY_ID
AND XTE.ENTITY_CODE = 'TRANSACTIONS'
AND XTE.SOURCE_ID_INT_1 = RCT.CUSTOMER_TRX_ID
AND RCT.BILL_TO_CUSTOMER_ID = CA.CUST_ACCOUNT_ID
AND CA.PARTY_ID = PARTY.PARTY_ID
AND rcT.CUSTOMER_TRX_ID = ctl.CUSTOMER_TRX_Id
AND CTL.LINE_TYPE = 'LINE'
AND XAL.CODE_COMBINATION_ID = CC.CODE_COMBINATION_ID
AND RCT.CUSTOMER_TRX_ID = 8857929
AND GJL.JE_LINE_NUM = 8866
Any ideas?
Thanks in advance,
Stoyanov.Hi Stoyanov,
Please try using the table xla_distribution_links to join with ra_cust_trx_line_gl_dist_all by using
xla_distribution_links.source_distribution_id_num_1 = ra_cust_trx_line_gl_dist_all.cust_trx_line_gl_dist_id
The below link gives the join conditions for various sub ledger types :
Techincal: R12 SLA Tables connection to AP, AR, INV,Payments, Receiving
Hope this helps.
Regards,
Manjusha.
Maybe you are looking for
-
Please Help, I just bought my IPhone 4s and set up icloud account, however my mac is still on OS 10.4 and I saw a thread that indicated that new 4s owners on icloud can get a free copy of the Upgrade cd for os 10.5. I can't even find how to buy the c
-
I've found two bugs in iOS 7: 1) declined calls does not appear as missed calls on the lock screen/notification centre - iOS 7.0.2. 2) when bluetooth is enabled from control center, it does not connect to an already paired bluetooth device automatica
-
How do I change the time format in the menu bar?
I've gone to system preferences - language - date and time, and customized the time for 24 hour time with no colon between HH and MM. The menu bar time display doesn't reflect this:-( There are some 5 year old posts about this not working, but nothi
-
PDF Conversion of Smartform Output
Hi All, Requirement : Be able to provide customers with reprinting old invoices. As Is : We have a standard way of doing it by reissuing a print of the Invoice by going into transaction VF02. But in doing so we have a chance that if some master data
-
CFIMAGE error "Numbers of source Raster bands and source color space components do not match"
I keep on getting this error when trying to upload a .JPG file. This error is not present for all jpegs, just for some of them. I am running CF 9 on a Windows 64-bit server. Any suggestions on how to modify cfimage tag or workaround this? Thank you!