How to run a stored procedure in TOAD 9.0

Dear Friends,
I am using TOAD 9.0 .
Running a procedure but getting the error ..
create or replace PROCEDURE UPD_TBL(I_table_name IN VARCHAR2) IS
CURSOR c_columns is select column_name from ALL_TAB_COLUMNS where
TABLE_NAME = I_table_name;
BEGIN
FOR rec in c_columns
LOOP
IF ( rec.COLUMN_NAME = 'X_NNM_TYPE_CD' ) THEN
UPDATE I_table_name set X_NNM_TYPE_CD = REPLACE (X_NNM_TYPE_CD, '-', '_')
WHERE INSTR (X_NNM_TYPE_CD, '-') > 0 ;
ELSIF ( rec.COLUMN_NAME = 'X_REVENUE_TYPE_CD' ) THEN
UPDATE I_table_name set X_REVENUE_TYPE_CD = REPLACE (X_REVENUE_TYPE_CD, '-', '_')
WHERE INSTR (X_REVENUE_TYPE_CD, '-') > 0 ;
END IF;
END LOOP;
EXCEPTION
when OTHERS then
NULL;
END UPD_TBL;
ERROR: TABLE OR VIEW DOES NOT EXIST.
Please let me know how to run the procedure in toad.
thanks/kumar

Kumar,
At a minimum, you would need to remove both the exception handler in your procedure and the exception handler in your anonymous block. As has been mentioned before, the code
EXCEPTION
  WHEN OTHERS THEN
    NULL;
END;is almost always a bug. In your case, your code is almost certainly generating an exception and your exception handler is silently catching and ignoring that exception. If you care whether or not any rows are updated, that is a bug.
Once you remove the exception handlers, you'll very likely discover that the SQL statements you are generating and executing dynamically are malformed. Off the top of my head, it would appear that there is no space between the table name and the SET keyword in the string you are constructing. That means that if I_TABLE_NAME is 'EMP', for example, you'd construct a statement like
UPDATE empSET x_nnm_typ_cd = ...'Oracle would interpret empSET as the table name, it would interpret X_NNM_TYP_CD as a table alias, and then it would encounter the equals sign unexpectedly and generate a syntax error. You'd need to insert a space after the table name and before the SET keyword (note where folks inserted extra spaces in their sample code).
In general, you are probably better served by having a local variable that you use to build up the SQL statement. That way, you can print (or log) the SQL statement that is constructed. When you encounter a syntax error at runtime, that will generally make debugging easier. So you'd probably want something like
  l_sql_stmt VARCHAR2(1000);
BEGIN
  FOR rec IN cur_c_columns LOOP
    IF (rec.column_name = 'X_NNM_TYPE_CD') THEN
      l_sql_stmt :=
         'UPDATE '||i_table_name||
         ' SET x_nnm_type_cd = REPLACE(x_nnm_type_cd, ''-'', ''_'')'||
         'WHERE INSTR(x_nnm_type_cd, ''-'') > 0';
      dbms_output.put_line( l_sql_stmt );
      EXECUTE IMMEDIATE l_sql_stmt;
...When you get a syntax error, you can then take a look at the SQL statement that was generated and debug the problem more easily.
Justin

Similar Messages

  • How to run a stored procedure in TOAD

    Hello,
    I created a simple stored procedure in the procedure editor in TOAD. It's just a simple 'Hello World' output statement. Here is the code:
    create or replace procedure new_proc is
    greetings varchar2(20);
    begin
    greetings := 'Hello World';
    dbms_output.put_line(greetings);
    end;
    The procedure created fine, but when I try to call it in the procedure editor or in the SQL Editor, both tools act as if the procedure cannot be found, and I get an error message.
    In SQL Editor, I type in:
    exec new_proc;
    and it says that "new_proc" is invalid.
    Does anyone know how to run this procedure in TOAD?
    Thanks,
    Peter
    Message was edited by:
    P. Swanson

    Don't know about TOAD but this is how it is in SQL*Plus.
    SQL> create or replace procedure new_proc is
      2  greetings varchar2(20);
      3  begin
      4  greetings := 'Hello World';
      5  dbms_output.put_line(greetings);
      6  end;
      7  /
    Procedure created.
    SQL> set serveroutput on
    SQL>
    SQL> exec new_proc ;
    Hello World
    PL/SQL procedure successfully completed.
    SQL>Message was edited by:
    Kamal Kishore

  • How to run oracle stored procedure dynamically

    How can I call a stored procedure dynamically. My requirement is to call a stored procedure based on user selection on a parameter screen. I do not want to hardcode proocedure name, but rather call dynamically.
    If I use the same methodology as of running dynamic sql's Iam getting an error.
    "invalid SQL statement after call to procedure"
    v_cursorid INTEGER;
    v_cnt NUMBER;
    v_sqlstring VARCHAR2(2000);
    v_sqlstring := 'execute insert_job_status('''||TO_CHAR(SYSDATE,
    'dd-mon-yyyy HH:mi:ss')||''');';
    v_cursorid := dbms_sql.open_cursor;
    dbms_sql.parse(v_cursorid, v_sqlstring, dbms_sql.v7);
    --cnt        := dbms_sql.execute(v_cursorid);
    dbms_sql.close_cursor(v_cursorid);

    EXECUTE is a SQL*Plus command. try
    v_sqlstring := 'begin  insert_job_status('''||TO_CHAR(SYSDATE,
    'dd-mon-yyyy HH:mi:ss')||'''); end;';Cheers, APC

  • CR2008 - How to run a Stored Procedure using Command Window

    Hi everybody,
    To generate my reports, I always adopted the foll. strategy:
      (a) Create a SQL Stored Procedure (with Input parameters) in Management Studio
      (b) Design a report in Crystal Report using the SP as datasource
    I want to experiment something different.
    Instead of using the SP as datasource, I wish to use the SQL Command window in CR2008.
    I have never succeeded to make it work.
    So, I am giving a simple example below , listing all my steps, so you can spot where my problem is:
    (A) Create a simple Stored Procedure in SSMS called [dbo].[usp_2014]
    USE [SIMUL02]
    GO
    /****** Object:  StoredProcedure [dbo].[usp_2014]    Script Date: 07/21/2014 12:40:22 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    ALTER PROCEDURE [dbo].[usp_2014] @Project nvarchar(15)
    AS
    SELECT DocEntry, DocDate, U_ShipDept, DocTotalSy FROM ORDR
    WHERE U_ShipCode = @Project
    (B) Create a Crystal Report called TEST.rpt
          I typed the following in the Command Window (see Capture.jpg)
              {CALL "SIMUL02"."dbo"."usp_2014";1({?Project1})}
    (C) I verify the database. I get this error message:
          Failed to retrieve data from the database
            Invalid character value for cast specification
    I am blocked from here.
    Please let me know what has gone and what I must do to continue my tests.
    Thanks
    Leon Lai

    Hi Abhilash
    I copied and pasted your formula:
    Exec "SIMUL02"."dbo"."usp_2014" '{?Project}'
    Now it works!
    So, probably I typed something wrong, and did not notice
    Thanks a lot for your patience and great reply
    Closing
    Leon Lai

  • Sqlbase - how to run a stored procedure with SYSDATE argument

    Hi, everyone!
    I'm trying to execute a stored procedure :
    cstmt = con.prepareCall("{ call PR_MYPROCEDURE(?, SYSDATE-1, SYSDATE) }");
    cstmt.setInt(1,1);And i get and SqlException - java.sql.SQLException: prepareCall(): An unexpected character 'S' found.
    Is there any way to pass a SYSDATE like argument?

    the problem that for sqlbase current date function is SYSDATE'sqlbase' the database?
    I couldn't ensure that the syntax that you posted looks correct but it seems possible.
    That would suggest there is a driver problem.
    Best I can suggest is modify the proc so it expects nulls for two parameters and then it creates the expressions that you are passing. Or create java Timestamp values and pass those.

  • How to run a stored procedure from sqlplus

    scehma name: aa
    package name: bb
    procedure name : cc
    I run the procedure from sql plus like this...
    execute aa.bb.cc
    I got error " not defined procedure" any one knows why? thanks!

    Based on the information you provided:
    1. You are not connected as Schema aa
    2. Schema aa has not granted permission to you to execute package bb.
    To resolve this issue:
    Connect as schema aa
    execute following statement:
    Grant execute on bb to Your_userName;connect as Your_userName
    On SQL*Plus prompt now you can execute this procedure using:
    execute aa.bb.cc;Assuming there is no parameter for procedure cc.
    You can create synoyms also to avoid specifying "aa".
    Thanks,
    Dharmesh Patel

  • How to schedule a Stored procedure to run every hour in SQL server express

    Hi,
    I am using SQL server express and I want to schedule a Stored procedure to run every hour.
    The Stored Procedure name is UpdateData.
    Can someone please give an example of how i can schedule this to run every hour, given that I do not have SQL Server agent on my express edition.

    Hello,
    You will find more options on the following thread.
    http://stackoverflow.com/questions/1675206/how-to-run-a-stored-procedure-every-day-in-sql-server-express-edition
    Hope this helps.
    Regards,
    Alberto Morillo
    SQLCoffee.com

  • How to execute a stored procedure/function in TOAD?

    Hi, All ,
    Can someone please tell me how to execute a stored procedure/function in TOAD?
    I have tired
    EXECUTE PROCEDURENAME(888), but it doesn’t work.
    TOAD give me the error: invalid SQL statement.
    Thanks a lot

    Write PL/SQl block.
    i.e Begin
    Procedure name..
    end;
    Then it will be excuted.
    Ashutosh

  • How can I execute Stored Procedures in PARALLEL and DYNAMICALLY ?

    Hi 
    I have a stored procedure. It can be executed like this
    exec test @p = 1;
    exec test @p = 2
    exec test @p = n;
    n can be hundred.
    I want the sp being executed in parallel, not sequence. It means the 3 examples above can be run at the same time.
    If I know the number in advance, say 3, I can create 3 different Execution SQL Tasks. They can be run in parallel.
    However, the n is not static. It is coming from a table. 
    How can I execute Stored Procedures in PARALLEL and DYNAMICALLY ?
    I think about using script task. In the script, I get the value of n, and the list of p, from the table, then running a loop with. In the loop, I create a threat and in the threat, I execute the sp like : exec test @p = p. So the exec test may
    be run parallel. But I am not sure if it works.
    Any idea is really appreciated.

    Hi nam_man,
    According to your description, you want to call stored procedures in parallel, right?
    In SSIS, we can create separate jobs with different stored procedures, then set the same schedule to kick the jobs off at the same time. In this way, we should be careful to monitor blocking and deadlocking depending on what the jobs are doing.
    We can also put all stored procedures in SSIS Sequence container, then they will be run in parallel.
    For more information about SSIS job and Sequence container, please refer to the following documents:
    http://www.mssqltips.com/sqlservertutorial/220/scheduling-ssis-packages-with-sql-server-agent/
    https://msdn.microsoft.com/en-us/library/ms139855(v=sql.110).aspx
    If you have any more questions, please feel free to ask.
    Thanks,
    Wendy Fu
    Wendy Fu
    TechNet Community Support

  • Running a stored procedure using  isqlPlus

    I have written a simple stored procedure which takes EMPLOYEE_ID as IN parameter returns EMPLOYEE_FIRST_NAME as OUT parameter (For Learning purpose only)
    How do I run this stored procedure using isqlPlus.
    Below is my stored procedure.
    CREATE OR REPLACE PROCEDURE "HR"."MY_PROC_2" (
    EMPLOYEE_ID_NUM in NUMBER,
    EMPLOYEE_FIRST_NAME out VARCHAR2
    as
    begin
    Select FIRST_NAME into EMPLOYEE_FIRST_NAME from Employees
    where Employee_ID = EMPLOYEE_ID_NUM;
    return;
    end;

    did you run that same procedure in SQL*Plus and it functioned ?
    Joel P�rez

  • Need an Example for How to call a Stored Procedure using DBAdapter

    Hi
    I am trying to invoke a stored procedure in Oracle Database using DB Adapter. I have successfully invoked and when i try to run it i got the following error.
    oracle.sysman.emSDK.webservices.wsdlapi.SoapTestException: Client received SOAP Fault from server : Exception occured when binding was invoked.
    Exception occured during invocation of JCA binding: "JCA Binding execute of Reference operation 'ExecuteScript' failed due to:
    Stored procedure invocation error.
    Error while trying to prepare and execute the RESONANCEDEMO.SP_QUERY API.
    An error occurred while preparing and executing the RESONANCEDEMO.SP_QUERY API. Cause: java.sql.SQLSyntaxErrorException: ORA-00917: missing comma
    ORA-06512: at "RESONANCEDEMO.SP_QUERY", line 7
    ORA-06512: at line 1
    Check to ensure that the API is defined in the database and that the parameters match the signature of the API.
    This exception is considered not retriable, likely due to a modelling mistake.
    To classify it as retriable instead add property nonRetriableErrorCodes with value "-917" to your deployment descriptor (i.e. weblogic-ra.xml).
    To auto retry a retriable fault set these composite.xml properties for this invoke: jca.retry.interval, jca.retry.count, and jca.retry.backoff.
    All properties are integers.
    I am trying to have a Out Parameter in my Procedure. Please provide me an example on how to invoke a Stored Procedure using Out Paramter using DB Adapter.

    Hi,
    It looks more like an Oracle error and not within the DbAdapter.
    Try to test first your procedure from PL/SQL or other developer you are using.
    Arik

  • How to Kill a Stored Procedure?

    Sombody knows how to kill a stored procedure from another stored peocedure?
    I wanna know if exists a way to use therads in sored procedures.
    Best Regards

    1) You can't. Unless you code a mechanism yourself, but then since
    you can't thread Procedure calls that wouldn't help much.
    2) You can try using DBMS_JOB, if your not in a hurry to have your procedure finish.
    This is PL/SQL, not Java. You have to imagine all you get is a single thread running
    static methods. You can get away from everything being static by using the CREATE TYPE
    OBJECT stuff. but that doesn't help you thread your processes.
    I hope someone else can give you a different answer,
    Eric Kamradt

  • How to compare two stored procedure

    I have two oracle database and each database have stored procedure
    How to compare two stored procedure?
    What is the command to compare the stored procedure?

    select line, text
    from user_source
    where name='....'
    minus
    select line, text
    from user_source
    where name='....'
    should do nicely.
    Or: get the procedure text to a file using dbms_metadata.get_ddl (9i and higher) and run diff (Unix) or fc (Windhoze) on it.
    You are a bit scarce on details.
    Better still: implement source control.
    Sybrand Bakker
    Senior Oracle D.B.A.

  • How to call Oracle Stored Procedure using EDQ

    Can someone tell me how to use Oracle Stored Procedure call in EDQ, sample scripts/steps will be really helpful. Thanks!

    It is also possible to do this using a custom processor in EDQ. The processor needs to do something very similar to the external task above (opens a DB connection, authenticates, runs a stored procedure).
    If you need this, please talk us through the use case so we can determine if it is the best fit. In some ways, an external task is better as logically a stored procedure call is normally divorced from any process logic in EDQ.
    Regards,
    Mike

  • How to execute oracle stored procedure through php as externally?

    hi...
    i am searching for the way that how to execute oracle stored procedure through web service, i am using php and mysql, i have some stored procedures in oracale database, i want to execute them, from php, means the database will be remain mysql, and the stored procedures of oracle will be executed externally...
    Kind regards,
    Wilayat.

    Ok, so first of all this is a kind of strange question. Since Oracle and MYSQL can happily live side by side.
    Make sure you have the oracle client (instant or regular ) installed and OCI_8 is set up and working correctly in PHP. If it is, when you run the phpinfo() routine you will see oci_8 on there. IF PHP connects just fine from the command line yet apache wont connect check permissions and things like the LD_Library Path.
    Then in php, right along with your MySQL statements run Oracle Statements eg:
    <?php
    $OraDB = oci_connect(name,pass,tnsname);
    $MySQLdb = mysql_connect([parms]);
    $oraQueryText = "begin sp_some_proc([some parms]); end;" ;
    $mysqlQuery = " Some mysql Query";
    $oraQuery = oci_parse($OraDB,$oraQueryText );
    oci_execute($oraQuery);
    mysql_execute([parms]);
    ?>
    Use the standard fetch code to get data from either of them.
    If you cannot and I mean absolutely cannot get an admin to link in OCI_8 then you still have recourse although it will be tedious as hell. PHP allows you to exec calls to the OS. You still MUST make sure the Oracle Client is installed and that sqlplus runs from the command line. You will more then likely have to have a shell script written to do this as well, but maybe not as I have never tried it with the exception of capturing the return value of sqlplus and you will have to dig into sqlplus to get it to send its results to a file you can then parse with php.
    Good Luck!

Maybe you are looking for