Retrieve as many duplicate records as a value stored in one of the columns
Hi,
I have a peculiar requirement where I want multiple copies of rows the count of which is determined by one of the column values:
create table test (id number, value number, data varchar2(100));
insert into test values (1,5,'one');
insert into test values (2,2,'two);
insert into test values (3,3,'three');
insert into test values (4,4,'four');
insert into test values (5,5,'five');
select * from test where id=3;
I get:
id,value,data
3,3,three
I want:
id,value,data
3,3,three_1
3,3,three_2
3,3,three_3
i.e. Althought there is ONLY ONE row for the id=3, but as the column value=3, i want 3 rows from this table (all identical) except the last column to which I append a running sequential number.
How to do that?
Thanks.
You have still pipelined function :
SQL> create or replace type TypeTest as object (id number, value number, data varchar2(100));
2 /
Type created.
SQL>
SQL> create or replace type ListTest as table of TypeTest;
2 /
Type created.
SQL>
SQL> create or replace function TblTest(p_id number default null)
2 return ListTest
3 pipelined
4 is
5 begin
6 for x in (select id, value, data from test where id = nvl(p_id,id)) loop
7 for i in 1.. x.value loop
8 pipe row (TypeTest(x.id, x.value, x.data||'_'||to_char(i)));
9 end loop;
10 end loop;
11 return;
12 end;
13 /
Function created.
SQL> show err
No errors.
SQL>
SQL> select * from table(TblTest(3));
ID VALUE DATA
3 3 three_1
3 3 three_2
3 3 three_3
SQL> select * from table(TblTest);
ID VALUE DATA
1 5 one_1
1 5 one_2
1 5 one_3
1 5 one_4
1 5 one_5
2 2 two_1
2 2 two_2
3 3 three_1
3 3 three_2
3 3 three_3
4 4 four_1
4 4 four_2
4 4 four_3
4 4 four_4
5 5 five_1
5 5 five_2
5 5 five_3
5 5 five_4
5 5 five_5
19 rows selected.
SQL> Nicolas.
Similar Messages
-
Does Premier have an Screen recorder if not does adobe has one in the Cloud ?
Basically Does Premier have an Screen recorder if not does adobe has one in the Cloud ?
Thanks !Adobe Captivate is the one but it's not in the Cloud. Camstudio is also very good at that.
-
Master data failed with error `too many duplicate records'
Dear all
below is error message
Data records for package 1 selected in PSA -
error 4 in the update
LOng text is giving as below
Error 4 in the update
Message no. RSAR119
Diagnosis
The update delivered the error code 4.
Procedure
You can find further information on this error in the error message of the update.
WOrking on BI - 7.0
any solutions
Thanks
satish .aHi,
Go through these threads, they have same issue:
Master data load: Duplicate Records
Re: Master data info object - duplicate records
Re: duplicate records in master data info object
Regards
Raj Rai -
How to Set column value in SO matrix , if the column is not visible.
Hi,
We are trying to set value in to a column from sales order matrix with the below mentioned code
((SAPbouiCOM.EditText)oMat.Columns.Item("U_TWBS_AC_BaseEntry").Cells.Item(pVal.Row).Specific).String
it will throw an u201CForm Item is not editable u201C error if the column ("U_TWBS_AC_BaseEntry") visible is set to false through form settings.
how can we solve the issue,can we use any DI object in order to reset the form settings.
Thanks & RegardsHi
Try and make the column visible then set the value and make it invisible then
Hope this helps
Regards
Vivek -
How to enter a value versus picking one from the pop-up menu?
I am new to numbers and am using version 3.5.2. I understand one can define a Pop-Up for cell value selection, but what if I want to also be able to specify a value that is not in the pull down? I thought "start with blank" would do the trick, but it won't let me enter any values. Thanks in advance for your suggestions!
Hi Sultry,
If your entry is a one time deal you could just delete the cells value and type in your choice. If you want to update your popup you need ot redefine its values. And then of course replace your old popups with your new one.
quinn -
Show values of filters used in the columns
hi experts
Probably it is very simple but I don´t find how to do it. I would like to see in the query the values of the filters used to calculate the columns.
I.e. One column is the amount of the net income for one month. The month is asked when I execute the query but when the query is executed I don´t see in the screen the month used.
Thanks and regardsLuis,
I think you are wanting to use text variables on the columns to get the values of the month. To do this go into the column name and type &. It will prompt you to select, create, or edit a text variable. You can create a variable here to display the value of the characteristic your variable is on (i.e Month).
Hope this helps,
Rusty -
Query - Remove duplicate records based on value of one field
Hi,
Pleae see the data below,
how to remove records when its count 0
AND those records (name ) repeat with count > 0
existing data
name loc count
aaa a1 10
aaa a1 0
bbb b1 0
ccc c1 0
dcc d1 11
dcc d1 0
required output
name loc count
aaa a1 10
bbb b1 0
ccc c1 0
dcc d1 11
remove these records -
aaa a1 0
dcc d1 0Thanks.i assume that loc always corresponds to name. So to find the rows to remain is just a simple group by
with data as(
select 'aaa' name,'a1' loc,10 count from dual union all
select 'aaa','a1',0 from dual union all
select 'bbb','b1',0 from dual union all
select 'ccc','c1',0 from dual union all
select 'dcc','d1',11 from dual union all
select 'dcc','d1',0 from dual )
select
name
, loc
, max(count) cnt
from data
group by
name
, loc
order by
name
, loc
NAME LOC CNT
aaa a1 10
bbb b1 0
ccc c1 0
dcc d1 11to find the other is just a minus
with data as(
select 'aaa' name,'a1' loc,10 count from dual union all
select 'aaa','a1',0 from dual union all
select 'bbb','b1',0 from dual union all
select 'ccc','c1',0 from dual union all
select 'dcc','d1',11 from dual union all
select 'dcc','d1',0 from dual )
select name,loc,count from data
minus
select
name
, loc
, max(count) cnt
from data
group by
name
, loc
order by
name
, loc
NAME LOC COUNT
aaa a1 0
dcc d1 0so a delete would be
delete from data
where
(name,loc,count)
in
(select name,loc,count from data
minus ..regards -
I have a hard drive with 800,000+ photos in it, many are duplicates after I have made multiple back-ups to different drives over the years and then transferred all the photos to this new drive. The photos are located in different folders but are all in the same hard-drive. How do a import the photos in the easiest/fastest way? How will they get sorted, by date? Is there anyway that I could delete the duplicates without losing photos? I have many photos with the same file name (but from different cameras), tumbnails, edited photos etc.
Very thankful for your assistance!Hi,
You can import photos from multiple folders.
Just click File >> Get Photos and Videos >> From Files and Folders
Now select the folders you want to import photos from (they should be at same level in the directory, say all folders in My Pictures) using Ctrl+Click, tick the checkbox for 'Get Photos from subfolders' if not already checked and then click 'Get Media'.
Hope that will help
Thanks
andaleeb -
Sorting the table records based on date (stored as string in the database)
Iam storing the date as string(varchar2) in the database.
Date format: DD-MMM-YYYY hh:mm:ss am/pm
example: 12-MAY-1984 11:12:45 AM
now i have to sort the records in such a way that recent records should be displayed first, then past records.
i need help reagrdingStep one: Select from the table
Step two: Convert the string to a date
Step three. Order on this converted date descending (= recenct records first) -
Hi,
I am providing support to one of our clients, where we have jobs scheduled to load the data from the tables in the source database to the destination database via SSIS packages. The first time load is a full load where we truncate all the tables in the destination
and load them from the source tables. But from the next day, we perform the incremental load from source to destination, i.e., only modified records fetched using changed tracking concept will be loaded to the destination. After full load, if we run the incremental
load, the job is failing with the error on one of the packages "Violation of PRIMARY KEY constraint. Cannot insert duplicate key in object '<tablename>'. The duplicate key value is <1234>, even though there are no duplicate records. When we
try debugging and running the failing package, it runs successfully. We are not able to figure out why the package fails and when we run the next day it runs successfully. Request you to help me in this regard.
Thank you,
Bala Murali Krishna Medipally.Hi,
I am providing support to one of our clients, where we have jobs scheduled to load the data from the tables in the source database to the destination database via SSIS packages. The first time load is a full load where we truncate all the tables in the destination
and load them from the source tables. But from the next day, we perform the incremental load from source to destination, i.e., only modified records fetched using changed tracking concept will be loaded to the destination. After full load, if we run the incremental
load, the job is failing with the error on one of the packages "Violation of PRIMARY KEY constraint. Cannot insert duplicate key in object '<tablename>'. The duplicate key value is <1234>, even though there are no duplicate records. When we
try debugging and running the failing package, it runs successfully. We are not able to figure out why the package fails and when we run the next day it runs successfully. Request you to help me in this regard.
Thank you,
Bala Murali Krishna Medipally.
I suspect you are trying to insert modified records instead of updating. -
How to delete duplicate records in 10 G.
how to delete duplicate records in 10 G.
--Here is one way to do it using a second table
create table temp1
(col1 char(1));
--Table created.
insert into temp1 (col1) values('A');
insert into temp1 (col1) values('B');
insert into temp1 (col1) values('B');
--1 row created.
--1 row created.
--1 row created.
create table temp2 as select distinct * from temp1;
--Table created.
--now you have a second table with no duplicates
--truncate your old table
truncate table temp1;
--Table truncated.
--and reload it with data from the new table
insert into temp1 select * from temp2;
--2 rows created.
--then drop the temp2 table
drop table temp2 -
InfoObject ZPRODGRP does not fulfill ref. integrity in record 39435 in valu
Hi Gurus,
There is a query which is related to master data. While updating the infocube we are getting the error InfoObject ZPRODGRP does not fulfill ref. integrity in record 39435 in value 58240, we have maintained the ref. integrity value 58240 in BW but still getting the same error message.
Please help me out in this issue.Hi Bhanu Gupta,
I have checked it in the SID Table of Product Group /BIC/SZPRODGRP it exists in the SID table, but when i try to look into the CUBE with the particular product group it says that it does not exist with that value.
I have seen many of your replies which are quite knowledgeble.
Please advise me soon what is to be done. -
Hi every one,
I have created a view on tables MVKE,MBEW and T001(just for ref key(waers)) with the fields
MANDT
MATNR
VKORG
VTWEG
MVGR4
STPRS
BWKEY
WAERS
the data in the base tables is proper.When I am viewing the data from VIEW it is presenting too many duplicate records.Have any one faced this problem?
Please share ur thought to resolve my problem, your help would be highly appreciated.
Thanks & Regards
Reddy Dasari.thanq
-
Removing duplicates record form a column
I ran this query to populate a field with random numbers but it keeps populating with some duplicate records. Any idea how I can remove the duplicates?
UPDATE APRFIL
SET ALTATH = CONVERT(int, RAND(CHECKSUM(NEWID())) * 10000);Prashanth,
You are correct the update does create the non-dupes records, it just doesn't insert them into the ALTATH field. I verify by running the select altath from aprfil table and the results are not the same records display after the updates. I hope I am clear
enough and thanks for your efforts.
Can you give example of a case where it doesnt work? It may be that values in actual were not duplicates due to presence of some unprintable characters like space characters.
Please Mark This As Answer if it solved your issue
Please Vote This As Helpful if it helps to solve your issue
Visakh
My Wiki User Page
My MSDN Page
My Personal Blog
My Facebook Page -
Array permitting duplicate record
Hi,
I have string array like below:
String strArr[] = {"style1","style2","style2","style4"};
In this string array index 1 and index 2 is having same value which is style2.
My target is to generate key(system time) for each value as below:
"key1" : "style1"
"key2" : "style2"
"key2" : "style2" //Here I want to reuse already generated key2 in place of creating new key like key3
"key4" : "style4 "
At last generated array should be:
["key1" : "style1",
"key2" : "style2",
"key2" : "style2" , //Here I want to retain this duplicate record
"key4" : "style4 "]
Value position is also important, like below array is not accepted:
["key2" : "style2",
"key1" : "style1",
"key2" : "style2" ,
"key4" : "style4 "]
I am struggling to achieve this.
Please guide me to achieve this!
Regards
My Efforts:
static Map<String, String> m = new HashMap<String, String>();
static int[] intarr;
static List<Integer> list = new ArrayList<Integer>();
public static void main(String[] args) throws InterruptedException {
String strArr[] = {"style1","style2","style2","style4"};
/**Find Index having duplicate value*/
for(int i=0; i<strArr.length; i++){
for(int j=0; j<strArr.length; j++){
if((strArr==strArr[j])&&(i!=j)){
list.add(i);
String newclass = "class"+new Date().getTime();//
//Thread.sleep(1000);//
m.put(newclass, strArr[i]);//
break;
for(int i : list){
//System.out.println("Duplicate value found at Index:: "+i);
/*String newduplicateclass = "class"+new Date().getTime();
Thread.sleep(1000);
for(int i=0; i<strArr.length; i++){
if(list.contains(i)){
System.out.println("i="+i);
m.put(newduplicateclass, strArr[i]);
}else{
String newclass = "class"+new Date().getTime();
m.put(newclass, strArr[i]);
Thread.sleep(1000);
System.out.println(m);
But want to do with smartest way using few lines of code.
Edited by: 898087 on Mar 17, 2012 3:16 AM@TPD Thanks for your help! It gave me a speed up.
At last I am done with what I wanted and below is that code:
public static void main(String[] args){
String strArr[] = {"style7","style1","style5","style7","style2","style1","style2","style7","style2","style5","style7","style7"};
Set<String> set = new HashSet<String>();
for(int i=0; i<strArr.length; i++){
set.add(strArr);
Object objArr[] = set.toArray();
int counter = 0;
Map<String, Integer> map = new HashMap<String, Integer>();
for(int j=0; j<objArr.length; j++){
map.put(objArr[j].toString(), counter);
counter++;
JSONArray jsonArr = new JSONArray();
JSONObject jsonObj;
for(int i=0; i<strArr.length; i++){
jsonObj = new JSONObject();
jsonObj.put(strArr[i], map.get(strArr[i]));
jsonArr.add(jsonObj);
System.out.println(jsonArr);
//OUTPUT: [{"style7":0},{"style1":2},{"style5":1},{"style7":0},{"style2":3},{"style1":2},{"style2":3},{"style7":0},{"style2":3},{"style5":1},{"style7":0},{"style7":0}]
Maybe you are looking for
-
How to select LOV items from edit report / form?
I'm new to ApEx 3 with very little web developer knowledge. I have a create record form (Page1) that uses single-select and multi-select LOVs and correctly inserts the data into a table. I have a basic report (tabular form) (Page2) that shows the rec
-
"The application SyncServer quit unexpectedly"
I'm looking for help. I have a recently new 24" iMac. About 3 times a day the computer comes to a halt I can't do anything (basically freezes). After about 5 mins I get an error stating "The application SyncServer quit unexpectedly". I looked at othe
-
Hi, The ace config contains more than 20 service-policy and many VIP addresses. The ace works in L3 mode. We have to restrict one of VIP traffic to 6 node only from public side. How can i restrict the traffic with ACL in the L3 class map. different
-
Hi, I'm having trouble with mySQL about the subselect, even setting ultraDevHack to true. I'm using mySQL 3.23.53 with JDBC driver mysql-connector-java-2.0.14-bin.jar Any suggestions ? Thanks.
-
Prime InfraStructure 2.2 - Support of Nexus 3524 model
Hello Community, I am trying to find but I am not sure if Nexus 3524 is supported on Cisco Prime Infrastructure 2.2 Please can someone clarify? thanks in advance, G