473,396 Members | 2,099 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Help to optimize procedure (concatenation of rows)

Hi,

I need to concatenate rows with description of account branch into one
column.

Example:
I have created temporary table to retrieve client and branches for his
accounts.(5 mil. rows)

CUS_NO MSP_ID MSP_DESC
5072130 2112 MsP Bratislava
5072130 2182 MsP Poprad

I would like to concatenate msp_desc into one row so the result will
look like this.

CUS_NO MSP_ID MSP_DESC
5072130 2112 MsP Bratislava :: MsP Poprad

I have created this procedure to perform the challenge. The procedure
is using 2 cursors. 1. cursor retrieves customer number and passes
customer number to 2. cursor. 2. cursor retrieves branches for a
customer and concatenates the branches. Concatenated values are passed
to variable. Then I insert customer number, name .... and variable
with concatenated branches. Its working but, its running toooo long (2
days). I would appreciate ideas to improve performance. I think the
problem is that I open second cursor for each customer.
Many thanks

Juraj
DECLARE
type mycur is ref cursor;
L_TNAME VARCHAR2(30) DEFAULT 'temp_table_' ||
USERENV('sessionid');
V_UCET_MSP VARCHAR2(200);
CURSOR C1 IS(
SELECT CUS.CUS_NO, CUS.LOB_ID, CUS.NAME, CUS.TAXIDNO,
CUS.AS_OF_DATE
FROM CUSTOMER CUS
WHERE CUS_NO IN (SELECT CUS_NO FROM ACCT)

);
c2 mycur;
v_msp_desc varchar2(300);
i INTEGER;
BEGIN
--create temporary table with client info and branches
EXECUTE IMMEDIATE 'create global temporary table ' || L_TNAME ||
' on commit delete rows
as
SELECT DISTINCT CUS.CUS_NO, ORG.MSP_ID,
ORG.MSP_DESC
FROM CUSTOMER CUS, ACCT A, ICARUS.ORG_HIER_TMP ORG
WHERE 1=0';
--fill temporary table
EXECUTE IMMEDIATE 'insert into ' || L_TNAME ||
' SELECT DISTINCT CUS.CUS_NO, ORG.MSP_ID,
ORG.MSP_DESC
FROM CUSTOMER CUS, ACCT A, ICARUS.ORG_HIER_TMP
ORG
WHERE CUS.CUS_NO = A.CUS_NO AND A.ORG_UNIT_ID = ORG.LEAF_NODE';

--delete target table
DELETE FROM ICARUS.CUSTOMER;
--insert into target table
FOR C1_REC IN C1 LOOP
OPEN c2 FOR 'select msp_desc from ' || l_tname || ' where cus_no =
'||c1_rec.cus_no|| '';
LOOP
FETCH c2 INTO v_msp_desc;
exit when c2%notfound;
V_UCET_MSP := V_UCET_MSP || ' :: ' || v_msp_desc;
END LOOP;
CLOSE c2;
INSERT INTO ICARUS.CUSTOMER
VALUES
(C1_REC.CUS_NO,
C1_REC.LOB_ID,
C1_REC.NAME,
C1_REC.TAXIDNO,
V_UCET_MSP,
C1_REC.AS_OF_DATE);
V_UCET_MSP := NULL;
I := I+1;
END LOOP;
DBMS_OUTPUT.PUT_LINE('Processed rows: ' || I);
EXECUTE IMMEDIATE 'drop table ' || L_TNAME ||'';
COMMIT;
END;
Jun 27 '08 #1
0 1064

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Juraj Longauer | last post by:
Hi, I need to concatenate rows with description of account branch into one column. Example: I have created temporary table to retrieve client and branches for his accounts.(5 mil. rows) ...
0
by: rg | last post by:
Hello, I use invisionboard on a bid web site (20 000 visitors each day) But my server has high load average. Could you help me to optimize these select command. 1) SELECT p.*,...
0
by: Andreas Falck | last post by:
Hi, I ran the code below on two different versions, 4.0.14 and 4.0.16 respectively, both running RH 7.3 on intel. In version mysql server version 4.0.14 the SELECT privelege suffices for...
4
by: mjuricek | last post by:
I'm having some problems to optimize my stored procedure (select statement with joins) What I'm trying to do is calculate total work. My situation: I have 3 tables I'm using -Input (char...
9
by: Rune | last post by:
Is it best to use double quotes and let PHP expand variables inside strings, or is it faster to do the string manipulation yourself manually? Which is quicker? 1) $insert = 'To Be';...
2
by: Jusan | last post by:
hi, I have written a cheque writing utility in vb.net and would like to invite comments on the code. can this be done in a better / faster / shorter way? thnx Public Class...
6
by: Robin Tucker | last post by:
I have a slight bottleneck in my code, the simplicity of which leads me to believe it is either insurmountable, or easily speeded up. I have an ArrayList of numbers (integers, which are in fact...
3
by: david | last post by:
I have trouble with it. I have created a sproc in SQL Server, called SearchClass, which returns a searched key from a table. I have tested this procedure in Analyzer and it works fine. However,...
15
by: Jay | last post by:
I have a multi threaded VB.NET application (4 threads) that I use to send text messages to many, many employees via system.timer at a 5 second interval. Basically, I look in a SQL table (queue) to...
4
by: Hemant Shah | last post by:
Folks, I am having problem with an application that uses static SQL, the application basically browses through the table given start and end key most of the time it is processed from begining to...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.