Solved

proc program returns ora-01458

Posted on 2002-04-11
6
2,473 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
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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Web Service from a stored procdure oracle 10 62
Distinct values from all columns in a table?? PL SQL 4 50
ODBC in excel 2016 in Windows 10 via VBA 16 147
Database Design Dilemma 6 58
Subquery in Oracle: Sub queries are one of advance queries in oracle. Types of advance queries: •      Sub Queries •      Hierarchical Queries •      Set Operators Sub queries are know as the query called from another query or another subquery. It can …
Have you ever had to make fundamental changes to a table in Oracle, but haven't been able to get any downtime?  I'm talking things like: * Dropping columns * Shrinking allocated space * Removing chained blocks and restoring the PCTFREE * Re-or…
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…

830 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