[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.0

ORA-06502 When using MAX(Column) with %TYPE

Asked by Kodarc in Oracle Database

Hi,

I have tried to narrow down the problem as much as I can, and have managed to isolate it to a particular scenario. As the structure and data is sensitive, I have had to come up with a scenario which I have tested and it causes the same issue to occur. The scenario is as follows

Assuming I have a table defined as follows

CREATE TABLE TEST_TABLE   (TEST_COLUMN CHAR(8 BYTE)) ;

and the table only has a single record NZ07100S

We also define a function as

CREATE OR REPLACE FUNCTION
FUNCTION GETTESTVALUE
RETURN TEST_TABLE.TEST_COLUMN%TYPE
IS
  TEST_VALUE TEST_TABLE.TEST_COLUMN%TYPE;
BEGIN
  SELECT MAX(TEST_COLUMN) INTO TEST_VALUE FROM TEST_TABLE;
  RETURN TEST_VALUE;
END;



We ran the following command

SELECT GETTESTVALUE FROM DUAL;

and receive an error as follows

Error report:
SQL Error: ORA-06502: PL/SQL: numeric or value error: character string buffer too small
ORA-06512: at "GETTESTVALUE", line 6
06502. 00000 -  "PL/SQL: numeric or value error%s"


However, if were to modify the function to the following

CREATE OR REPLACE FUNCTION
FUNCTION GETTESTVALUE
RETURN TEST_TABLE.TEST_COLUMN%TYPE
IS
  TEST_VALUE TEST_TABLE.TEST_COLUMN%TYPE;
BEGIN
  SELECT TEST_COLUMN INTO TEST_VALUE FROM TEST_TABLE;
  RETURN TEST_VALUE;
END;

There is no error reported and the value NZ07100S is returned.

Of course, when we modified the function to be

CREATE OR REPLACE FUNCTION
FUNCTION GETTESTVALUE
RETURN TEST_TABLE.TEST_COLUMN%TYPE
IS
  TEST_VALUE TEST_TABLE.TEST_COLUMN%TYPE;
BEGIN
  SELECT CAST(MAX(TEST_COLUMN) AS CHAR(8))INTO TEST_VALUE FROM TEST_TABLE;
  RETURN TEST_VALUE;
END;

No errors are reported, and the value is returned

However, the function in question has been in production usage since 2004. We are currently making some modifications to the application and had imported the backup from Oracle 10g into Oracle XE. When we try to run the function, the error is thrown out.

I would like to understand if this is a limitation with Oracle XE that causes this problem. It would seem to me that the problem is selecting the MAX value into the variable that had been defined. Running the query directly from sqlplus does not generate an error, and as such do not feel there is an error with the SQL. The only time we seem to get the error is with the INTO statement.

Is there are a means to use the function as it has been defined in production? Why would the ORA-06502 error be thrown out? It does not seem to make sense to me. Would appreciate any guidance on this.


Thanks and regards

Jega


 
[+][-]03/04/09 01:18 AM, ID: 23792944Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zone: Oracle Database
Sign Up Now!
Solution Provided By: Kodarc
Participating Experts: 2
Solution Grade: A
 
[+][-]03/04/09 12:34 AM, ID: 23792717Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03/04/09 12:52 AM, ID: 23792820Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-92 - Hierarchy / EE_QW_3_20080625