Combining Text Rows together
-
CREATE OR REPLACE TYPE Robert AS TABLE OF VARCHAR2(4000);
-
SELECT last_name,
-
CAST(COLLECT(employee_number) as Robert) as Emp_Num
-
FROM per_all_people_f
-
where business_group_id = 101
-
and sysdate between effective_start_date and effective_end_date
-
and employee_number is not null
-
and last_name = 'Abdi'
Another Alternative
-
SELECT last_name,
-
count(*),
-
LTRIM(MAX(SYS_CONNECT_BY_PATH(employee_number,','))
-
KEEP (DENSE_RANK LAST ORDER BY curr),',') AS employees
-
FROM (SELECT last_name,
-
employee_number,
-
ROW_NUMBER() OVER (PARTITION BY last_name ORDER BY employee_number) AS curr,
-
ROW_NUMBER() OVER (PARTITION BY last_name ORDER BY employee_number) -1 AS prev
-
FROM per_all_people_f
-
where business_group_id = 101
-
and sysdate between effective_start_date and effective_end_date
-
and employee_number is not null
-
--AND LAST_NAME = 'Abdi'
-
)
-
GROUP BY last_name
-
CONNECT BY prev = PRIOR curr AND last_name = PRIOR last_name
-
START WITH curr = 1
Find if string is numeric
-
if nvl(LENGTH(TRIM(TRANSLATE(string1, ' +-.0123456789', ' '))),-1)=-1 then
-
c := to_number(string1);
-
end if;
Commit every X
The following code will execute a commit every 500 rows. (if l_num_items is the row counter)
-
--commit every x
-
if mod(l_num_items,500)=0 then
-
commit;
-
end if;
While Loop which times out
-
set serveroutput on
-
declare
-
l_startTime TIMESTAMP;
-
l_timeElapsed INTERVAL DAY(3) TO SECOND(3);
-
l_intervalToWait INTERVAL DAY(3) TO SECOND(3) := INTERVAL '6' SECOND;
-
begin
-
dbms_output.put_line('Start');
-
-
l_startTime := SYSTIMESTAMP;
-
dbms_output.put_line('Set start time to: ' || to_char(l_startTime));
-
-
while true
-
LOOP
-
l_timeElapsed := SYSTIMESTAMP - l_startTime;
-
-
if l_timeElapsed>l_intervalToWait then
-
exit;
-
end if;
-
END LOOP;
-
dbmS_output.put_line(l_timeElapsed);
-
-
-
dbms_output.put_line(EXTRACT(DAY FROM l_timeElapsed) || ' days');
-
dbms_output.put_line(EXTRACT(HOUR FROM l_timeElapsed) || ' hours');
-
dbms_output.put_line(EXTRACT(MINUTE FROM l_timeElapsed) || ' minutes');
-
dbms_output.put_line(EXTRACT(SECOND FROM l_timeElapsed) || ' seconds');
-
-
-
dbms_output.put_line('End');
-
end;
Record Type Syntax
Record structure
-
TYPE Pack_Item IS Record (
-
xMode varchar2(255), final_file_name varchar2(2048),
-
file_handle UTL_FILE.FILE_TYPE, d Pack_Item_Data
-
);
-
Type Pack_Item_tab IS TABLE OF Pack_Item INDEX BY PLS_INTEGER;
-
set serveroutput on;
-
declare
-
TYPE xref_Item IS RECORD (
-
xref_table_name VARCHAR2(255),
-
ebiz_seq VARCHAR2(255),
-
ebiz_table_name VARCHAR2(255)
-
);
-
TYPE xref_Item_tab IS TABLE OF xref_Item INDEX BY PLS_INTEGER;
-
dat xref_Item_tab;
-
l_c pls_integer;
-
begin
-
dbms_output.put_line('--Start');
-
-
dat(0).xref_table_name := 'XREF_CUSTOMERPARTY_ACCTID';
-
dat(0).ebiz_seq := 'ff';
-
dat(0).ebiz_table_name := 'ff';
-
-
l_c := dat.FIRST;
-
while (l_c is not null)
-
loop
-
dbms_output.put_line(dat(l_c).xref_table_name);
-
l_c := dat.NEXT(l_c);
-
END LOOP;
RJM Article Type
Quick Reference