ORA-6502 Character string buffer too small error with Execute immediate statement - oracle

I get an Oracle error ORA-6502 Character string buffer too small in my code at the statement below
EXECUTE IMMEDIATE 'BEGIN :project_id :=
Activity_API.Get_Project_Id(:activity_seq); END;'
USING OUT project_id_, activity_seq_
project_id_ - this is a local variable in the function
activity_seq_ -- this is an IN parameter to the function.
I don't understand the cause of the error. Besides, the error is not consistently showing up.
Please help me know what am I missing out.
Thanks.

Generally this error means that you have a VARCHAR(N) variable somewhere in your code and you tried to assign VARCHAR(N+x) value to it. It may happens anywhere, say:
size of activity_seq_ is too big for function local variable
size of project_id_ is too small for function result
there is some oversized value used into the function itself
etc.
Sometimes it may happens because of multibyte character set used, say, if value is VARCHAR(N chars) while assignment target is VARCHAR(n bytes). Anyway, you should just debug it. Use PL/SQL Developer or any other tool which can trace stored procedures row by row, run your statement into the test window and see what happens, where and why.

Related

dbms_output.put_line in PLSQL Developer fails with ORA-06502 for strings longer than 32512 chars

This script fails in PLSQL Developer version 14.0.0.1961 (error ORA-06502: PL/SQL: numeric or value error: character string buffer too small):
declare
v varchar2(32767) := rpad('x',32513,'x');
begin
dbms_output.enable(null);
dbms_output.put_line(v);
end;
/
If 32513 is replaced by higher value, it fails too.
If 32513 is replaced by lower value, it works (i.e. prints text without failure).
In SQL*Plus and Toad it works for up to 32767 (this is expected).
In Intellij Idea it works for up to 32766, for 32767 it does not raise exception though prints nothing.
How can I explain such behaviour? The 32512 seems to be interesting constant (I found it in some APEX question, question about blobs and is also mentioned in JDBC tutorial but I miss any connection to described problem.)
Looks like a PL/SQL Developer bug.
In 2013, they said they'll fix it:
it's a bit of a low-level issue, so his may need to wait until version 11.0.
Which version do you use?

DSSetParam -4 error when filling a parameter with a routine

I'm building a Sequence job that contains a UserVariables activity (ParamLoading) and a Job activity (ExtractJob), in that order. ParamLoading creates 4 user variables and invokes a routine to fill each one with the correspondng value, then invokes ExtractJob pasiing it the parametes previously loaded.
ParamLoading invokes a server routine (GetParams) which simply executes a shell script (ShellQuery) and captures the result; that shell script executes an SQL query against an Oracle database and prints the result on screen.
As far as tests go, ShellQuery works as expected and GetParams returns the expected value. But when GetParams is invoked from the sequence job (no matter if it's in ParamLoading or ExtractJob) the job fails with the following error:
Test2..JobControl (#JOB033_TBK_026_EXT_PTLF): Controller problem: Error calling DSSetParam(RUTA_ORIGEN), code=-4
[ParamValue/Limitvalue is not appropriate]
I've checked data types, parameter names, all, without success or even a message saying what might be happening.
Code of ShellQuery:
value=$(sqlplus -s $1/$2#$3/$4 <<!
set heading off
set feedback off
set pages 0
select param_value from cfg_params where filter='$5' and param_name='$6';
!)
echo $value
Code of GetParams:
Call DSExecute("UNIX", Ruta_Programas:"getparams.sh ":Username:" ":Password:" ":Server:" ":ServiceId:" ":Filtro:" ":Parametro, Output, SystemReturnCode)
Ans = Output
Return(Ans)
What are you returning as values from GetParams?
Calling a function from a sequence expects an integer value back and any non-zero digit returned is evaluated as an error.
As a test, try changing the return value from the routines to values 0-4.
Solved. For those struggling with a similar problem, GetParams was returning the captured value from ShellQuery adding a special character called "field delimiter", and given that the character is a 254 in ASCII, any job receiving the parameter would complain of an invalid value, which was the error.
Changing the routine to the following solved it:
Call DSExecute("UNIX", Ruta_Programas:"getparams.sh ":Username:" ":Password:" ":Server:" ":ServiceId:" ":Filtro:" ":Parametro, Output, SystemReturnCode)
Ans = EReplace(Output, #FM, "")
Return(Ans)
Thanks to Matt Calderon for providing a clue for solving.

Oracle and TOAD (and I) disagree on number of variables to bind

At runtime, I'm getting "ORA-01008 - not all variables bound" with a SQL statement that runs fine in TOAD and in which TOAD (and I) only find one parameter.
As can be seen below, there IS only one parameter in the query. Why would Oracle think there are more than one parameters/variables and cause an exception to be thrown?
I cannot show the real sql, but here is a facsimile of it (column/table names changed):
SELECT DECODE(POSTWHEELTYPE,'0','NONE','D','NUMERIC','D','RESTRICTED NEEDLE','X','TRANSFER TO WINTER','A','ACCESS CODE') HALTYPE,
DECODE(VALIDATIONTYPE,'0','NONE','A','FOXPRO CODE','P','PERSONAL CODE','S','RESTRICTED') JBJTYPE,
LAZYNUMBER,
DISPLAYTEXT,
MINLENGTH || '-' || MAXLENGTH LENGTH,
NVL(INSTRUCTIONS, '<NONE>') INSTRUCTIONS
FROM
ABC.CODELAZYS
WHERE
BQSERVERABCID = :ABCID
AND VALIDATIONTYPE <> '0'
ORDER BY
LAZYNUMBER DESC
If Oracle is returning this error code, I would bet the better part of my last dollar that the variable was not bound. Just because TOAD has provided a value for the variable does not mean that it's bound in other clients.
Are you 100% positive your one variable is indeed bound? Where are you running the query that fails? Can you show us how it's called?
The problem was that I was binding the variable too late; once I moved it above the call to ExecuteReader(), it worked.

How to find the error causing ora-06575?

Recently I had to write an oracle function, and the error ora-06575 popped up awfully a lot.
Usually it was because of missing colon from assignment, such as: z = 5 (vs. z := 5)
Or a missed ';' at the end of a statement.
Anyway, I was able to create the function, but it failed during execution with that error, and gave no hint as to where the problem was (except that it was in the function).
I wrote same function in MSSQL and Sybase, and both of those actually tried to point me to the place of any errors. So I figure I'm doing something wrong in Oracle - it can't just tell me 'there's an error'.
In oracle I have a statement like this:
CREATE OR REPLACE
FUNCTION...
I'm compiling the function from SQL developer by selecting the function, and pressing F9.
When I select a statement which executes the function, and press F9, I get the ora-06575 error.
If I press F5 to compile the function, it tells me:
ORA-24344: success with compilation error
Compiled.
So I found this website: http://www.dba-oracle.com/t_ora_24344_success_with_compilation_error.htm
But I can't seem to run 'show errors'. When I run it, I get no output that I can see.
Can that only work from sqlplus? I'm using SQL developer, I'd prefer to stick to SQL developer.
Is there something I'm missing? I want it to tell me where the error is.
SHOW ERRORS is a sql*plus command
You can also query the USER_ERRORS view
SELECT line, position, text
FROM user_errors
WHERE name = '<<your_object_name>>'
SHOW ERRORS works in SQL*Developer too (at least in the versions I've used recently, certainly 3.1). You mentioned in a comment that you're connected as SYS, so I really hope you're creating your function explicitly in another schema - I'd avoid this anyway just in case you forget one day, and modifying any of the pre-built schemas (SYS, SYSTEM etc.) is a bad idea. If so you need to prefix the errored object with the schema too:
create or replace function my_schema.x return number is
begin
return sysdate;
end;
/
show errors my_schema.x
When run as a script (F5) this says:
FUNCTION X compiled
Warning: execution completed with warning
3/8 PLS-00382: expression is of wrong type
3/1 PL/SQL: Statement ignored
The first two lines of the output come from the function compilation, the last two from show errors. You can also run the two statements separately with F9 to see the same results.
But I'm not sure how you're getting the ORA-24344, so maybe you're on an earlier version; and it's possible that won't work. A.B.Cade's solution will work whatever your client though.

Oracle SQL Developer - Help for debugging

I am trying to debug a package with in the SQL Developer. The method that i am trying to debug takes 2 parameters
PROCEDURE procedure_name (dblink IN CHAR, bDebug IN BOOLEAN DEFAULT FALSE)
When i click on "Debug" icon, it asks for inputs that i need to give to this procedure. I give
dblink:='linkname';
bDebug:=TRUE;
but when it starts debugging, I see the value of dblink as
'linkname
'
i.e. linkname, lots of spaces and then the ending quote. so when in code i try to do this
`strSrc VARCHAR(120) := 'tablename'||dblink;`
it gives me error that buffer is to small, which makes sense. but why SQL Developer is doing so? how to fix it?
I am guessing your padding is coming from how SQL Developer is defining its variable to bind with (it is probably defining it as a CHAR(4000)). For now, you should be able to get around this in your test code by putting trim() around the dblink variable:
strSrc VARCHAR(120) := 'tablename'||trim(dblink);
Note that this would normally not be needed if the procedure was passed a literal (or a correctly sized CHAR variable, a VARCHAR, etc), like the production code is probably doing.
For debugging purposes, create a wrapper procedure that accepts a VARCHAR2 parameter, then passes it to your procedure; then you debug it in SQL Developer by calling your wrapper.

Resources