473,320 Members | 1,831 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,320 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;
Jul 19 '05 #1
0 3437

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

Similar topics

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.*,...
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: 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: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.