how to return less than 4000 characters from pl/sql function in SQL call?
Ilmars2Jun 11 2009 — edited Jun 13 2009Hello,
Is there a way to limit length for varchar when calling pl/sql function from SQL? No matter how I write it it always returns 4000 bytes.
If there is none, then does it make sense ever to specify lenght of the return variable?
My goal is to encapsulate business rules within pl/sql functions. But if all varchar columns are returned as 4000 it is not feasible solution. Not only this is a performance issue in a data warehousing environment, bet when using those rules within SQL views user experiance would suffer as well. Are we left with the rule hardcoding solution? Also, I think that using SUBSTRING or TRUNC functions on top of business rules function defeats the purpose.
Please see my attempt below. Your thoughts are appreciated.
Thank you.
/* Formatted on 06/11/2009 2:26:41 PM (QP5 v5.126.903.23003) */
CREATE OR REPLACE FUNCTION mytest (myvar_in VARCHAR2)
RETURN VARCHAR2
AS
l_return VARCHAR2 (15);
BEGIN
l_return := 'TEST_' || myvar_in;
RETURN l_return;
END mytest;
CREATE TABLE TEST_ME
AS
SELECT mytest ('ME') AS VERYLONG FROM DUAL;
describe TEST_ME;
RUN ABOVE CODE:
Function created.
Table created.
TABLE TEST_ME
Name Null? Type
----------------------------------------- -------- ----------------------------
VERYLONG VARCHAR2(4000)
Edited by: Ilmars2 on Jun 11, 2009 2:46 PM