Solved

Getting ROWCount and Replace function in Oracle SQL

Posted on 2011-02-10
7
743 Views
Last Modified: 2012-05-11
Hi All,

I'm trying to do something like this in Oracle10g. Not sure how to do it, since all solutions I found on Google were with PL/SQL.

SELECT %ROWCOUNT, ID
FROM TableName

I would also like to do the following, but could not seem to find a SQL equiv. Only PL/SQL.

UPDATE TableName
SET COLNAME = COLNAME.Replace(",",".")

Appreciate any advice.
0
Comment
Question by:chongchian
  • 4
  • 3
7 Comments
 
LVL 73

Expert Comment

by:sdstuber
ID: 34868077
very close...


I assume you want to replace all commas with periods,  if so, try this.


UPDATE TableName
SET COLNAME = Replace(COLNAME,",",".")
0
 
LVL 73

Expert Comment

by:sdstuber
ID: 34868223
for the rowcount I don't know what you're trying to do.


do you want a rownumber for each row? if so


select rownum, id from yourtable;


if you want a count of the number of rows in the entire table :


select count(*) over(), id from yourtable
0
 

Author Comment

by:chongchian
ID: 34868333
thanks sdstuber. What i was trying to do is to list the index of the row which is different from the ID. Thanks lots for your kind advice.
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 73

Expert Comment

by:sdstuber
ID: 34868387
by "index" if you mean the number of each row,  that's not deterministic without an order by
0
 

Author Comment

by:chongchian
ID: 34868390
hmm... what if i wanted to also display the row index?
0
 

Author Comment

by:chongchian
ID: 34868395
Example, Table consists of the following

----   ----------------
ID      Name
----   ----------------
av1   John
av2   James
av9   Jason
av4   Tom
av3   Joe

to be displayed as

----   ----   ----------------
S/N   ID      Name
----   ----   ----------------
1      av1   John
2      av2   James
3      av9   Jason
4      av4   Tom
5      av3   Joe
0
 
LVL 73

Accepted Solution

by:
sdstuber earned 500 total points
ID: 34868421
unless you have an explicit order by,  you can't guarantee that the ordering will always be that way.

They are not in alphabetic order or any other order I can see.

Some people mistakenly believe there is something like a "natural" order, or that Oracle will remember the order in which data is inserted and will
return rows in the same order,  but it won't, at least not reliably


the ONLY way to RELIABLY return data with a specific order is to order it yourself with an ORDER BY clause
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Why doesn't the Oracle optimizer use my index? Querying too much data Most Oracle developers know that an index is useful when you can use it to restrict your result set to a small number of the total rows in a table. So, the obvious side…
Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
Via a live example, show how to take different types of Oracle backups using RMAN.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now