Solved

Getting ROWCount and Replace function in Oracle SQL

Posted on 2011-02-10
7
751 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
Oracle - SQL Parse String 5 34
Extract Currency data from a string and put them in a new field 3 36
Oracle DB monitor SW 21 48
having some issue on pl sql procedure 1 19
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…
Introduction A previously published article on Experts Exchange ("Joins in Oracle", http://www.experts-exchange.com/Database/Oracle/A_8249-Joins-in-Oracle.html) makes a statement about "Oracle proprietary" joins and mixes the join syntax with gen…
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…
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.

770 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