Find Intersection of two array elements in Oracle 9i
How to find intersection of two arrays in pl/sql for Oracle 9i.
it is feasible in 11g using given code but this code is not working in 9i please help....
DECLARE
abc LIST := list(1,2,3,4);
def LIST := list(4,5,6,7);
BEGIN
dbms_output.put_line(format_list(abc MULTISET EXCEPT def));
END;
Thanks in advance.... :)
Argh. Never mind. My coordinates were reversed.
People that made my data set specified the coordinates as lat/long and I didn't question it. I can now see that Oracle expects long/lat instead, so my example works now.
Similar Messages
-
hi
Friends
i am compairing two int arrays of different size & printing the common elements of the both arrays
for example.----
int a[]=a{12,34,56,2,4,5,6,7,8,9,0,6,54,4,3,2,3,5,76,43,78,78,54,32,5,6,44,32};
int b[]=b{11,2,32,45,61,78,34,25,4};
i want output array having elements common to both
int c[]={ 2,32,78,34,4};
& count how many nos are matched
please help me
thanks
shivanandNoone will do it for you, but if you post your code we can help.
You may need to use nested for loops, one to iterate over the first array, then the inner one to iterate over the second array. Make a third array that is as big as your smallest array (or better make a java.util.Set instead) and add any values that are duplicates into that. -
Find and replace several array elements
I have a 2d array and want to subsitute any negitive value with a marker e.g "**" or any indicator which would be identified easily. I am using Labview 5.1
Hi,
The data type of you array is probably numerical. If you haven't already
done this, the first step would be to convert the data to a character
data type. This is easy done with 'Number to Decimal String'. Tie the
output to a 'For Loop' and the search and modify each element in the
array using a combination of 'Search 1D Array', 'Replace Array Subset',
and shift registers.
The first iteration of the 'For Loop' will give you the first index of
the first '-1' found. Use that index value to replace the the '-1' with
your '**'. Increment the index and pass it to the shift register to use
as a starting point for the next interation's search and replace process.
There may be a more "packaged" way of doing this but I just love For
Loops.
Hope this helps ...
- Kevin
In article <[email protected]>,
"Gorelick" wrote:
> I have a 2d array and want to subsitute any negitive value with a marker
> e.g "**" or any indicator which would be identified easily. I am using
> Labview 5.1 -
How to get the intersection of two arraylist containing user defined obj??
How to get the intersection of two arraylist containing user defined obj??
I can easily get the intersection of two array list which containing some simple class(Integer, String). But how to get the intersection of two arrayList which contain user defined object?
Here is the sample code..I can not run this out...anybody can help me? thank you very much..
The correct result should be like this:
2
2
but I can only get this:
2
0
import java.util.*;
public class testRetain{
public static void main(String[] args){
ArrayList a = new ArrayList();
ArrayList b = new ArrayList();
a.add( new dog(1,2,2) );
a.add( new dog(1,2,1) );
System.out.println(a.size() );
b.add( new dog(1,2,2) );
a.retainAll(b);
System.out.println(a.size() );
class dog implements Comparable{
int head;
int arms;
int legs;
dog(int head, int arms, int legs){
this.head = head;
this.arms = arms;
this.legs = legs;
public int compareTo(Object o){
if ( ((dog)o).head > this.head )
return -1;
else if ( ((dog)o).head < this.head )
return 1;
else
return 0;
}@Op. Your classes should override equals and hashCode
Kaj -
Can;t find what is wrong. Trying to add elements in two arrays
Hello everyone
I'm trying to take as input two numbers, convert them to arrays and add all the element of the array one by one. I want the result to be the sum of every element of the array. Let's say array1={1,2,3,4} and array2={2,6,4,3} I want the final result to be 3877.
If the sum of one element of the array is greater than nine, then I would put zero and add 1 to the element on the left.
Here is the code:
import javax.swing.JOptionPane;
public class Main {
public static void main(String[] args) {
String numberOne = JOptionPane.showInputDialog
("Enter the first number: ");
String numberTwo = JOptionPane.showInputDialog
("Enter the second number: ");
//compare string length and make them equal length
int[]n1 = toArray(numberOne); // my first array
int[]n2 = toArray(numberTwo); // my second array
//call the method that ads both strings
int[]finalArray = arrSum(n1,n2);
JOptionPane.showMessageDialog(null, "The sum of the two numbers is: "
+ finalArray);
}//end of main
//method to create an array from a string
public static int[] toArray(String str)
int[]arr = new int[str.length()];
arr[0]=0;
for (int i=1; i<str.length(); i++)
arr= Character.digit(str.charAt(i),10);
return arr;
}//end of toArray
//method to add arrays by elements
public static int[]arrSum (int[]arr1, int[]arr2){
for (int i = arr1.length-1; i >=1; i--)
int sum = arr1[i] + arr2[i];
if (sum > 9)
{ sum -= 10;
arr1[i-1]++;
return arr1;
}//end of arrSum method
}Edited by: designbc01 on Feb 16, 2010 1:15 AMThe best advice I can give you is to break your problem up into smaller pieces. First, focus on a method that converts an input String into an array. When you have that working perfectly, then focus on creating a method that "adds" two arrays with the logic you described. When you have that working perfectly, then combine the two different pieces.
Why does your for loop in toArray( ) start with 1? The first index of a String, array, or pretty much anything else, is zero. -
I have two arrays of points, when i plot them there´s an intersection point, but this point doesn´t belong to any arrays. I need to find the both value of this point, X and Y. I attached my problem in a very simple example. Thanks.
Attachments:
arrays_plot.vi 25 KBAlthough this doesn't directly answer your question , I've attached a VI that will hopefully give you a start and point you in the right direction. It generates a Boolean array that indicates between which indecies an intersection has taken place. Then, all you need to do is use triganometry to work out exactly what the intersection point is.
Copyright © 2004-2015 Christopher G. Relf. Some Rights Reserved. This posting is licensed under a Creative Commons Attribution 2.5 License.
Attachments:
2x1D_Array_Intersections.vi 36 KB -
Write two functions to find the the number of elements in a linked list?
I am trying to Write two functions to find the the number of elements in a linked list. One method using recursion and One method using a loop...
//The linked List class is Represented here.
public class lp {
public int first;
public lp rest;
public lp(int first1, lp rest1)
first = first1;
rest = rest1;
The program i wrote so far is
import java.util.*;
import linklist.lp;
public class listCount{
//loop function
public static void show_list(lp list)
int counter = 0;
while(list != null)
list = list.rest;
counter++;
System.out.println ("length computed with a loop:" + counter);
//recursive function
public static int recursive_count(lp list)
if (list.first == null)
return 0;
else
return recursive_count(list.rest) + 1;
//main method
public static void main (String args[])
lp list1 = new lp(1, new lp(2, new lp(3, null)));
show_list(list1);
System.out.println("length computed with a recursion:" +
recursive_count(list1));
at the if (list.first == null) line i get the error " incomparable types:
int and <nulltype>" I know this is a beginners error but please
help...What should I do?byte, char, short, int, long, float, double, and boolean are primitives, not objects. They have no members, you cannot call methods on them, and they cannot be set to or compared with null.
-
How do I find the total number of elements in a multi dim array
How do I find the total number of elements in a single or multi dim array?
For example, a 2x3 array has 6 elements, and a 2x3x4 has 24. How do I compute this very easily - is there a single VI that does this?
David
Solved!
Go to Solution.Use "array size" (array palette) followed by "multiply array elements" (numeric palette)
(Works also equally well for 3D arrays and higher)
For a 1D array, just use "array size".
Message Edited by altenbach on 02-05-2009 05:57 PM
LabVIEW Champion . Do more with less code and in less time .
Attachments:
NumberOfElements.png 3 KB -
Combining two StringBuffer array elements into a single array element
I just need to know how to combine two stringBuffer array elements into one
StringBuffer ciphertext [] = new StringBuffer[2];
StringBuffer s0 = new StringBuffer("11011111111110001001101110110101");
StringBuffer s1 = new StringBuffer("00010011001101000101011101111001");
ciphertext[0] = s0;
ciphertext[1] = s1;
ciphertext[2] = ciphertext[0].append(ciphertext[1]);I get an array index out of bounds exception:2
ThanksStringBuffer ciphertext [] = new StringBuffer[3]; // legal index values are: 0,1,2
-
Find intersection/union between two maps
Hello.
I'm trying to find out state changes between two maps.
I have two maps A and B, what I need to do is to find keys in A that doesn't exists in B and keys in B that doesn't exist in A.
If keys exists in both A and B I want to compare the values of those keys.
What would be the most effective way to implement this.
My first plan was to loop through the keys in A to find in B and loop through keys in B and find in A but I guess there is a more effective algorithm.
I'm also thinking about using java.util.Collections to find intersection/union between the keys in the maps but then I need to do a lookup in both
maps.
Any suggestions?
Regards
/FredrikFredrik wrote:
My scenario is this:
I'm writing a Swing app for administration of a clustered environment.
The keys in the map contains ip-address of cluster nodes, the value is a status/state for a node in the cluster.
I want to signal state change for the node in the GUI.
A state change happens if there is a new node in the cluster which means a new entry in the map since last checked or if a node
leaves the cluster a remove of entry in the map since last checked or if the status/state for the entry/ip has changed since last checked.
Regards
/FredrikBy your above senario, i don't think you have two objects of Map, there is only one object and you want to signal the change in GUI, whenever a object is added , removed or only value is changed (Key is same) to the Map.
Then i'll suggest below things:
1) to override hashcode and equal method. (Because whenever the put or putAll methods are called the hashcode and equal method checks in the bucket for equal and similar hashcode, and if its equal , then change the GUI for the existing Map).
2) As suggested earlier, override remove methods. (Whenever any object is removed, accordingly you can change the GUI).
3) As suggested earlier, override put and putAll method( whenever a new object is added, accordingly you can change the GUI).
And for this, i don't think you have iterate through the Map. -
Printing every possible pair combination of elements in two arrays??
Hi there,
I'm trying to implement the problem of printing every possible pair combination of elements in two arrays. The pattern I have in mind is very simple, I just don't know how to implement it. Here's an example:
g[3] = {'A', 'B', 'C'}
h[3] = {1, 2, 3}
...code...??
Expected Output:
A = 1
B = 2
C = 3
A = 1
B = 3
C = 2
A = 2
B = 1
C = 3
A = 2
B = 3
C = 1
A = 3
B = 1
C = 2
A = 3
B = 2
C = 1
The code should work for any array size, as long as both arrays are the same size. Anybody know how to code this??
Cheers,
Seannot a big fan of Java recursion, unless tail recursion, otherwise you are bound to have out of stack error. Here is some generic permutation method I wrote a while back:
It is generic enough, should serve your purpose.
* The method returns all permutations of given objects. The input array is a two-dimensionary, with the 1st dimension being
* the number of buckets (or distributions), and the 2nd dimension contains all possible items for each of the buckets.
* When constructing the actual all permutations, the following logic is used:
* take the following example:
* 1 2 3
* a d f
* b e g
* c
* has 3 buckets (distributions): 1st one has 3 items, 2nd has 2 items and 3rd has 2 items as well.
* All possible permutaions are:
* a d f
* a d g
* a e f
* a e g
* b d f
* b d g
* b e f
* b e g
* c d f
* c d g
* c e f
* c e g
* You can see the pattern, every possiblity of 3rd bucket is repeated once, every possiblity of 2nd bucket is repeated twice,
* and that of 1st is 4. The number of repetition has a pattern to it, ie: the multiplication of permutation of all the
* args after the current one.
* Therefore: 1st bucket has 2*2 = 4 repetition, 2nd has 2*1 = 2 repetition while 3rd being the last one only has 1.
* The method returns another two-dimensional array, with the 1st dimension represent the number of permutations, and the 2nd
* dimension being the actual permutation.
* Note that this method does not purposely filter out duplicated items in each of given buckets in the items, therefore, if
* is any duplicates, then the output permutations will contain duplicates as well. If filtering is needed, use
* filterDuplicates(Obejct[][] items) first before calling this method.
public static Object[][] returnPermutation(Object[][] items)
int numberOfPermutations = 1;
int i;
int repeatNum = 1;
int m = 0;
for(i=0;i<items.length;i++)
numberOfPermutations = numberOfPermutations * items.length;
int[] dimension = {numberOfPermutations, items.length};
Object[][] out = (Object[][])Array.newInstance(items.getClass().getComponentType().getComponentType(), dimension);
for(i=(items.length-1);i>=0;i--)
m = 0;
while(m<numberOfPermutations)
for(int k=0;k<items[i].length;k++)
for(int l=0;l<repeatNum;l++)
out[m][i] = items[i][k];
m++;
repeatNum = repeatNum*items[i].length;
return out;
/* This method will filter out any duplicate object in each bucket of the items
public static Object[][] filterDuplicates(Object[][] items)
int i;
Class objectClassType = items.getClass().getComponentType().getComponentType();
HashSet filter = new HashSet();
int[] dimension = {items.length, 0};
Object[][] out = (Object[][])Array.newInstance(objectClassType, dimension);
for(i=0;i<items.length;i++)
filter.addAll(Arrays.asList(items[i]));
out[i] = filter.toArray((Object[])Array.newInstance(objectClassType, filter.size()));
filter.clear();
return out; -
How to find point of intersection of two geometry?
Hello,
Could someone give suggestion about how can i find point of intersection of two geometry?
I need just point. (x,y,z)
Thanksdeclare
-- Local variables here
i integer;
l_geometry mdsys.sdo_geometry;
i integer;
l_x number;
l_y number;
l_cx varchar2(500);
l_vertexes integer;
begin
-- Test statements here
for wrk in (SELECT SDO_GEOM.SDO_INTERSECTION(SDO_GEOMETRY(2002,
1,
NULL,
SDO_ELEM_INFO_ARRAY(1,
2,
1),
SDO_ORDINATE_ARRAY(1,2,3,2,3,3,0,3,0,5,5,5)),
SDO_GEOMETRY(2002,
1,
NULL,
SDO_ELEM_INFO_ARRAY(1,
2,
1),
SDO_ORDINATE_ARRAY(2,1,2,10)),
0.005) as qq
FROM dual where SDO_RELATE(z.geometry,
SDO_GEOMETRY(2002,
1,
NULL,
SDO_ELEM_INFO_ARRAY(1, 2, 1),
SDO_ORDINATE_ARRAY(1,2,3,2,3,3,0,3,0,5,5,5)),
'mask=anyinteract') = 'TRUE')
loop
l_geometry := wrk.qq;
dbms_output.put_line('count: '||l_geometry.SDO_ORDINATES.count);
l_vertexes := trunc(l_geometry.SDO_ORDINATES.count / 2);
for i in 1 .. l_vertexes loop
l_x := l_geometry.SDO_ORDINATES(2 * i - 1);
l_y := l_geometry.SDO_ORDINATES(2 * i);
l_cx := to_char(l_x) || ' ' || to_char(l_y);
dbms_output.put_line(l_cx);
if i <> l_vertexes then
dbms_output.put_line('');
end if;
end loop;
end loop;
end;
output
count: 6
2 5
2 3
2 2
Thanks for help:)
Edited by: SVV on 16.11.2009 4:54
Edited by: SVV on 16.11.2009 9:31 -
Sort two dimentional array element
Hi,
i want sort 2dimentional array element ,
suppose i have matrix like this
[ 5,2,6]
[ 3,1,9]
[8,7,2]
then i want to answer like that
[ 1,2,2]
[3,5,6]
[7,8,9][How to ask questions the smart way|http://catb.org/~esr/faqs/smart-questions.html]
[How To Get Good Answers To Your Questions|http://www.tek-tips.com/viewthread.cfm?qid=473997]
db -
Unlimited number of array elements, help please!
Hi everyone,
I have written this code for comparing two arrays but i don't know how to accept all types array lengths. Now i am limited to 5 elements and i want it to accept the the users desired number of elements. How should i do?
import java.util.*;
class console
public static void main (String[] args)
ConsoleInput ci = new ConsoleInput();
System.out.print("Hur m�nga Vektorer ska lagras? ");
int antal = ci.readInt();
if (antal<2)
System.out.println("Du beh�ver 2 st vektorer");
System.out.println("Hur m�nga element per vektor?");
int antalelement = ci.readInt();
System.out.println();
for (int j=0 ; j<antal-1; j++)
System.out.print("Ange vektor1: ");
int vektor = ci.readInt();
int vektor3 = ci.readInt();
int vektor2 = ci.readInt();
int vektor4 = ci.readInt();
int vektor5 = ci.readInt();
int[] vektor1 = new int[] {vektor,vektor3, vektor2, vektor4, vektor5};
int langd = vektor1.length;
System.out.print("Ange vektor2: ");
int element1 = ci.readInt();
int element2 = ci.readInt();
int element3 = ci.readInt();
int element4 = ci.readInt();
int element5 = ci.readInt();
int[] vektor21 = new int[] {element1,element2,element3, element4, element5};
Arrays.sort (vektor21);
int kopiera = vektor1.length + vektor21.length;
int[] nyvektor = new int [kopiera];
for(int i = 0; i < vektor1.length; i++)
nyvektor[i] = vektor1;
for(int i = 0; i < vektor21.length; i++)
nyvektor[vektor1.length + i] = vektor21[i];
System.out.print("Unionen ar: ");
verktyg.sort(nyvektor);
int counter = 0;
for(int k = 1; k < nyvektor.length; k++)
if(nyvektor[k] == nyvektor[k-1])
counter++;
int[] union = new int[nyvektor.length - counter];
union[0] = nyvektor[0];
int b = 1;
for(int k = 1; k < nyvektor.length; k++)
if(nyvektor[k] != nyvektor[k-1])
union[b] = nyvektor[k];
b++;
for (int h = 0; h<union.length; h++)
System.out.print(" " +union[h]);
System.out.println();
System.out.print("Intersection ar: ");
Arrays.sort(nyvektor);
int counter1= 0;
for(int i = 1; i < nyvektor.length; i++)
if(nyvektor[i] == nyvektor[i-1])
counter1++;
int[] intersection = new int[counter1];
//c[0] = C[0];
int a = 0;
for(int i = 1; i < nyvektor.length; i++)
if(nyvektor[i] == nyvektor[i-1])
intersection[a] = nyvektor[i];
a++;
for(int i=0; i<intersection.length; i++)
System.out.print(" " +intersection[i]);
System.out.println();
System.out.println("Differensen ar: ");
Arrays.sort(nyvektor);
int counter2 = 0;
for(int i = 1; i < nyvektor.length; i++)
if(nyvektor[i] == nyvektor[i-1])
counter2++;
int[] difference = new int[vektor1.length-counter];
boolean falsk = false;
int k=0;
for(int i = 0; i < vektor1.length; i++)
for(int d=0; d<vektor21.length; d++)
if(vektor1[i]!=vektor21[d])
falsk = true;
else
falsk = false;
break;
if(falsk)
difference[k] = vektor1[i];
k++;
for(int i=0; i<difference.length; i++)
System.out.print(difference[i] + " ");How about this?import java.util.*;
import java.io.*;
class DynamicVectors
public static void main (String[] args)
BufferedReader console
= new BufferedReader (new InputStreamReader (System.in));
String consoleLine = "";
StringTokenizer tokenizer;
System.out.print ("Hur m�nga Vektorer ska lagras? ");
try
consoleLine = console.readLine();
catch (IOException ioe)
System.out.println (ioe);
tokenizer = new StringTokenizer (consoleLine);
int antal = Integer.parseInt (tokenizer.nextToken());
if (antal<2)
System.out.println("Du beh�ver 2 st vektorer");
for (int j=0 ; j<antal-1; j++)
int vektorSize;
System.out.print("Ange vektor1: ");
try
consoleLine = console.readLine();
catch (IOException ioe)
System.out.println (ioe);
// Here's where the fun starts...
tokenizer = new StringTokenizer (consoleLine);
vektorSize = tokenizer.countTokens();
int[] vektor1 = new int [vektorSize];
for (int i = 0; i < vektor1.length; ++i)
vektor1 = Integer.parseInt (tokenizer.nextToken());
// ...and that's all there is to it.
int langd = vektor1.length;
System.out.print("Ange vektor2: ");
try
consoleLine = console.readLine();
catch (IOException ioe)
System.out.println (ioe);
// Here's where the fun starts...
tokenizer = new StringTokenizer (consoleLine);
vektorSize = tokenizer.countTokens();
int[] vektor21 = new int [vektorSize];
for (int i = 0; i < vektor21.length; ++i)
vektor21 [i] = Integer.parseInt (tokenizer.nextToken());
Arrays.sort (vektor21); -
How to join two arrays together?
I have the following type
type TVarcharArr is table of varchar(4000) index by binary_integer;I have a procedure that passes in two separate arrays as:
p_account_number in TVarcharArr,
p_product_system_code in TVarcharArrThese arrays are related (they will have the same number of elements), the contents would be as follows:
Account Number Product System Code
123 ABC
456 DEF
789 GHII can use TABLE(CAST to turn each of these arrays into a table, but how do I join these two arrays together so that they become a single table with two columns? Or if I CAST them as TABLEs, how can I join these two tables together - is there some way of using the index to facilitate the join?
Cheers
RichardYou are right, I do need to convert the arrays first to use TABLE(CAST, and I do have my concerns about the use of rownum.
Here's the test case I built to test what I'm doing, incorporating the rownum solution:
declare
type TVarcharArr is table of varchar(4000) index by binary_integer;
v_arr TVarcharArr;
v_tab tchartab := tchartab();
v_arr2 TVarcharArr;
v_tab2 tchartab := tchartab();
begin
v_arr(1) := 'ABC';
v_arr(2) := 'DEF';
v_arr(3) := 'GHI';
v_arr2(1) := '123';
v_arr2(2) := '456';
v_arr2(3) := '789';
v_tab.extend(v_arr.Count);
for i in v_arr.first .. v_arr.last
loop
v_tab(i) := v_arr(i);
end loop;
v_tab2.extend(v_arr2.Count);
for i in v_arr2.first .. v_arr2.last
loop
v_tab2(i) := v_arr2(i);
end loop;
for rec in (with w_acct as
(select rownum rn, a.column_value acol
from table(cast(v_tab as tchartab)) a
w_prod as
(select rownum rn, b.column_value bcol
from table(cast(v_tab2 as tchartab)) b
select acol,bcol
from w_acct a,
w_prod b
where a.rn = b.rn) loop
DBMS_OUTPUT.PUT_LINE ( 'rec = ' || rec.acol || '|'|| rec.bcol );
null;
end loop;
end;It does return the correct result - but can it be trusted to be consistent - does the rownum in an array suffer the same problems as the rownum from a regular select? I'm guessing it's too risky to find out.
In essence, I'm getting two arrays and I'm trying to join them together so that I can CAST them as a table. (And I know the real question is why isn't it just one array of records with two elements - but sometimes you have to work with what you're given)
Maybe you are looking for
-
How do I make a flow chart in pages
How can I make a simple flow chart in pages for a lesson plan? Or can I?
-
I need to buy a Windows PC Notebook and want to make sure there are adapters or if necessary video cards for it to run my 23" Apple Cinema Display. (I'd prefer not having to get a separate monitor for the pc windows only jobs). If anyone else does th
-
I live in Holland and I have downloaded all my apps here! I have als some UK apps. My ipad seems to think I am linked to the UK store, and will not update or download anything. It keeps on telling me to switch to the dutch store. How do I go about do
-
JFormattedTextField insert/overwrite toggle
The insert/overwrite toggle seems not to work unless I do an InputMap/ActionMap myself. Am I doing something wrong, or is this the way it's supposed to be? With all the built-in actions, I was surprised that I had to implement insert/overwrite myself
-
hi every one while i configured my webutil (specially when i assign sign_webutil for frmwebutil.jar and jacob.jar) i got this message C:\ordv\forms\webutil>sign_webutil.bat C:\ordv\forms\java\frmwebutil.jar Generating a self signing certificate for k