Solved

Getting ROWCount and Replace function in Oracle SQL

Posted on 2011-02-10
7
748 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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Identify records which do NOT qualify for a view 9 36
dates - loop 12 57
case statement in where clause with not exist 15 46
PL SQL Search Across Columns 4 17
Note: this article covers simple compression. Oracle introduced in version 11g release 2 a new feature called Advanced Compression which is not covered here. General principle of Oracle compression Oracle compression is a way of reducing the d…
I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that use…
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…

932 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

11 Experts available now in Live!

Get 1:1 Help Now