Oracle Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesOracle Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old August 30th, 2006, 09:16 PM
debussyman debussyman is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2006
Posts: 3 debussyman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 28 m 39 sec
Reputation Power: 0
Procedure query returns incorrect result

I have a stored procedure running a batch of sql queries. However, one of the queries always returns the wrong result for a single table.

The procedure is:

CREATE OR REPLACE PROCEDURE countUser ( name IN USERS.username%TYPE )

AS

rows_counted NUMBER := 0;

BEGIN

dbms_output.enable;

dbms_output.put_line('Counting values for user '||name);

SELECT count(*) AS count INTO rows_counted FROM files fi WHERE fi.username = name;
dbms_output.put_line(rows_counted||' files counted');

SELECT count(*) AS count INTO rows_counted FROM files fi WHERE fi.username = '771';
dbms_output.put_line(rows_counted||' files(2) counted');

SELECT count(*) AS count INTO rows_counted FROM userdevices ud where ud.username = name;
dbms_output.put_line(rows_counted||' user devices counted');

SELECT count(*) AS count INTO rows_counted FROM users u where u.username = name;
dbms_output.put_line(rows_counted||' users counted');

commit;

EXCEPTION

WHEN OTHERS THEN
raise_application_error(-20001,'An error was encountered - '||SQLCODE||' -ERROR- '||SQLERRM);

END;


When I call this procedure, it prints out this result:

SQL> exec countUser('771');
Counting values for user 771
0 files counted
1 files(2) counted
1 user devices counted
1 users counted

PL/SQL procedure successfully completed.

The parameter 'name' works fine in the where clause of queries on the UserDevices table and Users table, but fails for the Files table.

Any ideas whats happening here?

Reply With Quote
  #2  
Old August 30th, 2006, 10:49 PM
clivew clivew is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jan 2006
Location: Carlsbad, CA
Posts: 852 clivew User rank is Sergeant (500 - 2000 Reputation Level)clivew User rank is Sergeant (500 - 2000 Reputation Level)clivew User rank is Sergeant (500 - 2000 Reputation Level)clivew User rank is Sergeant (500 - 2000 Reputation Level)clivew User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 4 Days 10 h 56 m 22 sec
Reputation Power: 19
1. What happens if you change the order?
2. I do not believe you need the "AS count" and, if you do, choose a name that is not a reserved word COUNT.

Using reserved words in the wrong context can be a source of hard to trace problems.
Clive

Reply With Quote
  #3  
Old August 31st, 2006, 05:48 PM
debussyman debussyman is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2006
Posts: 3 debussyman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 28 m 39 sec
Reputation Power: 0
Quote:
Originally Posted by clivew
1. What happens if you change the order?
2. I do not believe you need the "AS count" and, if you do, choose a name that is not a reserved word COUNT.

Using reserved words in the wrong context can be a source of hard to trace problems.
Clive
1. Order doesn't affect the output.
2. I changed the alias assigned to count and the behavior doesn't change: the output is still wrong.

Thanks for the reply. Any other thoughts?

Reply With Quote
  #4  
Old September 1st, 2006, 03:51 AM
bhushanm bhushanm is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2006
Posts: 32 bhushanm User rank is Private First Class (20 - 50 Reputation Level)bhushanm User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 6 h 2 m 6 sec
Reputation Power: 3
what is the datatype and precision of the users.username column and files.username column?...you might wanna try

SELECT count(*) AS count INTO rows_counted FROM files fi WHERE trunc(fi.username) = name

Reply With Quote
  #5  
Old September 5th, 2006, 03:06 PM
debussyman debussyman is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2006
Posts: 3 debussyman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 28 m 39 sec
Reputation Power: 0
Quote:
Originally Posted by bhushanm
what is the datatype and precision of the users.username column and files.username column?...you might wanna try

SELECT count(*) AS count INTO rows_counted FROM files fi WHERE trunc(fi.username) = name
The data type is varchar2. I tried

SELECT count(*) AS count INTO rows_counted FROM files fi WHERE trim(fi.username) = name

but with the same result.

Thanks for your reply. This has been a pretty annoying bug.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesOracle Development > Procedure query returns incorrect result


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT