Substr function fails

hi there, can anyone tell me why a simple substr would throw an error if the target varchar assignment isn't three characters larger than the length provided to the substr function?
can anyone tell me why this:
declare
v_legal varchar2(200);
v_disp_trans_sid integer := 850500;
begin
v_legal := SUBSTR(Ttls_Common.build_parcel_string(v_disp_trans_sid),1,200);
dbms_output.put_line('v_legal is '||length(v_legal)||' characters.');
end;
causes this even though the assignment is substr to 200:
declare
ERROR at line 1:
ORA-06502: PL/SQL: numeric or value error: character string buffer too small
ORA-06512: at line 7
yet once i increase the size of the target varchar by three characters it works:
declare
v_legal varchar2(203);
v_disp_trans_sid integer := 850500;
begin
v_legal := SUBSTR(Ttls_Common.build_parcel_string(v_disp_trans_sid),1,200);
dbms_output.put_line('v_legal is '||length(v_legal)||' characters.');
end;
causes:
v_legal is 200 characters.
PL/SQL procedure successfully completed.

user521233 wrote:
my character set:Yes, UTF8 is multi-byte. Now check NLS_LENGTH_SEMANTICS:
select value from nls_session_parameters where parameter = 'NLS_LENGTH_SEMANTICS';Most likely it is set to BYTE. If so, as I already noted, you can explicitly specify:
v_legal varchar2(200 char);or you can set lenght semantics for your session to characters instead of bytes
ALTER SESSION SET NLS_LENGTH_SEMANTICS=CHAR;or you could set it to CHAR once for the instance:
ALTER SYSTEM SET NLS_LENGTH_SEMANTICS=CHAR;and bounce th instance.
SY.

Similar Messages

  • Substr function in CTL file of sqlloader

    Hi gurus,
    I am using sql loader to load the data from text file to oracle table.
    I have 2 columns in the input data, which are of more size than their corresponding destination table column sizes.
    I am using substr() function in the control file, but it is failing for some records in 2 scenarios, details given below.
    First scenario:
    destination table column size is 250 characters.
    substr() function works fine when the source data is less than 255 characters, but when it is more than 255 characters, the record is getting rejected as bad record.
    eg: if the source data is of 254 characters, only 250 chars are inserted in the table, but if the size is 256, record is not inserted in the table.
    Here is the syntax i am using
    ENQUIRY "SUBSTR(:ENQUIRY, 0, 250)",
    Second scenario:
    destination table column size is 2000 characters.
    substr() function works fine when the source data is upto 2000 characters, but when it is more than 2000 characters, the record is getting rejected as bad record.
    Here is the syntax i am using
    ANSWER CHAR(2000) "SUBSTR(:ANSWER, 0, 2000)",
    Please suggest.
    Thanks,

    odie_63 wrote:
    Hi,
    Try with specifying a larger size limit for both columns :
    ENQUIRY CHAR(4000) "SUBSTR(:ENQUIRY, 0, 250)",        
    ANSWER  CHAR(4000) "SUBSTR(:ANSWER, 0, 2000)"
    Will the substr work with a starting offset of 0 ? Doesn't substr uses 1 as the first character position? or it is different with sqlloader?
    Okay I checked, It works just like if the offset is given as one. Perfect.
    SQL> select substr('ABCDEF',0,3) from dual;
    SUB
    ABCThanks odie_63. :)
    Edited by: zahid79 on Jul 23, 2010 5:20 PM
    Edited by: zahid79 on Jul 23, 2010 5:22 PM

  • Use of substr function will avoid the use of indexes in a table

    i have one table which will contain some 3,00,000 records, it contains some 11 primary keys i am using some update statements to update some fields in the records (of 3,00,000 i will compare some 1,50,000 records with 1,50,000 another records) i am using substr function in all the select statements. whether usage of substr function will avoid the use of index
    can any one clarify?

    contains some 11 primary keys by this I suppose you mean to say the table has a composite PK on 11 columns.
    i am using substr function in all the select statementsCould you please post your SQL statement?

  • Using substring function in the Universe

    What is the correct syntax of using the substring function in the Universe?
    I need to extract the numbers and decimal between the #'s, and the character length varies:
    From: DOE, JOHN  Added the following entry to work history:
    A1S#0.25#
    To: 0.25
    Please help!  Thanks!

    There are ticket details in the text - I replaced certain letters with x, o, or a.  I thought you would need the total number of characters in the text.
    0.25#"
    DOE, JOHN A Xddxd xxx xxllxwOIg xIxxI xx wxxk xOXxxxI:
    A1S#0.25#"O xxxxd Oxck xxxm CJ, xx XxOd xxxx wx xxx XuppxXxd xx Ox gxxxOIg xlxxxX xI xxOX.  Xx, xxx quxXxOxI xxmxOIX wxxx xx dx Ixw?  XOxxxx wx mxkx xxx dxcOXOxI xx OgIxxx xxOX cxIdOxOxI xId xxvx Ox xxmxvxd xxxm XmxxxX, xx wx xxI xx xxXxxxcx xxp xxlkxxX xId Xxx Ox wx cxI Xxxp Xxmx xx xxx xxxxxOc, xx wx xxdxx x OOggxx cOxcuOx xx xxIdlx xxx OuxXxX wOxxxux xII dxxpX.  O'll xxI xx xuI xxOX OI mxIxgxmxIx xId xxx xxXx xx xxx xxxm xx Xxx wxOcx wxI wx wxIx xx gx".
    1#"
    DXX, JXXN X XddXd xxX xxllxAxng XnxrN xx Axrk xxAxxrN:
    A1S#1#"X dxn'x AXX xxxA xn AxnAxrd.  X AxA gxxng xx AxXAk xxX xnxXrxxAX xx AXX xx ApxkXA xn xxrxugxpux AXrX xbAXrvXd xA xxA bXXn AuggXAxXd, xxAXvXr, xxA nxx xn AxnAxrd.  X AxXAkXd Dxrx xnd dxn'x AXX xnN xndxAxxxxn xxxx xxxA xA xn xnN xlxrI grxupA xxr xxrXAxxld Ixnxxxrxng, Ax X'I AxndXrxng AxXrX xxX xlxrI xA AxIxng xrxI.  Xx Axuld bX xxxx xxXrX xA nx xnxXnxxxn xx bX xlxrIxng xn xxxA xx xll xnd xxX xlxrIA Axuld bX AxIxng xrxI xn xld Ixnxxxrxng AxurAX xxxx xA nx lxngXr vxlxd (xX, xxxA AlxppXd xxrxugx xxX ArxAkA AxIXxxA).  X AXnx xn XIxxl xx AurxxA JxnXA xx AXX xx xX Axn xXll Axxx xxX AxurAX xx xxX xlxrI xA (xX, Axxx Ixnxxxrxng ANAxXI xAxuxllN gXnXrxxXd xxX xlxrI)."
    0.5#
    DOE, JOHN A Xaaxa xax OolloxixI xxxIx xo xoIk aisxoIx:
    A1S#.05# "XIxxsOxIIixI xo IXS XixI x quxux OoI xaaixioxxl ixOoIoxxiox xxa Ixcoooaxxioxs."

  • SUBSTR function in the where clause

    HI
    I want to get a number of 15 digits from a column where the user only know the last 10 digits.
    So that when the user enter a number with 10 digits, only the record of that specific number should be displayed.
    And then when the user did not enter any number all the records in the table should be displayed.(this part works fine)
    The problem is: when the user enters any last digits( last, second last, thirth last and so on) the records which satisfy this are retrieved, which is not supose to be the case.
    I' am trying to use the substr function in the where clause but I'm not sure if it's working or not becasue the result of the query is just the same as before i used the substr.
    Thanks

    better to pad with '*' me thinks in case u have a number ending with 0's:
      1  select empno,ename
      2  from emp
      3* where empno like '%'||lpad('&1',2,'*')
    SQL> /
    Enter value for 1: 0
    old   3: where empno like '%'||lpad('&1',2,'*')
    new   3: where empno like '%'||lpad('0',2,'*')
    no rows selected
    SQL> /
    Enter value for 1: 00
    old   3: where empno like '%'||lpad('&1',2,'*')
    new   3: where empno like '%'||lpad('00',2,'*')
         EMPNO ENAME
          7900 JAMES
    SQL> /
    Enter value for 1:
    old   3: where empno like '%'||lpad('&1',2,'*')
    new   3: where empno like '%'||lpad('',2,'*')
         EMPNO ENAME
          7369 SMITH
          7499 ALLEN
          7521 WARD
          7566 JONES
          7654 MARTIN
          7698 BLAKE
          7782 CLARK
          7788 SCOTT
          7839 KING
          7844 TURNER
          7876 ADAMS
         EMPNO ENAME
          7900 JAMES
          7902 FORD
          7934 MILLER
    14 rows selected.

  • Substr function? extracting just the records with 4 digits?

    have a column like this in a table
    SZSCAPD_SEC_SCHOOL_CEEB
    364775
    460460
    460240
    2562
    164625
    460240
    230969I need to be able to retrieve just the values with 4 digits like 2562 and add 00 at the front, so it will ended like 002562
    I am thinking in the substr function, but it won't work, because I will be extracting the first 4 digits of each number.
    How I will do this? I want to only retrieve the numbers with 4 digits Then I will concatenate the 00 in front.
    Thank you

    Hi,
    peace4all wrote:
    ... How I will do this? I want to only retrieve the numbers with 4 digits One way to do that is
    WHERE   TRANSLATE ( szscapd_sec_school_ceeb
                , '123456789'
                , '000000000'
                ) = '0000'
    Then I will concatenate the 00 in front.
    '00' || szscapd_sec_school_ceebThis assumes that szscapd_sec_school_ceeb is a string.
    If szscapd_sec_school_ceeb is a positive number, and you want to ignore any fractional part, use
    WHERE   szscapd_sec_school_ceeb     >=  1000
    AND     szscapd_sec_school_ceeb <  10000to find the numbers and
    TO_CHAR (szscapd_sec_school_ceeb, 'FM000000')to display them as 6 digits, with leading 0's.
    Edited by: Frank Kulash on Aug 20, 2010 11:01 AM
    Added NUMBER alternative.

  • Substring function not working in Analytical view

    Dear All,
    I am trying to use substring function in my analytical view .It says valid expression during syntax check but getting activation error.
    thanks
    Sourav

    Hi Krishna,
    This is Kiran, I am trying to restrict a (string) filed value by removing the spaces and wring to calculated column field in an Analytical view for position 6 - 10.
    Example: Field name XYZ (Values showing as: ASDFG GETVALUENW  2345) --> (data type :22 VARCHAR)
    Output Value must be : GETVALUENW (which is 10 characters, from position 6 after trimming)
    Please advice which function use and how to apply the syntax
    Your inputs are highly appreciated.
    Thanks
    Kiran.

  • Substring Function without the length!

    I know I have seen this before, but cannot find it when searching.
    I need to do something similar to the Substring function, where I start from position 4, but the length behind this position is variable.   Due to the IDOC it only passes the value...
    I think I possibly saw a UDF for this somewhere - unless I can use some standard mapping!
    It is probably very simple - but it is late in the day and my eyes are square!  = )
    <i> I need a drink......</i>
    Can anyone help?
    Message was edited by:
            Barry Neaves

    For substring function, you have 1 input and 2 parameters (you set the parameters by double-clicking the function box).
    I also didn't understand how you can pass the output of length function two 2nd parameter of substring function (since it is a parameter and not an expected input).
    You could always create a UDF...
    public String UDSubstring(String a,String b,String c,Container container){
      int d = Integer.parseInt(b);
      int e = Integer.parseInt(c);
      if ((e == 0) && (a.length() >= d)) {
        return a.substring(d);
      else if ((e > d) && (a.length() >= e)) {
        return a.substring(d, e);
      else return "";
    They don't bite, you know...
    Regards,
    Henrique.
    <b>Edit:</b> followed by Michal's correction...

  • Substring function in HFR

    Hello Experts,
    Iam a rookie in HFR. I needed to know how to implement the Substring functionality in Hyperion. Can anyone throw some light on this?

    thats a major drawback of hyperion financial reporting of not having any string functions. as per my knowledge there is none.
    Let me know if you get to know of the same. Coz even I need it for couple of things in my reports.
    regards,
    rahul

  • Substring Function in formula builder of transfer rule

    Hi Gurus
    I want to get the domain name from Email address.
    For eg: if the email address is [email protected], i want to display only "yahoo.com" in the report.
    For that, shall i use Substring function in transfer rule.
    If so, please advice me how i can do this.
    Thanks
    Sansen

    Instead try using a routine using the SPLIT function...
    For example if you want to split the value of the field TEST whose value is [email protected] then try writing a code like below in the transfer routine...
    DATA: TEST1(30), TEST2(30) TYPE C.
    SPLIT TRAN_STRUCTURE-ZEMAILID AT '@' into TEST1 and TEST2.
    RESULT = TEST2.
    (value of TEST2 would be yahoo.com)
    Hope this helps...

  • Using substring function with error

    Hi Guys,
    I have a source field with 1200 characters which need to map to multiple target segments for  132 count of this source field.
    This is not a mandatory field so it sometimes come without any value.
    I am using substring function to breakout the string for every 132 characters and mapped to the target segments.
    There are two problems, first it seems that if source is blank, there will be error.
    Second, if source field come with only eg. 300 characters, error will also occurs.
    I have searched thru SDN and try some of the UDF but to no avail.
    Appreciate your guidance on this problem.
    Regards
    FNG

    H Rahul,
    I have tried your quote but face some syntax error as follows
    Function calculate, Line 6:
    cannot find symbol symbol  : method length() location: class java.lang.String[] j = input.length();       
    Function calculate, Line 26:
    cannot find symbol symbol  : method subString(int,int) location: class java.lang.String[]           
    result.addValue(input.subString(0,EndIndex));                                      ^
    Function calculate, Line 34:
    cannot find symbol symbol  : method subString(int,int) location: class java.lang.String[]                result.addValue(input.subString(StartIndex,EndIndex));                                              ^
    Function calculate, Line 40:
    cannot find symbol symbol  : method subString(int,int) location: class java.lang.String[]                result.addValue(input.subString(StartIndex,EndIndex));                                              ^ Note: /usr/sap/D03/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Mapd66a3a60002911e09ba9e41f132d6b68/source/com/sap/xi/tf/_MM_MT_COMS_TO_ZME_CRE_CHG_CONTRACT_.java uses or overrides a deprecated API. Note: Recompile with -Xlint:deprecation for details. Note: /usr/sap/D03/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Mapd66a3a60002911e09ba9e41f132d6b68/source/com/sap/xi/tf/_MM_MT_COMS_TO_ZME_CRE_CHG_CONTRACT_.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. 4 errors

  • Substring function in DDL

    Can I use substring function in DDL? I want to get the prot_id column by combining rest of the columns. Please help me whether I can write like this or any way is there?
    create table testsyn(
    lega_sty_nr          VARCHAR2(6),
    col_cd VARCHAR2(6),
    del_cd VARCHAR2(2),
    prot_id VARCHAR2(60) as
    (select SUBSTR(
    CASE WHEN(LENGTH(lega_sty_nr) > 0)
         THEN lega_sty_nr||'_'||col_cd||'_'||del_cd
    ELSE NULL
    END )
    )

    No.
    +(inspired by Alex ;) )+
    edit:
    You need to explain more clearly what you're trying to do.
    Why the substr?
    SQL> create table testsyn(
      2  lega_sty_nr VARCHAR2(6),
      3  col_cd VARCHAR2(6),
      4  del_cd VARCHAR2(2),
      5  prot_id VARCHAR2(60) as
      6  (select SUBSTR(
      7  CASE WHEN(LENGTH(lega_sty_nr) > 0)
      8  THEN lega_sty_nr||'_'||col_cd||'_'||del_cd
      9  ELSE NULL
    10  END )
    11  );
    prot_id VARCHAR2(60) as
    ERROR at line 5:
    ORA-00907: missing right parenthesisEdited by: hoek on Jun 10, 2009 11:56 AM

  • Substring function for presentation variables in obiee

    I have a presentation variable called period that has the (fromdate and to date)
    Is there any way that I can split this one variable into 2 by using substring function??in such a way that it gives one for from date and the other for to date..
    any synatx like
    SUBSTRING ( '@{period} FROM 0 FOR POSITION
    (' - ' IN '@{period})) ???
    and how to apply this?

    The answer to this question is the same for the one you posted here:
    can we create two dashboard prompts for the same column in the samepage
    You need to split your prompts into two. If you read the link I posted in the other thread and re-posted here, you will find that the reason to do it this way is so you can see the values of the prompts. Read the first paragraph of this link -- again, if you already read it. You cannot split the single presentation variable if you use the BETWEEN operand in the dashboard prompt. You need to put the operand in the filter in your report.
    http://oraclebizint.wordpress.com/2008/02/26/oracle-bi-ee-101332-between-prompts-for-date-columns-using-presentation-variables/

  • How to use Substring function with Case statement.

    Hello Everyone,
    I have one requirement where I have to use substring function on the field for report criteria.
    E.G.
    I have Branch Name Field where I have all branch names information, Now some of the branch names are too big with some extension after the name .
    now i want to substing it but the character length varies for each branch.
    so is there any way where we can use case statement where we can define that if branch name character are exceeding some value then substing it with this length.

    Try something like this:
    CASE WHEN LENGTH(tablename.Branch_Name) > n THEN SUBSTRING(...) ELSE tablename.Branch_Name END
    where n is the number of characters you want to start the break.

  • Convert substring function from SQL Server to Oracle

    I am converting a large application written for SQL Server to Oracle and have encountered a difference in how the substring function is called between the two database systems.
    In SQL Server:
    select substring('xyz'1,2)
    In Oracle:
    select substr('xyz',1,2)
    Is there a way to establish a user-defined operator to map the substring call to a substr call so I don't have to change the application code?
    Is the user-defined function a way to do this?
    Which is better?

    If you want to be able to use the code that has substring in it, without modifying it, and have it do the same thing as substr, then try running the script below. It will create a user-defined function named substring that will cause substring to act like substr.
    CREATE OR REPLACE FUNCTION substring
    (p_string IN VARCHAR2,
    p_start IN VARCHAR2,
    p_end IN VARCHAR2 DEFAULT NULL)
    RETURN VARCHAR2
    IS
    v_string VARCHAR2 (100);
    BEGIN
    IF p_end IS NULL
    THEN
    SELECT SUBSTR (p_string, p_start)
    INTO v_string
    FROM DUAL;
    ELSE
    SELECT SUBSTR (p_string, p_start, p_end)
    INTO v_string
    FROM DUAL;
    END IF;
    RETURN v_string;
    END substring;
    null

Maybe you are looking for

  • Problem trying to update book with Producer

    I found a typo in my book and I wanted to upload a corrected version. Everything works fine in iBooks Author, but then when it opens producer I noticed that the title is incomplete and has odd spacing. So I fixed that and made all entries and then wh

  • Registering a UK cell but my location isn't in the...

    Hi hi,  I'm trying to register my new UK cell to use Skype-to-go, but the drop down menu doesn't have Oxford cells (0755) on there. I'm not sure what to do. Any ideas?

  • Invalid option for MAP: MAP.

    Hi , My replication file is running fine with below contents MAP PROD.f0911, TARGET PROD.f0911, & REPERROR (21000, EXCEPTION), & SQLEXEC (ID lookup, ON UPDATE, & QUERY "select count(*) conflict from PROD.f0911 where ID_NO = :p1 and & UPDT_DT > :p2",

  • Pages mess up with email signature

    Hello, I've a problem with pages. When I send an E-mail with mail app, the recipient get the email with the correct signature on it. When i send a file from Pages, the signature is "gone" and it's added in a "ATT00007.txt" file attached to the email.

  • Update to Mavericks, Firmware password lost

    Hello, about a year ago I set up a firmware password for my MacBook 5.1 (Aluminium Unibody MacBook, no Pro). I forgot to store the password in 1Password, so now I'm stuck with a MacBook which has a firmware password set I can't reset. Will the Maveri