ORA-01458 invalid length inside variable character string

I got ” ORA-01458 invalid length inside variable character string ”  error in Oracle database.

 

ORA-01458 invalid length inside variable character string

 

Details of error are as follows.

ORA-01458 invalid length inside variable character string

Cause: An attempt was made to bind or define a variable character string with a buffer length less than the minimum requirement.

Action: Increase the buffer size or use a different type.

 

 

invalid length inside variable character string

This ORA-01458 error is related to the attempt was made to bind or define a variable character string with a buffer length less than the minimum requirement.

Increase the buffer size or use a different type.

 

Calling a PL/SQL stored procedure which has an OUT parameter from a Pro*C program.  The OUT parameter is of type VARCHAR or CHAR, and the host variable you are passing for this parameter is of type VARCHAR.

When you call the PL/SQL procedure, you receive the following error:

ORA-01458 invalid length inside variable character string

For Example:

EXEC SQL BEGIN DECLARE SECTION;
    VARCHAR    username[20];
    VARCHAR    password[20];
EXEC SQL END DECLARE SECTION;
 
EXEC SQL INCLUDE sqlca;
 
void proc1();
void sqlerror();    /* handles unrecoverable errors */
 
main() {
 
    /* Log on to ORACLE */
    strcpy(username.arr, "SCOTT");        /* copy the username */
    username.len = strlen(username.arr);
    strcpy(password.arr, "TIGER");        /* copy the password */
    password.len = strlen(password.arr);

    EXEC SQL WHENEVER SQLERROR DO sqlerror();

    EXEC SQL CONNECT :username IDENTIFIED BY :password;
    printf("\nConnected to ORACLE as user: %s\n", username.arr);
 
    proc1();

    EXEC SQL COMMIT WORK RELEASE;    /* log off ORACLE */

    printf("\nHave a good day.\n");

    exit(0);
}
 
void proc1()
{
  EXEC SQL BEGIN DECLARE SECTION;
    varchar pv1[10];
    varchar pv2[10];
  EXEC SQL END DECLARE SECTION;

  strcpy(pv1.arr,"ABC");
  pv1.len=strlen(pv1.arr);

  printf("Calling PL/SQL procedure myproc from C function proc1.\n");
  EXEC SQL EXECUTE
  BEGIN
    myproc(:pv1, :pv2); /* Parm 2 in this case is OUT mode */
  END;
  END-EXEC;
}
 
void sqlerror()
{
    EXEC SQL WHENEVER SQLERROR CONTINUE;
 
    printf("\nORACLE error detected:\n");
    printf("\n% .70s \n", sqlca.sqlerrm.sqlerrmc);
 
    EXEC SQL ROLLBACK RELEASE;

    exit(1);
}

Sample Output:

Connected to ORACLE as user: SCOTT
Calling PL/SQL procedure myproc from C function proc1.

ORACLE error detected:

ORA-01458: invalid length inside variable character string

 

 

Length of Host Viable not set properly.

 

Set the length of the VARCHAR host variable being bound to the OUT parameter in the procedure call to a valid length before calling the procedure.

Even though the value is never read by PL/SQL for OUT parameters, the API still validates the input to ensure that it is in the allowable range.  For VARCHAR variables, we recommend you set the length field to the maximum length for the variable in question, but you could use any valid value in
practice, including 0 (zero).

 

For Example:

EXEC SQL BEGIN DECLARE SECTION;
    VARCHAR    username[20];
    VARCHAR    password[20];
EXEC SQL END DECLARE SECTION;
 
EXEC SQL INCLUDE sqlca;
 
void proc1();
void sqlerror();    /* handles unrecoverable errors */
 
main() {
 
    /* Log on to ORACLE */
    strcpy(username.arr, "SCOTT");        /* copy the username */
    username.len = strlen(username.arr);
    strcpy(password.arr, "TIGER");        /* copy the password */
    password.len = strlen(password.arr);

    EXEC SQL WHENEVER SQLERROR DO sqlerror();

    EXEC SQL CONNECT :username IDENTIFIED BY :password;
    printf("\nConnected to ORACLE as user: %s\n", username.arr);
 
    proc1();

    EXEC SQL COMMIT WORK RELEASE;    /* log off ORACLE */

    printf("\nHave a good day.\n");

    exit(0);
}
 
void proc1()
{
  EXEC SQL BEGIN DECLARE SECTION;
    varchar pv1[10];
    varchar pv2[10];
  EXEC SQL END DECLARE SECTION;

  strcpy(pv1.arr,"ABC");
  pv1.len=strlen(pv1.arr);

  pv2.len=10; /**** Initialize the length of OUT variable ***/

  printf("Calling PL/SQL procedure myproc from C function proc1.\n");
  EXEC SQL EXECUTE
  BEGIN
    myproc(:pv1, :pv2);
  END;
  END-EXEC;
}
 
void sqlerror()
{
    EXEC SQL WHENEVER SQLERROR CONTINUE;
 
    printf("\nORACLE error detected:\n");
    printf("\n% .70s \n", sqlca.sqlerrm.sqlerrmc);
 
    EXEC SQL ROLLBACK RELEASE;

    exit(1);
}

In some cases, moving the declaration of the variable from local to global or static scope can eliminate the problem by implicitly relocating the variable to default-initialized storage (e.g., global/static data is often zero-initialized by default and zero is a valid length), but this is not the preferred solution.

 

 

 

 

Do you want to learn Oracle Database for Beginners, then read the following articles.

Oracle Tutorial | Oracle Database Tutorials for Beginners ( Junior Oracle DBA )

 

 488 views last month,  5 views today

About Mehmet Salih Deveci

I am Founder of SysDBASoft IT and IT Tutorial and Certified Expert about Oracle & SQL Server database, Goldengate, Exadata Machine, Oracle Database Appliance administrator with 10+years experience.I have OCA, OCP, OCE RAC Expert Certificates I have worked 100+ Banking, Insurance, Finance, Telco and etc. clients as a Consultant, Insource or Outsource.I have done 200+ Operations in this clients such as Exadata Installation & PoC & Migration & Upgrade, Oracle & SQL Server Database Upgrade, Oracle RAC Installation, SQL Server AlwaysOn Installation, Database Migration, Disaster Recovery, Backup Restore, Performance Tuning, Periodic Healthchecks.I have done 2000+ Table replication with Goldengate or SQL Server Replication tool for DWH Databases in many clients.If you need Oracle DBA, SQL Server DBA, APPS DBA,  Exadata, Goldengate, EBS Consultancy and Training you can send my email adress [email protected].-                                                                                                                                                                                                                                                 -Oracle DBA, SQL Server DBA, APPS DBA,  Exadata, Goldengate, EBS ve linux Danışmanlık ve Eğitim için  [email protected] a mail atabilirsiniz.

Leave a Reply