?
Solved

Getting ROWCount and Replace function in Oracle SQL

Posted on 2011-02-10
7
Medium Priority
?
765 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 74

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 74

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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 74

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 74

Accepted Solution

by:
sdstuber earned 2000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
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 syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…
Suggested Courses

801 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