473,379 Members | 1,220 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

How to rename each column values with distinct prime number?

Hello Every body:

i want rename a table values in bulk as...each colum value(cell) is assing a unique value...
For example:

Table looks like

column1, column2,column3,column4
Milk,sugar,butter,cheez
null,sugar,butter,null

now when i run the procedure...
it will change my table values as

column1, column2,column3,column4
2,3,4,5
0,2,3,0

i-2 replacing each coloumn value with a unique prime value...

thnx BR amad...
Jan 21 '11 #1
3 2329
amitpatel66
2,367 Expert 2GB
Try this:

Expand|Select|Wrap|Line Numbers
  1. SQL> ed
  2. Wrote file afiedt.buf
  3.  
  4.   1  with t as (SELECT 'MILK' col1,'SUGAR' col2,'BUTTER' col3,'CHEESE' col4 from dual
  5.   2  union select NULL,'SUGAR','BUTTER',NULL from dual),
  6.   3  s as (SELECT col1,(CASE WHEN col1 IS NULL THEN 0 ELSE ROW_NUMBER() OVER(ORDER BY col1) END ) rn
  7.   4  (SELECT col1 from t
  8.   5  UNION
  9.   6  select col2 from t
  10.   7  UNION
  11.   8  SELECT col3 from t
  12.   9  union
  13.  10  select col4 from t))
  14.  11  select nvl(C1,0),nvl(c2,0),nvl(c3,0),nvl(c4,0) FROM
  15.  12  (SELECT (SELECT rn FROM s WHERE col1 = x.col1) c1,
  16.  13  (SELECT rn FROM s WHERE col1 = x.col2) c2,
  17.  14  (SELECT rn FROM s WHERE col1 = x.col3) c3,
  18.  15  (SELECT rn FROM s WHERE col1 = x.col4) c4
  19.  16* FROM t x)
  20. SQL> /
  21.  
  22.  NVL(C1,0)  NVL(C2,0)  NVL(C3,0)  NVL(C4,0)
  23. ---------- ---------- ---------- ----------
  24.          3          4          1          2
  25.          0          4          1          0
  26.  
  27. SQL> 
  28.  
Jan 21 '11 #2
Rabbit
12,516 Expert Mod 8TB
4 is not a prime number.
Jan 21 '11 #3
amitpatel66
2,367 Expert 2GB
I just missed that it has to be a prime number. In that case you will need to store the list of prime numbers seperately and associate those with the value. Else if single query is built to generate prime numbers as well, it would be not so good performance wise.
Jan 26 '11 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

36
by: Dag | last post by:
Is there a python module that includes functions for working with prime numbers? I mainly need A function that returns the Nth prime number and that returns how many prime numbers are less than N,...
11
by: lostinpython | last post by:
I'm having trouble writing a program that figures out a prime number. Does anyone have an idea on how to write it? All I know is that n > 2 is prim if no number between 2 and sqrt of n...
11
by: don | last post by:
Ok, this is a homework assignment, but can you help me out anyway...... I need a routine for figuring out if a number inputted by the user is a prime number or not...... all I'm asking for is Not...
32
by: Cmorriskuerten | last post by:
HI, is this is this solution to test if a number is a prime number or not: /* * Is n a prime number? * Return TRUE (1): n is a prime number * Return FALSE (0): n is a *not* a prime number...
4
by: SweetLeftFoot | last post by:
Hello, i have designed some code that works out the first 250 prime numbers and prints them to the screen. However i need to implement 2 functions, one of which returns a 1 if the number is a prime...
10
by: Joel Mayes | last post by:
Hi All; I'm teaching myself C, and have written a prime number generator. It is a pretty inefficient implementation of the Sieve of Eratosthenes to calculate primes up to 1,000,000. If anyone...
7
by: Caffiend | last post by:
Well, I've been picking at learning python, got tired of reading, and figured I'd try to replicate my prime number generator I wrote (with much TSDN forum help) in C++. I've hit a stumbling block......
2
by: QHorizon | last post by:
Hello, I'm new to Python (I've learned everything up to iterators so far) and fairly new to Programming. This would be my first real program: #Coordinate Geometry (The whole program is not...
5
by: silversnake | last post by:
I'm trying to write a program that take a input number and prints if is a prime numbers but is not working for instance, it says that 4 is prime while 5 is not. can anyone see what the problem is ....
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.