Distinct Values on column ov NVARCHAR2 Type

Hi,
I have a Table with a Nvarchar2(255) Column on a 10.2.0.4 Database.
I collected statistics on the table on different ways, with and without histograms. I know the table has about 65.000 distinct values, but dba_tab_col_statistics always shows 10 Rows.
For a test I created a new column of type varchar2(255) and copied the data from the nvarchar2 in the varchar2 column. Again i collected statistics, and for the varchar2 column it shows the correct value.
any ideas ?
Regards
PK
Here some more data:
select count(distinct(REPOSID_XMETA)) from tmp;COUNT(DISTINCT(REPOSID_XMETA))
63933
alter table tmp add tmp_col varchar2(255);Table altered.
>desc tmp
Name Null? Type
REPOSID_XMETA NVARCHAR2(255)
TMP_COL VARCHAR2(255)
update tmp set tmp_col = REPOSID_XMETA;63933 rows updated.
commit;Commit complete.
create index tmp_index1 on tmp (REPOSID_XMETA);Index created.
create index tmp_index2 on tmp (tmp_col);Index created.
begin
dbms_stats.gather_table_stats(
ownname=> 'SYS',
tabname=> 'TMP' ,
estimate_percent=> null,
cascade=> TRUE,
degree=> 4,
no_invalidate=> FALSE,
granularity=> 'AUTO',
method_opt=> 'FOR ALL INDEXED COLUMNS');
end; /
select COLUMN_NAME, NUM_DISTINCT, DENSITY, NUM_NULLS, NUM_BUCKETS from dba_tab_col_statistics where table_name = 'TMP2';Column Distinct
Name Values Density NUM_NULLS NUM_BUCKETS
REPOSID_XMETA 10 0 0 10
TMP_COL 63,933 0 0 75
Edited by: user1131374 on Jul 1, 2011 5:27 AM

Sorry, wrong cut and paste. TMP2 is a copy of TMP. Nethertheless, same query on TMP shows same results:
select COLUMN_NAME, NUM_DISTINCT, DENSITY, NUM_NULLS, NUM_BUCKETS from dba_tab_col_statistics where table_name = 'TMP';COLUMN_NAME NUM_DISTINCT DENSITY NUM_NULLS NUM_BUCKETS
REPOSID_XMETA 10 7.8207E-06 0 10
TMP_COL 63933 .000015641 0 75
regards
Paolo

Similar Messages

  • CE function to get distinct values from Column table

    Hi All,
    Could you please let me know the appropriate CE function to get the distinct values from column table.
    IT_WORK = SELECT DISTINCT AUFNR FROM :IT_WO_DETAILS;
    Thank you.

    Hi,
    If you have 10g, you can use Model( with model performance is better than connect by )
    Solution
    ========================================================================
    WITH t AS
    (SELECT '0989.726332, 1234.567432, 3453.736379, 3453.736379, 0989.726332, 3453.736379, 1234.567432, 1234.567432, 0989.726332'
    txt
    FROM DUAL)
    SELECT DISTINCT TRIM(CHAINE)
    FROM T
    MODEL
    RETURN UPDATED ROWS
    DIMENSION BY (0 POSITION)
    MEASURES (CAST( ' ' AS VARCHAR2(50)) AS CHAINE ,txt ,LENGTH(REGEXP_REPLACE(txt,'[^,]+',''))+1 NB_MOT)
    RULES
    (CHAINE[FOR POSITION FROM  1 TO NVL(NB_MOT[0],1) INCREMENT 1] =
    CASE WHEN NB_MOT[0] IS NULL THEN TXT[0] ELSE REGEXP_SUBSTR(txt[0],'[^,]+',1,CV(POSITION)) END );
    =========================================================================
    Demo
    =======================================================================
    SQL> WITH t AS
    2 (SELECT '0989.726332, 1234.567432, 3453.736379, 3453.736379, 0989.726332, 3453.736379, 123
    4.567432, 1234.567432, 0989.726332'
    3 txt
    4 FROM DUAL)
    5 SELECT DISTINCT TRIM(CHAINE)
    6 FROM T
    7 MODEL
    8 RETURN UPDATED ROWS
    9 DIMENSION BY (0 POSITION)
    10 MEASURES (CAST( ' ' AS VARCHAR2(50)) AS CHAINE ,txt ,LENGTH(REGEXP_REPLACE(txt,'[^,]+',''))+1 NB_MOT)
    11 RULES
    12 (CHAINE[FOR POSITION FROM  1 TO NVL(NB_MOT[0],1) INCREMENT 1] =
    13 CASE WHEN NB_MOT[0] IS NULL THEN TXT[0] ELSE REGEXP_SUBSTR(txt[0],'[^,]+',1,CV(POSITION)) END );
    TRIM(CHAINE)
    3453.736379
    1234.567432
    0989.726332
    SQL>
    ========================================================================

  • Select records based on first n distinct values of column

    I need to write a query in plsql to select records for first 3 distinct values of a single column (below example, ID )and all the rows for next 3 distinct values of the column and so on till the end of count of distinct values of a column.
    eg:
    ID name age
    1 abc 10
    1 def 20
    2 ghi 10
    2 jkl 20
    2 mno 60
    3 pqr 10
    4 rst 10
    4 tuv 10
    5 vwx 10
    6 xyz 10
    6 hij 10
    7 lmn 10
    so on... (till some count)
    Result should be
    Query 1 should result --->
    ID name age
    1 abc 10
    1 def 20
    2 ghi 10
    2 jkl 20
    2 mno 60
    3 pqr 10
    query 2 should result -->
    4 rst 10
    4 tuv 10
    5 vwx 10
    6 xyz 10
    6 hij 10
    query 3 should result -->
    7 lmn 10
    9 .. ..
    so on..
    How to write a query for this inside a loop.

    Hi,
    So, one group will consist of the lowest id value, the 2nd lowest and the 3rd lowest, reggardless of how many rows are involved. The next group will consist of the 4th lowest id, the 5th lowest and the 6th lowest. To do that, you need to assign numbers 1, 2, 3, 4, 5, 6, ... to the rows in order by id, with all rows having the same id getting the same number, and without skipping any numbers.
    That sounds like a job for the analytic DENSE_RANK function:
    WITH     got_grp_id     AS
         SELECT     id, name, age
         ,     CEIL ( DENSE_RANK () OVER (ORDER BY id)
                   / 3
                   )          AS grp_id
         FROM     table_x
    SELECT     id, name, age
    FROM     got_grp_id
    WHERE     id     = 1     -- or whatever number you want
    ;If you'd care to post CREATE TABLE and INSERT statements for your sample data, then I could test it.
    See the forum FAQ {message:id=9360002}

  • Sum rows of Column A based on distinct values of Column B

    Hello everyone,
    below is my xml
    <ROWSET>
    <ROW>
    <ORDER_NO>103-4385509</ORDER_NO>
    <SITE_NO>103</SITE_NO>
    <ORDER_ID>4385509</ORDER_ID>
    <CUSTOMER_ID>2676832</CUSTOMER_ID>
    <TAX_AMOUNT>.33</TAX_AMOUNT>
    <CREATED_DATE>08/20/2010</CREATED_DATE>
    <USER_CREATED>TSDAL671</USER_CREATED>
    <Delivery_Method>CARRY OUT STORE</Delivery_Method>
    <Entered_By>TSDAL671</Entered_By>
    <SKU_NO>321182</SKU_NO>
    <NAME_TEXT>MGR_OVERRIDE</NAME_TEXT>
    <ATTRIBUTE_ID>319</ATTRIBUTE_ID>
    <ATTRIBUTE_VALUE>Override Done</ATTRIBUTE_VALUE>
    <DETAIL_SEQ_NO>1</DETAIL_SEQ_NO>
    </ROW>
    <ROW>
    <ORDER_NO>103-4385509</ORDER_NO>
    <SITE_NO>103</SITE_NO>
    <ORDER_ID>4385509</ORDER_ID>
    <CUSTOMER_ID>2676832</CUSTOMER_ID>
    <TAX_AMOUNT>.33</TAX_AMOUNT>
    <CREATED_DATE>08/20/2010</CREATED_DATE>
    <USER_CREATED>TSDAL671</USER_CREATED>
    <Delivery_Method>CARRY OUT STORE</Delivery_Method>
    <Entered_By>TSDAL671</Entered_By>
    <SKU_NO>321182</SKU_NO>
    <NAME_TEXT>OEDTL_TAX_INFO</NAME_TEXT>
    <ATTRIBUTE_ID>314</ATTRIBUTE_ID>
    <ATTRIBUTE_VALUE>441130760|441130760|441130760|1|1|1|20100820|2676832|2|SPARTS|</ATTRIBUTE_VALUE>
    <DETAIL_SEQ_NO>1</DETAIL_SEQ_NO>
    </ROW>
    <ROW>
    <ORDER_NO>103-4385509</ORDER_NO>
    <SITE_NO>103</SITE_NO>
    <ORDER_ID>4385509</ORDER_ID>
    <CUSTOMER_ID>2676832</CUSTOMER_ID>
    <TAX_AMOUNT>.18</TAX_AMOUNT>
    <CREATED_DATE>08/20/2010</CREATED_DATE>
    <USER_CREATED>TSDAL671</USER_CREATED>
    <Delivery_Method>CARRY OUT STORE</Delivery_Method>
    <Entered_By>TSDAL671</Entered_By>
    <SKU_NO>412679</SKU_NO>
    <NAME_TEXT>OEDTL_TAX_INFO</NAME_TEXT>
    <ATTRIBUTE_ID>314</ATTRIBUTE_ID>
    <ATTRIBUTE_VALUE>441130760|441130760|441130760|1|1|1|20100820|2676832|2|0035|</ATTRIBUTE_VALUE>
    <DETAIL_SEQ_NO>2</DETAIL_SEQ_NO>
    </ROW>
    i have to display 3 rows but while doing sum of TAX_AMOUNT grouped by ORDER_ID, i need to sum only for 2 records based on the distinct value of DETAIL_SEQ
    so my output should be some thing like below
    ORDER_ID|TAX_AMOUNT|DETAIL_SEQ|ATTRIBUTE_ID
    4385509|0.33|1|319
    4385509|0.33|1|314
    4385509|0.18|2|314
    SUM = 0.51
    Note : i cannot do distinct in the sql becuase attribute_id is different for same DETAIL_SEQ_NO.
    I tired doing <?sum([xdoxslt:distinct_values(current-group()/DETAIL_SEQ_NO)]/TAX_AMOUNT)?>
    it didn't work.
    Can anyone please help me!!
    Thanks in Advance!!

    That syntax wont work.
    One method of doing.
    <?for-each-group:/ROWSET/ROW;ORDER_NO?>
    <?for-each:current-group()?>
    <?ORDER_NO?>  <?TAX_AMOUNT?>  <?DETAIL_SEQ?>  <?ATTRIBUTE_ID?>
    <?end for-each?> <?xdoxslt:set_variable($_XDOCTX,'sum_attr',0)?>
    <?for-each-group:current-group();DETAIL_SEQ_NO?>
    <?xdoxslt:set_variable($_XDOCTX,'sum_attr', xdoxslt:get_variable($_XDOCTX,'sum_attr')+ TAX_AMOUNT)?>
    <?end for-each?><?xdoxslt:get_variable($_XDOCTX,'sum_attr')?>
    <?end for-each?>

  • Calculating sum of distinct values

    Hello,
    I have a table with columns
    U1,U2,U3 of type VARCHAR2 and other columns as UQ1,UQ2,UQ3 as NUMBER
    I need to find out the sum of UQ1,UQ2,UQ3 column for the distinct value in U1,U2,U3 columns.
    Can we construct a sql statement to achive this?
    Cheers

    My apology, I actually didn't explained my problem properly. its infact is as following
    the table has columns U1,U2,U3 of type VARCHAR2 and other columns as UQ1,UQ2,UQ3 as NUMBER
    and i need to obtain the sum UQ1,UQ2,UQ3 for distinct values in column U1,U2,U3
    the column UQ1 hold the value for item in column U1
    and column UQ2 hold the value for item in column U2
    and column UQ3 hold the value for item in column U3
    So there could be a instance where columns U1,U2,U3 may contains the same item but difference values in columns UQ1,UQ2,UQ3 i.e.
    u1 = 'A' and uq1 = 1
    u2 = 'B' and uq2 = 4
    u3 = 'A' and uq3 = 6
    the result should be
    A, 7
    B, 4
    Can we achive this through simple construct?

  • "How to get distinct values of sharepoint column using SSRS"

    Hi,
        I have integrated sharepoint list data to SQL Server reporting services. I am using the below to query sharepoint list data using sql reporting services.
    <Query>
       <SoapAction>http://schemas.microsoft.com/sharepoint/soap/GetListItems</SoapAction>
       <Method Namespace="http://schemas.microsoft.com/sharepoint/soap/" Name="GetListItems">
          <Parameters>
             <Parameter Name="listName">
                <DefaultValue>{GUID of list}</DefaultValue>
             </Parameter>
             <Parameter Name="viewName">
                <DefaultValue>{GUID of listview}</DefaultValue>
             </Parameter>
             <Parameter Name="rowLimit">
                <DefaultValue>9999</DefaultValue>
             </Parameter>           
          </Parameters>
       </Method>  
    <ElementPath IgnoreNamespaces="True">*</ElementPath>
    </Query>
    By using this query, I am getting a dataset which includes all the columns of sharepoint list. Among these columns, I wanted to display only 2 columns (i.e Region and Sales type) using chart. I have created a Region parameter but when I click preview, the drop down box is giving me all the repeatative values of region like RG1,RG1,RG1,RG2,RG2,RG2,RG2,RG3.......... I wanted to display only distinct values of Region parameter so that whenever end user select region from the parameter drop down, it will display the respective value of Sales type column.
    Also when I select only RG1 parameter, it is giving me a chart including the sales type of all the Regions. (it should display me only the sales type of RG1) How can I link these 2 columns so that they will display the values respectively.
              I would really appreciate if anyone can help me out with this.
    Thanks,
    Sam.

    Hi Sam,
    By code, the CAML language doesn’t have any reserved word (or tag) to set this particular filter to remove duplicate results.
    In this case, we could use the custom code to get distinct records.
    Here are the detailed steps:
    1.         Create a hidden parameter that gets all the records in one field.
    Note: Please create another dataset that is same of the main dataset. This dataset is used for the parameter.
    2.         Create a function that used to remove the duplicate records.
    Here is the code:
    Public Shared Function RemoveDups(ByVal items As String) As String
    Dim noDups As New System.Collections.ArrayList()
    Dim SpStr
    SpStr = Split(items ,",")
    For i As Integer=0 To Ubound(Spstr)
    If Not noDups.Contains(SpStr(i).Trim()) Then
    noDups.Add(SpStr(i).Trim())
    End If
    Next
    Dim uniqueItems As String() = New String(noDups.Count-1){}
    noDups.CopyTo(uniqueItems)
    Return String.Join(",", uniqueItems)
    End Function
    3.         Create another parameter that will be used for filtering the maindata.
    Please set the available value to be =Split(Code.RemoveDups(JOIN(Parameters!ISSUE_STATUS_TEMP.Value, ",")), ",")
    And the default value to be the value you what such as the first value:
    =Split(Code.RemoveDups(JOIN(Parameters!ISSUE_STATUS_TEMP.Value, ",")), ",").(0)
    4.         Go to the main dataset. Open the property window of this dataset.
    5.         In the “Filters” tab, set the filter to be:
    Expression: <The field to be filter>
    Operator: =
    Value: =Parameters!Region.Value
    The parameter “Region” should be the parameter we created in the step3.
    Now, we should get distinct values of SharePoint columns.
    If there is anything unclear, please feel free to ask.
    Thanks,
    Jin
    Jin Chen - MSFT

  • OBI columns not showing distinct values.

    Hi,
    Please help me out with the below issue.
    I have a colulmn called Product Type. Same column is been pulled into many subject areas. In one of the subject area the column when checked for all product types, it is not showing distinct values, instead it displays multiple rows of sinlge value. Whereas in other subject areas it dsiplays distinct values.
    So please help me out on this issue.
    Thanks,
    Rajesh S

    Hi,
    I don't think it's not an issue with not selecting "Select Distinct Value" checkbox .. because same column pulled into to other subject areas working fine. But here also sometimes it shows correct distinct value and sometimes all values(Duplicate values).
    Thanks,
    Rajesh.

  • Count number of distinct values for a column for all tables that contains that column

    Imagine I have one Column called cdperson. With the query below I know which Tables have column cdperson
    select
    t.[name]fromsys.schemassinnerjoin 
    sys.tables 
    tons.schema_id=t.schema_idinnerjoin 
    sys.columnscont.object_id=c.object_idinnerjoin 
    sys.types  
    donc.user_type_id=d.user_type_idwherec.name ='cdperson'
    now I want to know for each table, how many distinct values of cdperson I have and I want the result ordered by the table that has more distinct values (descending)
    Table1                                                                                     
       cdperson                        select distinct(cdperson) = 10
       cdadress
       quant
    Table2 with 
       cdaddress                      (no column cdperson in this table)
       quant
    Table3
       cdperson                        select distinct(cdperson) = 100
       value
    Table 4
       cdperson                        select distinct(cdperson) = 18
       sum
    I want this result ordered by number of distinct cdperson
    table3   100
    table4   18
    table    10
    Thks for your answers

    I had to add schema name to the above script to make it work in AdventureWorks:
    CREATE TABLE #temp(TableName sysname , CNT BIGINT)
    DECLARE @QRY NVARCHAR(MAX);
    SET @qry=(SELECT
    N'INSERT INTO #TEMP SELECT '''+schema_name(t.schema_id)+'.'+T.[name] +''' AS TableName, COUNT (DISTINCT ProductID) DistCount FROM '+
    schema_name(t.schema_id)+'.'+t.[name] +';'
    FROM sys.schemas s INNER JOIN sys.tables t ON s.schema_id=t.SCHEMA_ID
    INNER JOIN sys.columns c ON t.object_id=c.object_id INNER JOIN sys.types d ON c.user_type_id=d.user_type_id
    WHERE c.name ='ProductID'
    FOR XML PATH(''))
    EXEC(@QRY)
    SELECT * FROM #temp ORDER BY TableName
    DROP TABLE #temp
    Production.Product 504
    Production.ProductCostHistory 293
    Production.ProductDocument 31
    Production.ProductInventory 432
    Production.ProductListPriceHistory 293
    Production.ProductProductPhoto 504
    Production.ProductReview 3
    Production.TransactionHistory 441
    Production.TransactionHistoryArchive 497
    Production.WorkOrder 238
    Production.WorkOrderRouting 149
    Purchasing.ProductVendor 211
    Purchasing.PurchaseOrderDetail 211
    Sales.SalesOrderDetail 266
    Sales.ShoppingCartItem 3
    Sales.SpecialOfferProduct 295
    Kalman Toth Database & OLAP Architect
    SQL Server 2014 Database Design
    New Book / Kindle: Beginner Database Design & SQL Programming Using Microsoft SQL Server 2014

  • Sorting a column does not result in distinct values on Dashboard prompts

    Hi,
    We have a period column, the records of which are 'JAN-02' , "FEB-02"...."DEC-09". We need sort this column in descending order in Dashboard Prompts. We have another column "Date", which has been used to sort the period column. To achieve this in descending order, we have converted Show Results from “All Values” to “SQL Results” in dashboard prmpts, then entered the below sql.
    SELECT "CODE COMBINATIONS"."LINE AC PERIOD" FROM INVOICE_PAYMENTS
    order by "CODE COMBINATIONS"."LINE AC DATE" desc
    The above sql resulted in non-distinct values as below. Using distinct in the above sql throws syntax error.
    Period
    JAN-09
    JAN-09
    JAN-09
    FEB-09
    FEB-09
    How do we get distinct values and in descending order??
    Thanks and appreciate any ideas
    Surya

    Go to advanced tab and check "Use distinct clause" that will fire a distinct to the query.
    In the rpd month logical column , there is an option called sort order in the general properties and you need to specify the date column if you need to sort it based on the date column and in the Answers you can simply enable Descending sort order on the same column. That should take care of it
    Hope it helps
    Thanks
    Prash

  • Distinct values in each column

    Hi
    I have a table with three columns and I would like to display distinct values in each column. Could any one please help me to get the output.
    col1     col2     col3
    ====     ====     ====
    a     1     x     
    a     2     y
    a     3      z
    a     4      u
    b     5      v
    b     6      x
    b     7      x
    b     9      x
    b     10     y
    b     11     y
    b     12     y
    b     13     y
    b     14     x
    b     15     y
    b     16     z
    b     17     u
    b     18     v
    b     19     x
    b     20     x
    c     21     x
    c     22     y
    c     23     y
    c     24     y
    c     25     y
    c     26     x
    c     27     y
    c     28     z
    Output needed
    ===========
    col1     col2     col3
    ====     ====     ====
    a     1     x
    b     2     y
    c     3     z
         4     u
         5     v
         6
         7
         9
         10
         11
         12
         13
         14
         15
         16
         17
         18
         19
         20
         21
         22
         23
         24
         25
         26
         27
         28
    Thanks
    Vasanth

    but the only drawback - you need to know the column, comprising the biggest amount of distinct values beforehand.No. There is no any difference in which column will be chosen as "based".
    For demo purposes I've added extra row number column to show full generality and symmetry of the approach:
    exec dbms_random.seed(0)
    with t as ( select chr(ascii('a') + dbms_random.value(0, 3)) as c1,
                       trunc(dbms_random.value(1, 20))           as c2,
                       chr(ascii('u') + dbms_random.value(0, 6)) as c3
                  from dual connect by level <= 20
       tt1 as ( select lag(          null,  1, c1) over (partition by c1 order by null) as c1,
                       lag(to_number(null), 1, c2) over (partition by c2 order by null) as c2,
                       lag(          null,  1, c3) over (partition by c3 order by null) as c3
                  from t
       tt2 as ( select tt1.*,
                       row_number() over (order by c1) as rn1,
                       row_number() over (order by c2) as rn2,
                       row_number() over (order by c3) as rn3,
                       rownum rn
                  from tt1
       tt3 as ( select case when rn1 > rn
                            then last_value(c1) over (order by rn1 range between abs(rn1 - rn) preceding
                                                                             and abs(rn1 - rn) preceding)
                            else last_value(c1) over (order by rn1 range between abs(rn - rn1) following
                                                                             and abs(rn - rn1) following)
                       end as c1,
                       case when rn2 > rn
                            then last_value(c2) over (order by rn2 range between abs(rn2 - rn) preceding
                                                                             and abs(rn2 - rn) preceding)
                            else last_value(c2) over (order by rn2 range between abs(rn - rn2) following
                                                                             and abs(rn - rn2) following)
                       end as c2,
                       case when rn3 > rn
                            then last_value(c3) over (order by rn3 range between abs(rn3 - rn) preceding
                                                                             and abs(rn3 - rn) preceding)
                            else last_value(c3) over (order by rn3 range between abs(rn - rn3) following
                                                                             and abs(rn - rn3) following)
                       end as c3
                  from tt2
    select c1, c2, c3 from tt3
      where c1 || c2 || c3 is not null
      order by c1, c2, c3
    C1            C2 C3
    a              1 u
    b              3 v
    c              4 w
                   5 x
                   7 y
                   8 z
                   9
                  11
                  13
                  15
                  16
                  17
                  19
    13 rows selected.P.S. Thanks to [url http://www.sql.ru/forum/actualthread.aspx?bid=3&tid=482506&hl=over+range#4785373]Vladimir Sitnikov for the demo of the approach.

  • Get distinct values from plsql array

    Hi,
    I have declared a variable as below in plsql proc.
    type t_itemid is table of varchar2(10);
    inserted set of items in to this using a program
    now i want distinct values from that array how can i get it.

    I am using 9i so i cannot use set operator and more over my problem is that i am declaring the variable inside the plsql block . when i tried i am getting the below errors:
    SQL> r
    1 declare
    2 type t_type is table of varchar2(10);
    3 v_type t_type;
    4 begin
    5 v_type := t_type('toys','story','good','good','toys','story','dupe','dupe');
    6 for i in (select column_value from table(v_type)) loop
    7 dbms_output.put_line(i.column_value);
    8 end loop;
    9* end;
    for i in (select column_value from table(v_type)) loop
    ERROR at line 6:
    ORA-06550: line 6, column 41:
    PLS-00642: local collection types not allowed in SQL statements
    ORA-06550: line 6, column 35:
    PL/SQL: ORA-22905: cannot access rows from a non-nested table item
    ORA-06550: line 6, column 10:
    PL/SQL: SQL Statement ignored
    ORA-06550: line 7, column 22:
    PLS-00364: loop index variable 'I' use is invalid
    ORA-06550: line 7, column 1:
    PL/SQL: Statement ignored

  • Getting a list of distinct values

    Hello,
    I'm using Toplink named queries with an sql-expression (in JDev Studio 10.1.0.3.) but I'm having trouble to get distinct values.
    I want to create a dropdown list containing all pricerange possibilities, the basic data comes from a table with following format:
    PRICERANGE_ID -- ACTIVITY -- PRICE
    LOW--------------------- Analysis ---- 65
    LOW -------------------- Training ----- 75
    MEDIUM -------------- Analysis ---- 75
    MEDIUM -------------- Training ----- 90
    HIGH ------------------- Analysis ---- 85 etc.
    I have now created a TopLink named query, type: ReadAllQUery,
    SQL statement: select pricerange.PRICERANGE_ID from pricerange
    group by pricerange.PRICERANGE_ID
    order by pricerange.PRICERANGE_ID
    and PRICERANGE_ID is part of the primary key of pricerange (but I don't expect this to be a problem)
    Now, when I use this query to get the values in a dropdown list, I don't get any values as a return. I have tested in pure SQL (using TOAD) in which I was able to get the correct value for each record.
    My guess is that is some problem with defining row names in this TopLink query. Since I ask only to select the data of one column, but when I want to create a dropdown list I get a list of all fields in the original table.
    Can you limit the selection to certain fields or columns in a TopLink named query ? Are there other options ?
    I have posted this question on the Toplink forum and did get the suggestion of Doug Clarke to use a ReportQuery instead of a ReadAllObjects query, but it's still not clear to me where and what I should do.
    Kind regards,
    Nemata

    This discussion is being followed up on at Re: getting a list of distinct values

  • Concatenation of character values by columns with excluding duplicates

    Hi all! Assume, that there is a multi-rows table of the following form (for example):
    1|A  |   |B  |C  |   |D  |   |
    2|   |   |A  |B  |C  |D  |   |
    3|   |A  |B  |   |   |C  |D  |
    4|   |   |A  |   |B  |C  |D  |
    5|   |   |A  |   |B  |   |C  |i.e. there are NULL and NOTNULL values in VARCHAR2( or NVARCHAR2) format, and the first column is a primary key.
    I need to do next:
    1. Select some set of certain rows, primary keys of those are initialy known, e.g. 1, 3, 5;
    2. Parse this table such way: concatenate values by columns in selected rows, if there are few not-null values in one column, it's necessary to separate concatenated values with comma and whitesbase (it's desirable that's word after comma with whitespace is outputted in lowercase). Finally, it's necessary to insert dot and whitespace character after the last value.
    3. Exclude duplicate substrings from the outcoming text values.
    Thereafter I need to initialize set of local variables with the values, obtained by forementioned parsing (parsing of one column match the corresponding variable), e.g. columns of 1, 3 and 5 rows.
    I.e. result in our case looks like:
    variable1 = A.
    variable2 = A.
    variable3 = B, A.
    variable4 = C.
    variable5 = B.
    variable6 = D, C.
    variable7 = D, C.
    Does the task will be easier, if the number of parsed rows is known (e.g. 3 as in our case)?
    Edited by: 942736 on 02.10.2012 17:17

    You missed your db-version. Please give the result from
    select * from v$version;When you are on 11.2 you can try this (will not work with 10.x):
    with yourtable as
    select 1 id, 'A' col1, 'N' col2, 'B' col3, 'C' col4 ,'N' col5, 'D' col6 ,'N' col7 from dual union all
    select 2,'N','N','A','B','C','D','N' from dual union all
    select 3,'N','A','B','N','N','C','D' from dual union all
    select 4,'N','N','A','N','B','C','D' from dual union all
    select 5,'N','N','A','N','B','N','C' from dual
    select
    (select listagg(col1,',') within group (order by id)||'.' from (select distinct col1, min(id) over (partition by col1 order by id) id from yourtable where id in (1,3,5))) v1,
    (select listagg(col2,',') within group (order by id)||'.' from (select distinct col2, min(id) over (partition by col2 order by id) id from yourtable where id in (1,3,5))) v2,
    (select listagg(col3,',') within group (order by id)||'.' from (select distinct col3, min(id) over (partition by col3 order by id) id from yourtable where id in (1,3,5))) v3,
    (select listagg(col4,',') within group (order by id)||'.' from (select distinct col4, min(id) over (partition by col4 order by id) id from yourtable where id in (1,3,5))) v4,
    (select listagg(col5,',') within group (order by id)||'.' from (select distinct col5, min(id) over (partition by col5 order by id) id from yourtable where id in (1,3,5))) v5,
    (select listagg(col6,',') within group (order by id)||'.' from (select distinct col6, min(id) over (partition by col6 order by id) id from yourtable where id in (1,3,5))) v6,
    (select listagg(col7,',') within group (order by id)||'.' from (select distinct col7, min(id) over (partition by col7 order by id) id from yourtable where id in (1,3,5))) v7
    from dual;Output with 11.2 is:
    V1      V2      V3      V4      V5      V6      V7
    A,N.     N,A.     B,A.     C,N.     N,B.     D,C,N.     N,D,C.@ranit B: You missed, that the OP said that only rows 1,3 and 5 shall be used.
    Edited by: hm on 01.10.2012 23:09

  • How to get distinct values from a list and display in a ListView webpart.

    Hi,
    I have a requirement in which I need to pull unique/distinct values from a custom list and then display it via a listview webpart. Can any one suggest how this can be done.
    If possible please share the CAMEL query to fetch distinct values from a custom list.
    Thanks,
    Ankit

    Hi Ankit,
    Is there any particular reason that the values need to be shown in a list view web part?  Are you going to use that web part for filtering via web part connections?
    I ask because the enterprise site collection features include the SharePoint List Filter web part, which may accomplish what you're looking for.
    If you just need to display the values in a grid view, you might have more luck with the JavaScript Client Object Model.  Try putting the following in a text file:
    <style>
    .CustomTableClass{display:table;table-layout:fixed}
    .CustomRowClass{display:table-row;}
    </style>
    <div id="distinct_values_div" class="CustomTableClass">
    <img src="/_layouts/loading.gif" />
    </div>
    <script language="JavaScript" type="text/JavaScript">
    var siteUrl = '/sitecollection/web'; //use the actual subsite URL here
    var listName = 'mylist'; // use the actual list name here
    var field = "Title" // use the actual field you want to display here
    var divToUpdate = document.getElementById("distinct_values_div");
    var rowClass = "CustomRowClass";
    ExecuteOrDelayUntilScriptLoaded(function(){
    var clientContext = new SP.ClientContext(siteUrl);
    var web = clientContext.get_web();
    var lists = web.get_lists();
    var list = lists.getByTitle(listName);
    var camlQuery = new SP.CamlQuery();
    camlQuery.set_viewXml('<View><Query></Query><RowLimit>500</RowLimit></View>');
    this.collListItem = list.getItems(camlQuery);
    clientContext.load(collListItem,"Include ("+field+")");
    clientContext.executeQueryAsync(
    Function.createDelegate(this, this.onQuerySucceeded),
    Function.createDelegate(this, this.onQueryFailed));
    },"sp.js");
    function onQueryFailed(sender, args){
    divToUpdate.innerHTML = 'Unable to retrieve values: '+args.get_message());
    function onQuerySucceeded(sender, args){
    var allValues = [];
    var listItemEnumerator = collListItem.getEnumerator();
    divToUpdate.innerHTML = "";
    while(listItemEnumerator.moveNext()){
    var listItem = listItemEnumerator.get_current();
    if(!containsString(allValues,listItem.get_item(field)){
    var value = listItem.get_item(field);
    allValues.push(value);
    var newDiv = document.createElement("div");
    newDiv.className = rowClass;
    newDiv.innerHTML = value;
    divToUpdate.appendChild(newDiv);
    function containsString(strArray, text){
    var contains = false;
    for (var i=0; i<strArray.length; i++){
    if(strArray[i]==text){contains = true; break;}
    return contains;
    </script>
    Upload the text file to a library on the site, then add a content editor web part to a page where you want the distinct values to appear. In the content editor web part's properties, edit the Content Link so that it links directly to the text file.  This
    will cause the JavaScript to run on the page.

  • Get distinct values from a coma seperated string variable

    Hi ,
    I am getting an comma seperated string as in parameter, now i want to get the distinct values from that string and will use those values to pass it to a query.
    any help

    try this:
    sorry about the messiness - it's just quickly copied from some badly formatted code....
    TYPE T_FieldArray IS TABLE OF varchar2(255) INDEX BY BINARY_INTEGER;
    function SPLIT_CSV_FIELDS (
    p_Input_Str in varchar2,
    p_Delimiter in varchar2,
    p_Quote_Char in varchar2)
    return t_fieldarray is
    v_FieldArray T_FieldArray;
    v_input_str varchar2(4000);
    v_field_str varchar2(255);
    v_pos number;
    e number := 0;
    v_delim_str varchar2(3);
    cur_pos number;
    begin
    loop
    -- find each delimiter char in string
    v_pos := INSTR(v_input_str, p_Delimiter);
    -- each time delimiter char is found
    if v_pos > 0 then
    -- current field value is current string to position prior to delimiter char
    v_field_str := UPPER(SUBSTR(v_input_str, 1, v_pos - 1));
    -- remove quote char from end of field (if any)
    v_field_str := TRIM(TRANSLATE(v_field_str, NVL(p_Quote_Char, p_Delimiter), ' '));
    -- increment element number
    e := e + 1;
    -- get remainder of input string to check
    v_input_str := SUBSTR(v_input_str, v_pos + 1, LENGTH(v_input_str) - v_pos);
    v_FieldArray(e) := v_field_str;
    else
    -- increment element number
    e := e + 1;
    -- last field value is what's left of input string less quote char (if any)
    v_field_str := TRIM(TRANSLATE(UPPER(v_input_str), NVL(p_Quote_Char, p_Delimiter), ' '));
    v_FieldArray(e) := v_field_str;
    exit;
    end if;
    end loop;
    return v_FieldArray;
    end;

Maybe you are looking for