Distinct Select on Varchar2 Column
Hi,
I have a unique problem - (no pun intended) - pls bare with me while I explain...
I have the following table (tbl_party) :
p_num VARCHAR2(30)
p_name VARCHAR2(100)
p_cert NUMBER
i_cat NUMBER
p_stat DATE
Test 1.
When I do a select count(distinct(p_num)) from tbl_party;
Return 6298 rows
Test 2.
When I do a select distinct(p_num) from tbl_party;
Return 6298 rows
Test 3.
When I do a select distinct(p_num), p_cert from tbl_party;
Return 6300 rows???
Can some1 pls enlighten me if there is a limitation on distinct/unique when using it on VARCHAR2??
Thanks in advance.
Jaco
I think in third test you get 6300 not 6298 because there are two additional value for the same values in p_num column.
See this:
SQL> ed
Wrote file afiedt.buf
1 with t as
2 (select 1 as col1, 'abc' from dual
3 union all
4 select 2, 'bcd' from dual
5 union all
6* select 1, 'bcd' from dual)
SQL> ed
Wrote file afiedt.buf
1 with t as
2 (select 1 as col1, 'abc' from dual
3 union all
4 select 2, 'bcd' from dual
5 union all
6 select 1, 'bcd' from dual)
7* select distinct(col1) from t
SQL> /
COL1
1
2
SQL> ed
Wrote file afiedt.buf
1 with t as
2 (select 1 as col1, 'abc' from dual
3 union all
4 select 2, 'bcd' from dual
5 union all
6 select 1, 'bcd' from dual)
7* select count(distinct(col1)) from t
SQL> /
COUNT(DISTINCT(COL1))
2
SQL> ed
Wrote file afiedt.buf
1 with t as
2 (select 1 as col1, 'abc' as col2 from dual
3 union all
4 select 2, 'bcd' from dual
5 union all
6 select 1, 'bcd' from dual)
7* select distinct(col1), col2 from t
SQL> /
COL1 COL
1 bcd
1 abc
2 bcdAs you can see there are two values in col2 for one value in col1. That's why you get 6300 not 6298 even if you use DISTINCT.
Peter D.
Similar Messages
-
Apply distinct to all the columns in a select list
Select distinct name, date , venue , duration from tableA
the above query distinct onlu the first column in the select list but is it possible to distinct all the columns.
current out put is
1 , raj, 25-may-2009, uk , 10
1 , raj, 25-may-2009, usa , 10
1 , raj, 25-may-2009, uk , 20
requried output....
1 , raj, 25-may-2009, uk , 10
the first found row is enogh...
thanks in advance :)
rajBut all these tree rows are distinct. Doesn't it? Why you want to take only first row? What's the logic?
Kamran Agayev A. (10g OCP)
http://kamranagayev.wordpress.com
[Step by Step install Oracle on Linux and Automate the installation using Shell Script |http://kamranagayev.wordpress.com/2009/05/01/step-by-step-installing-oracle-database-10g-release-2-on-linux-centos-and-automate-the-installation-using-linux-shell-script/] -
Select distinct('more than one column') from ....
Why does this sql statement not work:
select distinct(column_a, column_b, column_c), empno
from emp;
How can I 'select distinct' using more than one column.Actually, DISTINCT applies to all columns in the result.
Distinct is not a function, you cannot do distinct(column1, column2, ...).
As a matter of fact it doesn't make sense to expect distinct applies to only one column, because you do not specify any criteria on how to select the values for the second column.
A final note: you can do distinct(column1), column2, but this will still apply to both columns!
Here're some examples that will all return both rows from the set, where set is: (1,1), (1,2):
select distinct val1, val2
from
select 1 as val1, 1 as val2 from dual
union all
select 1 as val1, 2 as val2 from dual
select distinct val1||'-'||val2
from
select 1 as val1, 1 as val2 from dual
union all
select 1 as val1, 2 as val2 from dual
select distinct(val1), val2 -- this is very misleading. distinct still applies to both columns
from
select 1 as val1, 1 as val2 from dual
union all
select 1 as val1, 2 as val2 from dual
Edited by: user4010726 on Dec 1, 2009 11:06 AM
Edited by: user4010726 on Dec 1, 2009 11:07 AM -
"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 -
How do I select a date column and display the millesecond along with it.
I am trying to select a date column from database and want to
display millesecond with it. How do I do this. I am aware of
the "alter session set NLS_DATE_FORMAT = 'MM/DD/YY HH:MI:SS'"
command. However, I do not know how to display this with the
millesecond.
Thanks for all the help.Example:
SQL> CREATE OR REPLACE JAVA SOURCE
2 NAMED "MyTimestamp"
3 AS
4 import java.lang.String;
5 import java.sql.Timestamp;
6
7 public class MyTimestamp
8 {
9 public static String getTimestamp()
10 {
11 return (new
12 Timestamp(System.currentTimeMillis())).toString();
13 }
14 };
15 /
Java created.
SQL> CREATE OR REPLACE FUNCTION my_timestamp
2 RETURN VARCHAR2
3 AS LANGUAGE JAVA
4 NAME 'MyTimestamp.getTimestamp() return java.lang.String';
5 /
Function created.
SQL> CREATE TABLE test_time
2 (date_col VARCHAR2 (23))
3 /
Table created.
SQL> INSERT INTO test_time (date_col)
2 SELECT my_timestamp
3 FROM dual
4 /
1 row created.
SQL> SELECT date_col
2 FROM test_time
3 /
DATE_COL
2001-11-02 14:58:51.766 -
Sort Order for a VARCHAR2 Column
Hello Everyone,
This is probably quite simple, however I cannot see it. I am trying to sort on a varchar2 column that has numbers, text, dashes, tildes, carets and underscores which are mixed to compose a wire number. I have come up with an order by that changes the sort order from alpha to numeric satisfying one portion of the requirement.
select wirenbr,fromitem "from",frompin,diagnbr,sht,toitem,topin,effect
from acft_wires
order by decode(to_char(nvl(length(translate(wirenbr,'A1234567890','A')),0)),'0',lpad(wirenbr,18),wirenbr);
The select returns:
1
2
3
20
21
200
201
1000
A
ADT1
AEN1
AE1
AE9
AFA
B
1A
2U7230A-ZZ
2000A
213-22
22X100A20
220-11
The customer preferred sort looks like:
1
2
3
10
10A
11
200
201
201-01
202
1000
1000A
1001
I will build a shrine in my hall of honor to this forum if someone can point me in the right direction on how to solve this problem.
Thanks everyone for your help.ok, start with this
order by
translate(substr(wirenbr,1,1),'1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ-','0000000000ZZZZZZZZZZZZZZZZZZZZZZZZZZZ')
, nvl(length(substr(wirenbr,1,instr(translate(wirenbr,'1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ-','1234567890XXXXXXXXXXXXXXXXXXXXXXXXXXX'),'X')-1)),length(wirenbr))
, to_number(translate(wirenbr,'1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ-','123456789000000000000000000000000000'))
First, all that start with number go to the beginning and all that start with a letter go to the end.
Next, sort by the length of the first numerical part, as per Al's first solution.
Next, sort by the numerical part.
I started getting what I think is the right sort by that point. However, I think that you'll also have to add
stuff to sort by the alpha part, mine was
, NVL(RTRIM(LTRIM(wirenbr,'0123456789'),'0123456789'),0)
The biggest problem I see is all of the different number-letter-number
number-letter-number-letter formats. How many levels of recursion you'll have to go through to get it perfectly sorted, could you have ZZ999ZZ99Z9Z9Z9Z99?
Any ideas for breaking this value up? -
TO_NUMBER function on varchar2 column with numbers and strings
I need to create a column in a view that converts a varchar2 column data to number. The problem is that some
of the data have strings and some numbers. I get "ORA-01722: invalid number" error when Oracle tries to covert
strings (e.g. 'ABCD') to number. What I need is to get a NULL value if the data is an invalid number.
How can I rewrite the following to get NULL value is a string is invalid number?
select to_number('abcd') numberColumn
from dual
thanx
AlfredSQL> select * from test_char_num;
ALPHA_NUM
ABC
DEF
123
234
A12
SQL> select decode(NVL(length(trim(translate(alpha_num, '1234567890', ' '))), 0),
2 0, alpha_num, 'NULL') new_alpha_num
3 from test_char_num;
NEW_ALPHA_
NULL
NULL
123
234
NULLP.S I am printing 'NULL' just to show the result, Please replace the 'NULL string with NULL value in SQL.
Thx,
Sri -
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
Vasanthbut 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. -
SELECT in SELECT returning multiple columns ?
10.2.0.3 version.
I am trying to tune this query
SELECT A.EMPLID, A.EFFDT, A.ACAD_PROG,
(SELECT A1.DESCR FROM PS_ACAD_PROG_TBL A1
WHERE A1.INSTITUTION = 'AUAO1' AND A1.ACAD_PROG = A.ACAD_PROG AND A1.EFFDT = (SELECT MAX (EFFDT) FROM PS_ACAD_PROG_TBL WHERE INSTITUTION = A1.INSTITUTION AND ACAD_PROG = A1.ACAD_PROG),
(SELECT A2.DESCRSHORT FROM PS_ACAD_PROG_TBL A2
WHERE A2.INSTITUTION = 'AUAO1' AND A2.ACAD_PROG = A.ACAD_PROG AND A2.EFFDT = (SELECT MAX (EFFDT) FROM PS_ACAD_PROG_TBL WHERE INSTITUTION = A2.INSTITUTION AND ACAD_PROG = A2.ACAD_PROG),
as you can see it reading the table PS_ACAD_PROG_TBL two time to get two cloumns DESCR (alias A1) and DESCRSHORT (alias A2) exactly with the same where condition.
I am trying to replace it with just one select returning multiple columns like this
SELECT A.EMPLID, A.EFFDT, A.ACAD_PROG,
(SELECT A1.DESCR, A1.DESCRSHORT FROM PS_ACAD_PROG_TBL A1
WHERE A1.INSTITUTION = 'AUAO1' AND A1.ACAD_PROG = A.ACAD_PROG AND A1.EFFDT = (SELECT MAX (EFFDT) FROM PS_ACAD_PROG_TBL WHERE INSTITUTION = A1.INSTITUTION AND ACAD_PROG = A1.ACAD_PROG),
but I am getting ORA-00913: too many values.
Please help on how to get around this. Thanks in advance.William,
On similar lines I am struggling with the below query based on your suggestions.
SQL*Plus: Release 9.2.0.1.0 - Production on Wed Aug 5 14:17:21 2009
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> WITH arch_dup AS
2 (SELECT a.file_id,
3 a.sale_start,
4 a.activity_start,
5 a.activity_end,
6 a.item_code_cust,
7 a.division,
8 (SELECT MAX (DISTINCT (NVL (b.advertised, 'No')))
9 FROM ah_cust_gis_arch_stg b
10 WHERE b.file_id = a.file_id
11 AND NVL (b.sale_start, 'NULL') = NVL (a.sale_start, 'NULL')
12 AND NVL (b.activity_start, 'NULL') = NVL (a.activity_start, 'NULL')
13 AND NVL (b.activity_end, 'NULL') = NVL (a.activity_end, 'NULL')
14 AND b.item_code_cust = a.item_code_cust
15 AND b.division = a.division) advertised,
16 COUNT (*)
17 FROM ah_cust_gis_arch_stg a
18 WHERE a.file_id = 209
19 AND a.status_id = 21
20 GROUP BY a.file_id, a.sale_start, a.activity_start, a.activity_end, a.item_code_cust, a.d
ivision
21 HAVING COUNT (*) > 1)
22 SELECT dup.*,
23 (SELECT activity_id
24 FROM (SELECT activity_id,
25 ROW_NUMBER () OVER (ORDER BY (activity_retail / activity_mult)) rnk
26 FROM ah_cust_gis_arch_stg
27 WHERE status_id = 21
28 AND NVL (sale_start, 'NULL') = NVL (dup.sale_start, 'NULL')
29 AND NVL (activity_start, 'NULL') = NVL (dup.activity_start, 'NULL')
30 AND NVL (activity_end, 'NULL') = NVL (dup.activity_end, 'NULL')
31 AND item_code_cust = dup.item_code_cust
32 AND division = dup.division
33 AND file_id = 209
34 AND UPPER (NVL (advertised, 'N')) = dup.advertised)
35 WHERE rnk = 1) activity_id
36 FROM arch_dup dup;
AND UPPER (NVL (advertised, 'N')) = dup.advertised)
ERROR at line 34:
ORA-00904: "DUP"."ADVERTISED": invalid identifierCan you throw some light on what to do to make the outer query columns available to inner query?
Thanks,
Raj. -
An unusual select rows as columns...
Colleagues,
I could really use some help on this one. Thanks in advance for all your help.
Here is what I have:
the input (create and insert scripts provided below) is:
ID SCHEMA_ID TBL_ID TBL_COLS_ID COLUMN_VALUE
=============================================
100 1 1 76 0
101 1 1 77 ABCD
102 1 1 76 0
103 1 1 77 DEF
COLUMN NAMES:
TBL_COLS_ID 76 = 'KEY'
TBL_COLS_ID 77 = 'KEYVAL'
End result I am looking for is to select rows into columns like:
ALSO, I would like to know how this can be done in a dynamic way within a PLSQL procedure as there are multiple tables and columns in each table are different.
SCHEMA_ID TBL_ID KEY KEYVAL
=============================
1 1 0 ABCD
1 1 0 DEF
select schema_id,tbl_id,
decode( tbl_cols_id, 76, COLUMN_VALUE, null) KEY,
decode( dr_table_cols_id, 77, COLUMN_VALUE, null) KEYVAL
from items where schema_id =1
and tbl_id =1
CREATE TABLE ITEMS(
ID NUMBER NOT NULL,
SCHEMA_ID NUMBER,
TBL_ID NUMBER,
TBL_COLS_ID NUMBER,
COLUMN_VALUE VARCHAR2 (30)
Insert into items
(ID, SCHEMA_ID, TBL_ID, TBL_COLS_ID, COLUMN_VALUE)
Values
(151056, 1, 1, 76, '0');
Insert into items
(ID, SCHEMA_ID, TBL_ID, TBL_COLS_ID, COLUMN_VALUE)
Values
(151057, 1, 1, 77, 'ABCD');
Insert into items
(ID, SCHEMA_ID, TBL_ID, TBL_COLS_ID, COLUMN_VALUE)
Values
(151058, 1, 1, 76, '0');
Insert into items
(ID, SCHEMA_ID, TBL_ID, TBL_COLS_ID, COLUMN_VALUE)
Values
(151059, 1, 1, 77, 'XYZ ');
Insert into items
(ID, SCHEMA_ID, TBL_ID, TBL_COLS_ID, COLUMN_VALUE)
Values
(151060, 1, 1, 76, '0');
Insert into items
(ID, SCHEMA_ID, TBL_ID, TBL_COLS_ID, COLUMN_VALUE)
Values
(151061, 1, 1, 77, 'DEF');
Insert into items
(ID, SCHEMA_ID, TBL_ID, TBL_COLS_ID, COLUMN_VALUE)
Values
(151062, 1, 1, 76, '0');
Insert into items
(ID, SCHEMA_ID, TBL_ID, TBL_COLS_ID, COLUMN_VALUE)
Values
(151063, 1, 1, 77, 'TNT ');
Insert into items
(ID, SCHEMA_ID, TBL_ID, TBL_COLS_ID, COLUMN_VALUE)
Values
(151064, 1, 1, 76, '0');
Insert into items
(ID, SCHEMA_ID, TBL_ID, TBL_COLS_ID, COLUMN_VALUE)
Values
(151065, 1, 1, 77, 'CD ');
Insert into items
(ID, SCHEMA_ID, TBL_ID, TBL_COLS_ID, COLUMN_VALUE)
Values
(151066, 1, 1, 76, '0');
Insert into items
(ID, SCHEMA_ID, TBL_ID, TBL_COLS_ID, COLUMN_VALUE)
Values
(151067, 1, 1, 77, 'NN ');
Insert into items
(ID, SCHEMA_ID, TBL_ID, TBL_COLS_ID, COLUMN_VALUE)
Values
(151068, 1, 1, 76, '0');
Insert into items
(ID, SCHEMA_ID, TBL_ID, TBL_COLS_ID, COLUMN_VALUE)
Values
(151069, 1, 1, 77, 'BCDA');
Insert into items
(ID, SCHEMA_ID, TBL_ID, TBL_COLS_ID, COLUMN_VALUE)
Values
(151070, 1, 1, 76, '0');
Insert into items
(ID, SCHEMA_ID, TBL_ID, TBL_COLS_ID, COLUMN_VALUE)
Values
(151071, 1, 1, 77, 'GAG ');
Insert into items
(ID, SCHEMA_ID, TBL_ID, TBL_COLS_ID, COLUMN_VALUE)
Values
(151072, 1, 1, 76, '0');
Insert into items
(ID, SCHEMA_ID, TBL_ID, TBL_COLS_ID, COLUMN_VALUE)
Values
(151073, 1, 1, 77, 'ABC1');
Thank you.If I understand correctly, you want to pair up successive records to match the key and value pairs. Assuming that each successive pair of id's (e.g. 151056/76 and 151057/77) go together, then something like tthis should do it. Not that I replaced your 0 in the records for the 76 column values with the id just to make sure that the rows were pairing correctly.
SQL> SELECT schema_id, tbl_id, key, keyval
2 FROM (
3 SELECT schema_id,tbl_id,
4 DECODE( tbl_cols_id, 76, COLUMN_VALUE, null) KEY,
5 LEAD(DECODE( tbl_cols_id, 77, COLUMN_VALUE, null),1)
6 OVER (ORDER BY ID) KEYVAL
7 FROM items
8 WHERE schema_id =1 and
9 tbl_id =1)
10 WHERE key IS NOT NULL and
11 keyval IS NOT NULL;
SCHEMA_ID TBL_ID KEY KEYVAL
1 1 151056 ABCD
1 1 151058 XYZ
1 1 151060 DEF
1 1 151062 TNT
1 1 151064 CD
1 1 151066 NN
1 1 151068 BCDA
1 1 151070 GAG
1 1 151072 ABC1TTFN
John -
Is it possible to distinct based on individual column ?
This is the sample data i have , on Oracle 11G ,Release 1.
WITH T AS
(SELECT '001' ID,TO_DATE('16-08-2011','dd-mm-yyyy') DT FROM DUAL UNION
SELECT '002' ID,TO_DATE('16-08-2011','dd-mm-yyyy') DT FROM DUAL UNION ALL
SELECT '003' ID,TO_DATE('16-08-2011','dd-mm-yyyy') DT FROM DUAL UNION ALL
SELECT '004' ID,TO_DATE('16-08-2011','dd-mm-yyyy') DT FROM DUAL UNION ALL
SELECT '005' ID,TO_DATE('16-08-2011','dd-mm-yyyy') DT FROM DUAL UNION ALL
SELECT '005' ID,TO_DATE('16-08-2011','dd-mm-yyyy') DT FROM DUAL UNION ALL
SELECT '005' ID,TO_DATE('16-09-2011','dd-mm-yyyy') DT FROM DUAL UNION ALL
SELECT '006' ID,TO_DATE('16-08-2011','dd-mm-yyyy') DT FROM DUAL UNION ALL
SELECT '006' ID,TO_DATE('16-09-2011','dd-mm-yyyy') DT FROM DUAL
SELECT DISTINCT ID,DT FROM T;From the above query as expected i got all those rows that have distinct ID and DT column . Here a total of 8 rows.
It is also important to note that distinct applies on whole column of a row at time and not on the individual column ,as explained in this example.
Is there any way to get all those rows whose one column do not contain repeated data.
e.g., select ID and DT where ID column do not repeat with same value.Depends on what you want to do exactly.
But analytics can probably help you out.
E.g.
SQL> WITH T AS
2 (SELECT '001' ID,TO_DATE('16-08-2011','dd-mm-yyyy') DT FROM DUAL UNION
3 SELECT '002' ID,TO_DATE('16-08-2011','dd-mm-yyyy') DT FROM DUAL UNION ALL
4 SELECT '003' ID,TO_DATE('16-08-2011','dd-mm-yyyy') DT FROM DUAL UNION ALL
5 SELECT '004' ID,TO_DATE('16-08-2011','dd-mm-yyyy') DT FROM DUAL UNION ALL
6 SELECT '005' ID,TO_DATE('16-08-2011','dd-mm-yyyy') DT FROM DUAL UNION ALL
7 SELECT '005' ID,TO_DATE('16-08-2011','dd-mm-yyyy') DT FROM DUAL UNION ALL
8 SELECT '005' ID,TO_DATE('16-09-2011','dd-mm-yyyy') DT FROM DUAL UNION ALL
9 SELECT '006' ID,TO_DATE('16-08-2011','dd-mm-yyyy') DT FROM DUAL UNION ALL
10 SELECT '006' ID,TO_DATE('16-09-2011','dd-mm-yyyy') DT FROM DUAL
11 )
12 SELECT id
13 , dt
14 FROM
15 (SELECT id
16 , dt
17 , row_number() over (partition by id order by dt) rn
18 FROM T)
19 WHERE rn = 1;
ID DT
001 16-AUG-11
002 16-AUG-11
003 16-AUG-11
004 16-AUG-11
005 16-AUG-11
006 16-AUG-11
6 rows selected.
SQL>
SQL> WITH T AS
2 (SELECT '001' ID,TO_DATE('16-08-2011','dd-mm-yyyy') DT FROM DUAL UNION
3 SELECT '002' ID,TO_DATE('16-08-2011','dd-mm-yyyy') DT FROM DUAL UNION ALL
4 SELECT '003' ID,TO_DATE('16-08-2011','dd-mm-yyyy') DT FROM DUAL UNION ALL
5 SELECT '004' ID,TO_DATE('16-08-2011','dd-mm-yyyy') DT FROM DUAL UNION ALL
6 SELECT '005' ID,TO_DATE('16-08-2011','dd-mm-yyyy') DT FROM DUAL UNION ALL
7 SELECT '005' ID,TO_DATE('16-08-2011','dd-mm-yyyy') DT FROM DUAL UNION ALL
8 SELECT '005' ID,TO_DATE('16-09-2011','dd-mm-yyyy') DT FROM DUAL UNION ALL
9 SELECT '006' ID,TO_DATE('16-08-2011','dd-mm-yyyy') DT FROM DUAL UNION ALL
10 SELECT '006' ID,TO_DATE('16-09-2011','dd-mm-yyyy') DT FROM DUAL
11 )
12 SELECT id
13 , dt
14 FROM
15 (SELECT id
16 , dt
17 , count(*) over (partition by id) cn
18 FROM T)
19 WHERE cn = 1;
ID DT
001 16-AUG-11
002 16-AUG-11
003 16-AUG-11
004 16-AUG-11 -
I HAVE ONE VARCHAR2 COLUMN.
hI
i HAVE ONE VARCHAR2 COLUMN. IN THIS COLUMN I STROED ALL CHARECTER DATA .SOME EXCTION FILE NAME ,
TEST.DOC,TEST2.DOC,TEST3.DOC AND TEXT_MAIN.DOC NOW I WANT EXTRACT STRING UP TO . CHARECTER WHICH FUNCTION I WANT USE TO GET THE VALUE UP TO . CHERECTER,MEANS I DON'T WANT TO EXTENSION I WANT ONLY FILE NAME.
thank'sYou did not mention the version of Oracle you are using
SQL> with d as
( select 'test.doc' name from dual union all
select 'test2.doc' from dual
select name, regexp_substr(name,'[^.]+') str
, substr(name,1,instr(name,'.')-1) str9iVersion
from d
NAME STR STR9IVERS
test.doc test test
test2.doc test2 test2SS -
How to select a specific column in a bean method?
Hey everyone,
I'm trying to select a specific column in my adf table so i can hightlight the ones i can after, with a method bean that does a match from another table. I'm using JDeveloper 12.1.2.0.0.
Here's my table at the moment (its a static list that Timo and Alejandro helped me create, thanks to them again!):
<af:table value="#{bindings.Anos1.collectionModel}" var="row"
rows="#{bindings.Anos1.rangeSize}"
emptyText="#{bindings.Anos1.viewable ? 'No data to display.' : 'Access Denied.'}"
rowBandingInterval="0" fetchSize="#{bindings.Anos1.rangeSize}"
filterModel="#{bindings.Anos1Query.queryDescriptor}"
queryListener="#{bindings.Anos1Query.processQuery}"
filterVisible="false" varStatus="vs" id="t5"
styleClass="AFStretchWidth" columnSelection="multiple"
inlineStyle="max-width:100%;" columnStretching="multiple"
columnSelectionListener="#{ControlBean.onAnoColumnSelect}"
disableColumnReordering="true"
binding="#{ControlBean.dimAnos}">
<af:column sortProperty="#{bindings.Anos1.hints.A2011.name}"
filterable="true" sortable="false"
headerText="2011"
id="c54" width="16%">
<af:outputText value="#{row.A2011}"
shortDesc="#{bindings.Anos1.hints.A2011.tooltip}"
id="ot54">
<af:convertNumber groupingUsed="false"
pattern="#{bindings.Anos1.hints.A2011.format}"/>
</af:outputText>
</af:column>
<af:column sortProperty="#{bindings.Anos1.hints.A2012.name}"
filterable="true" sortable="false"
headerText="2012"
id="c55" width="16%">
<af:outputText value="#{row.A2012}"
shortDesc="#{bindings.Anos1.hints.A2012.tooltip}"
id="ot55">
<af:convertNumber groupingUsed="false"
pattern="#{bindings.Anos1.hints.A2012.format}"/>
</af:outputText>
</af:column>
<af:column sortProperty="#{bindings.Anos1.hints.A2013.name}"
filterable="true" sortable="false"
headerText="2013"
id="c56" width="16%">
<af:outputText value="#{row.A2013}"
shortDesc="#{bindings.Anos1.hints.A2013.tooltip}"
id="ot56">
<af:convertNumber groupingUsed="false"
pattern="#{bindings.Anos1.hints.A2013.format}"/>
</af:outputText>
</af:column>
</af:table>
I've deleted some of the columns because they are all equal and by doing so, you have less problems in reading it.
In my method i have a matchEm but i'm trying to select a column by using this line:
dimAnos.setColumnSelection("A2012");
dimAnos is the binding for my table Anos (Years in Portuguese). I even tried another values fro the columnSelection but i couldn't make it selected. Am i doing anything wrong?
Please help me or give me an idea of how can i do this.
Regards,
Frederico.Hi Frederico,
The method setColumnSelection is meant to set whether your table supports column selection or not. It doesn't select the column. In order to select the column, you need to set the column attribute Selected to true. So I don't know if its an option for you but you can create a binding to all the columns you have in you bean, and then call the method A2012.setSelected(true), and then add a partial target to the table to re render it and show the selected column.
Hope this helps -
How to select even the column names of a table?
Hello All,
Is there a way to select even the column names of a table in the select statement?
My select from a table (say X) is in a SQL* Plus script that gets invoked by application tier and displays data in the application tier window. User's can then copy the data into a spreadsheet and do their processing. However, I need to give them the column names too along with the data.
Thanks,
ChiruIf there is a middle tier that is selecting and
displaying the data, and that's what the users are
copying from, the middle tier would have to address
its presentation of the data to allow users to
include column names. If this is a common task, the
application should probably be modified to give users
the option of downloading the data in a spreadsheet
directly rather than forcing them to copy and paste
data.Thanks for the reply.
The users don't have to copy paste. The application tier has an options in the "Tools" menu item which allows them to copy the entire output to a file (in my case a txt file which is a pipe delimited). Then they have to do text to columns to get the data into each column of the spreadsheet. I could have directly called the stored procedures from the application tier and created ".csv" files and FTP'd them to the user's folders. However, I am having to go this round about because, I am not getting enough support from the LAN team in FTP'ing etc.
OK I'll think of another workaround.
Thanks,
Chiru -
How to set the Selected row and Column in JTable
Hi,
i have a problem like the JTable having one Method getSelectedRow() and getSelectedColumn to know the Selected row and Column but if i want to explicitly set the Selected Row and Column,then there is no such type of Methods.If anybody has any solution then i will be thankful to him/her.
Praveen K SaxenaIs that what you're looking for? :myTable.getSelectionModel().setSelectionInterval(row, row);
myTable.getColumnModel().getSelectionModel().setSelectionInterval(column, column);
Maybe you are looking for
-
Column used in stored procedure
i want to pass table name and column name as a paramter . is it possible to get which procedure using the column
-
BTE for material classification
Hi, im searching for a BTE which trigger modification on material classifications. I found EVENT 4004 and 4005, but they not work. I change classification with mm02 under the classification tab. Have someone an idea if there is an EVENT for this? Or
-
Set Exchange Related Properties task gets rejected
Hi All, During exchange account creation one of task 'Set Exchange Related Properties' is getting rejected with error ' incorrect information provided'. I have tried checking all the attributes in process forms but finding all proper. Create mailbox
-
SRM-PI Integration for Supplier and Company Replication ( EBP-SUS Scenario)
Dear Experts, We are doing a scenario where we are trying to replicate the Company and the Vendors from EBP to SUS via tcode- BBP_SP_COMP_INI and BBP_SP_SUPP_INI. When we are doing this in EBP , at SLG1 it is showing the replication done successfully
-
I am trying to debug java programs in NetBeans IDE but when I start the debugger using F7 Key, it points to some old class file that I had debugged previously. Can somebody suggest what's going on? What setting do I need to do in order to debug my cu