SQL> r
1 select baseXname from (
2 select basename(file_name) baseXname from dba_data_files)
3* where basexname like 'B%'
select basename(file_name) baseXname from dba_data_files)
*
ERROR at line 2:
ORA-06502: PL/SQL: numeric or value error
ORA-06512: at "DKRAY.BASENAME", line 15
The inline view run alone does not produce the error:
SQL>
SQL> select basename(file_name) baseXname from dba_data_files;
===============================================
CREATE OR REPLACE FUNCTION RAY.basename(file_name_in in varchar2) return varchar2
is
Result varchar2(150);
last_slash_pos number;
begin
last_slash_pos := 0;
for i in 1..length(file_name_in)
loop
if substr(file_name_in, i, 1) = '/' or substr(file_name_in, i, 1) = '\'
then
last_slash_pos := i;
end if;
end loop;
if last_slash_pos = 0
then
Result := file_name_in;
else
Result := substr(file_name_in, last_slash_pos + 1);
end if;
One of your variables is too small. In any event you should not hard code the size of variables, but instead TYPE it to the column and table that the data represents. I also changed your number to BINARY_INTEGER.
Code:
CREATE OR REPLACE FUNCTION get_base_name
( file_name_in IN dba_data_files.file_name%TYPE )
RETURN dba_data_files.file_name%TYPE
IS
Result dba_data_files.file_name%TYPE;
last_slash_pos BINARY_INTEGER;
BEGIN
last_slash_pos := 0;
FOR i in 1..length( file_name_in )
loop
IF SUBSTR(file_name_in, i, 1) = '/' or SUBSTR(file_name_in, i, 1) = '\'
THEN
last_slash_pos := i;
END IF;
END LOOP;
IF last_slash_pos = 0
THEN
Result := file_name_in;
ELSE
Result := substr(file_name_in, last_slash_pos + 1);
END IF;
RETURN Result;
END get_base_name;
/
Originally posted by DBAtrix i made those changes, with the same result (ora-6502). any ideas why the query by itself is okay, but as an inline view the query fails?
IF you do a "SELECT file_name FROM dba_data_files;", what do you get?
I'm thinking the problem relates to the data that you are bringing back.
Do you have any files located in the root directory?
Last edited by gandolf989; 12-28-2004 at 11:04 AM.
Somewhere there is a value that is too big for a variable. But I am not sure what that would be. It would help to know the full value for the file_name that it is failing on.
Is this a cut and paste job, or is there a difference between RAY.basename and DKRAY.basename? Your original error message references DKRAY.basename, but the function you posted is RAY.basename.
Bookmarks