Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Getting ROWCount and Replace function in Oracle SQL

Posted on 2011-02-10
7
Medium Priority
?
767 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
Technology Partners: 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!

 
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

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

Question has a verified solution.

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

Working with Network Access Control Lists in Oracle 11g (part 2) Part 1: http://www.e-e.com/A_8429.html Previously, I introduced the basics of network ACL's including how to create, delete and modify entries to allow and deny access.  For many…
Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.

610 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