Solved

proc program returns ora-01458

Posted on 2002-04-11
6
2,485 Views
Last Modified: 2010-10-05
hello.

i have got a proc program that worked good on oracle 7, i compiled it to work with oracle 8 and when i try to tun it i get ora-01458 .

the problem is in the line :

dbms_output.get_line (:outtxt,:status);

the declaration of the relevant varaibles :

exec sql
   BEGIN DECLARE SECTION;
      VARCHAR  outtxt[255];
      int      status;
exec sql
   END DECLARE SECTION;

does anyone knows whay it doesnt work ?

tx.
   hagai.
0
Comment
Question by:hagaiy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 48

Expert Comment

by:schwertner
ID: 6933618
ENABLE Procedure
This procedure enables calls to PUT, PUT_LINE, NEW_LINE, GET_LINE, and GET_
LINES. Calls to these procedures are ignored if the DBMS_OUTPUT package is not
enabled.
If there are multiple calls to ENABLE, then buffer_size is the largest of the values
specified. The maximum size is 1,000,000, and the minimum is 2,000.
Syntax
DBMS_OUTPUT.ENABLE (
buffer_size IN INTEGER DEFAULT 20000);
Note: It is not necessary to call this procedure when you use the
SERVEROUTPUT option of Enterprise Manager or SQL*Plus.
0
 
LVL 1

Author Comment

by:hagaiy
ID: 6933770
i have this call on my program, this is the full program :



#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
EXEC SQL BEGIN DECLARE SECTION;
    VARCHAR  username[20];
    VARCHAR  password[20];
      VARCHAR  ora_sql_command[500];
EXEC SQL END DECLARE SECTION;

EXEC SQL INCLUDE SQLCA;

void main( int argc, char *argv[] )
{
   EXEC SQL INCLUDE sqlca.h;
   char *octo_env;
   char *exec_str;
   char *sql_cmd;
   char *procname;
   char *params;
   int args_len;
   int counter;
   int buf_size;
   int args_no;
   char msg[200];
   size_t buf_len, msg_len;

   exec sql
      BEGIN DECLARE SECTION;
         VARCHAR  outtxt[255];
         int      status;
   exec sql
      END DECLARE SECTION;

   /* Finding which enviroment do we work in */

   octo_env = getenv("OCTO_ENV");
   if ( !octo_env )
   {
      printf ("ERROR: enviroment OCTO_ENV must be declared.\n");
      exit(2);
   }
 
    strcpy (username.arr,"octo");
    strcat (username.arr,octo_env);
    username.len=strlen(username.arr);
    strcpy (password.arr,username.arr);
    password.len=strlen(password.arr);
   
 
 
 
   /* Checking for the number of arguments */
 
   args_no = argc - 1;
   if ( args_no < 1 )
   {
      printf("No procedure name\n");
      exit(2);
   }

   /* Connecting to the database */

   exec sql
      whenever sqlerror goto connect_error;
   exec sql
      connect :username identified by :password;

   /* Finding the procedure-name */

   procname = (char *) malloc ( sizeof(char) * strlen(argv[1]));
   if (!procname)
   {
      perror("malloc(procname) failed");
      exit(1);
   }

   strcpy (procname, argv[1]);
 
   /* Finding the length of the arguments */

   args_len = 0;
   for (counter=2;counter<=args_no;counter++)
   {
      args_len = args_len + strlen(argv[counter]) + 1;
   };
   args_len = args_len + 3;
 
   /* Preparing the paramters string */

   params = (char *) malloc ( sizeof(char) * args_len);  
   if (!params)
   {
      perror("malloc(username) failed");
      exit(1);
   }

   if ( args_no > 1 )
   {
      strcpy (params,"(");
      for (counter=2;counter<args_no;counter++)
      {
         strcat(params,argv[counter]);
         strcat(params,",");
      }
      strcat(params,argv[args_no]);
      strcat(params,");");
   }
   else
   {
      strcpy (params,";");
   }

   /* Making the executing string */

   exec_str = (char *) malloc ( sizeof(char) * strlen(params)+strlen(procname));
   if (!exec_str)
   {
      perror("malloc(exec_str) failed");
      exit(1);
   }

   strcpy (exec_str,procname);
   strcat (exec_str,params);

   /* Making the sql command to execute and executing it */

   sql_cmd = (char *) malloc ( sizeof(char) * strlen(exec_str) + 15);
   if (!sql_cmd)
   {
      perror("malloc(sql_cmd) failed");
      exit(1);
   }

   strcpy (sql_cmd,"begin ");
   strcat (sql_cmd,exec_str);
   strcat (sql_cmd," end;");
   strcpy (ora_sql_command.arr,sql_cmd);
   ora_sql_command.len = strlen(ora_sql_command.arr);
   
   /* Enabling the buffer for dbms_output */

   exec sql
      execute
         begin
            /*buf_size =  */
            dbms_output.enable(1000000);
         end;
      end-exec;
 
   exec sql
      whenever sqlerror goto exec_error;
   exec sql execute immediate :ora_sql_command;

   //exec sql
   //whenever sqlerror continue;

   /* Printing the output */

     exec sql
      execute
         begin
            dbms_output.get_line (:outtxt,:status);
         end;
      end-exec;
 
   while ( !status)
   {
      outtxt.arr[outtxt.len]='\0';
      printf ("%s\n",outtxt.arr);
      exec sql
         execute
            begin
               dbms_output.get_line (:outtxt,:status);
            end;
         end-exec;
   }

   /* Freeing the memory of the buffer */

   exec sql
      execute
         begin
            dbms_output.disable;
         end;
      end-exec;

   exit(0);

   /* Error in the connection */

   connect_error:
      fprintf(stderr,"%s: Cannot connect to the database\n",argv[0]);
      exit(2);

   exec_error:
      buf_len = sizeof (msg);
      sqlglm(msg, &buf_len, &msg_len);
      printf ("%.*s\n", msg_len, msg);
      exit(1);
}
0
 
LVL 22

Expert Comment

by:DrSQL
ID: 6934097
hagaiy,
    The question is: what's in the buffer that it's reading (get_line)?  It seems empty.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 4

Expert Comment

by:Bhatti
ID: 6934133
You buffer length is 2 byte. Increase it and will work.


Bhatti
0
 
LVL 7

Accepted Solution

by:
waynezhu earned 300 total points
ID: 6934169
There are some changes were made for Pro*C pre-compiler
from 7 to 8.

You need to initialize the length of OUT variable to avoid the error in 8, by adding a line, such as:

-------------------------------------------------------
exec sql
  BEGIN DECLARE SECTION;
     VARCHAR  outtxt[255];
     int      status;
exec sql
  END DECLARE SECTION;

outtxt.len=255;
-------------------------------------------------------
0
 
LVL 1

Author Comment

by:hagaiy
ID: 6939651
tx alot, that solved my problem.
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…
Via a live example, show how to take different types of Oracle backups using RMAN.

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question