2012-12-19 19 views
7

एकत्रित मैं एक एक्सेल कॉलम के साथ फाइल मिल गया है,एक्सेल समारोह

C_IP 
SESSION_ID 
CS_USER_AGENT 
CS_URI_STEM 
CS_URI_QUERY 
WEB_LINK 

मैं स्ट्रिंग आकार ओरेकल (11g) में अनुमति की सीमाओं के कारण ऊपर विशेषताओं कुल करने में सक्षम नहीं हूँ। मैंने उपयोगकर्ता द्वारा परिभाषित समेकित फ़ंक्शन का उपयोग करने का प्रयास किया। मैं "WEB_LINK" कॉलम और C_IP द्वारा समूह को एकत्र करना चाहता हूं। क्या एक्सेल में ऐसा करना संभव है?

SQL क्वेरी मैं उपयोग करने का प्रयास किया गया था,

CREATE TABLE WEBLOG_AGG AS 
SELECT C_IP, 
tab_to_string(CAST(COLLECT(WEB_LINK) AS T_VARCHAR2_TAB)) AS WEBLINKS 
FROM WEBLOG_SESSION 
GROUP BY C_IP; 

उत्तर

2

जब तक मैं इस सवाल में इसे देखा मैं भी COLLECT() समारोह की प्रतिक्रिया नहीं मिली है, लेकिन यह बहुत ही उपयोगी लग रहा है। मैंने जो पढ़ा है, उसके आधार पर, मुझे लगता है कि वेब_लिंक कॉलम को एकत्र करते समय निम्नलिखित को आपकी एक्सेल वर्कशीट को अद्वितीय पंक्तियों में कम करना चाहिए। यह फ्लाई पर ऐसा नहीं करेगा (जो हो सकता है कि आप जो खोज रहे हों) लेकिन जब डेटा वहां होता है तो आप इसे पूरी शीट पर चला सकते हैं।

Public Type Entry 
    C_IP As String 
    rowNum As Integer 
End Type 

Public entryList() As Entry 

Sub AggregateRows() 

    Dim lastRow As Integer 
    Dim i As Integer 
    Dim webLinks As String 
    Dim entryItem As Entry 
    Const C_IPColumn As Integer = 1   ' This is the column number of the C_IP column 
    Const WEB_LINKColumn As Integer = 6  ' This is the column number of the WEB_LINK column 

    ReDim entryList(0) 

    ' Get the last used row on the sheet 

    lastRow = ActiveSheet.Cells.Find("*", SearchOrder:=xlByRows, LookIn:=xlValues, SearchDirection:=xlPrevious).Row 

    ' Loop through all of the rows 

    For i = 1 To lastRow 

     ' See if we've already encountered the C_IP in this row 

     entryItem = GetEntry(ActiveSheet.Cells(i, C_IPColumn).Value) 

     If Not entryItem.C_IP = "" Then 

      ' We have, so add the current web link to the list for the row associated with this C_IP 

      webLinks = ActiveSheet.Cells(entryItem.rowNum, WEB_LINKColumn).Value 
      webLinks = webLinks & ", " & ActiveSheet.Cells(i, WEB_LINKColumn).Value 
      ActiveSheet.Cells(entryItem.rowNum, WEB_LINKColumn).Value = webLinks 

      ' Now remove this row (since it has been grouped with row with the same C_IP) 

      ActiveSheet.Rows(i).Delete 

      ' Decrement our counters by 1 since we have 1 fewer rows (assuming we're not on the last row already) 

      If Not i = lastRow Then 

       i = i - 1 
       lastRow = lastRow - 1 

      End If 

     Else 

      ' We've not encountered this C_IP yet, so add it to the list 

      ReDim Preserve entryList(UBound(entryList) + 1) 
      entryList(UBound(entryList)).C_IP = ActiveSheet.Cells(i, C_IPColumn).Value 
      entryList(UBound(entryList)).rowNum = i 

     End If 

    Next i 

End Sub 

' Returns the Entry matching the passed-in C_IP 
Function GetEntry(C_IP As String) As Entry 

    Dim i As Integer 

    ' Loop through all stored entries and return the first whose C_IP matches that passed in 

    For i = 0 To UBound(entryList) 
     If entryList(i).C_IP = C_IP Then 
      GetEntry = entryList(i) 
     End If 
    Next i 

End Function 

' A quick and dirty way to get an empty Entry 
Function GetEmptyEntry() As Entry 

End Function 
3

मुझे लगता है कि यह clob में संयोजन प्रदर्शन करने के लिए VBA कोड लिखने के लिए की तुलना में आसान हो जाएगा।

15:34:36 [email protected]> create table t1 (group_col number, value varchar2(1 byte)); 

Table created. 

Elapsed: 00:00:00.10 
15:34:38 [email protected]> insert into t1 
15:35:34 2 select 1, decode(mod(rownum,5), 0,0,1) from dual connect by rownum <= 4001 
15:36:20 3 union all 
15:36:22 4 select 2, decode(mod(rownum,5), 0,0,1) from dual connect by rownum <= 4001 
15:36:27 5 ; 

8002 rows created. 

Elapsed: 00:00:00.05 
15:36:28 [email protected]> commit; 

Commit complete. 

Elapsed: 00:00:00.02 
15:36:31 [email protected]> create type t_varchar2_tab is table of varchar2(1); 
15:37:11 2/

Type created. 

Elapsed: 00:00:00.50 
15:38:15 [email protected]> ed 
Wrote file S:\tools\buffer.sql 

    1 create function tab_to_str(tab in t_varchar2_tab) return clob 
    2 as 
    3 result clob; 
    4 begin 
    5 for i in tab.first .. tab.last loop 
    6  result := result || tab(i); 
    7 end loop; 
    8 return result; 
    9* end; 
15:38:46 [email protected]>/

Function created. 

Elapsed: 00:00:00.19 
15:46:01 [email protected]> select group_col 
15:46:04 2 ,length(tab_to_str(cast(collect(value) as t_varchar2_tab))) len 
15:46:10 3 ,substr(tab_to_str(cast(collect(value) as t_varchar2_tab)), 1, 20) val 
15:46:12 4 from t1 group by group_col; 

GROUP_COL LEN VAL 
---------- ------ -------------------- 
     1 4001 11011110111101111011 
     2 4001 11011110111101111011 

Elapsed: 00:00:01.13