Executing create or replace procedure statement from plsql script

Hi ,
I want to execute create or replace procedure from pl/sql block without using execute immediate or dbms_sql, please let me know if feasible.
Eg:
declare
begin
create or replace procedure .....
if v_temp = 4 then
end if;
end;
Thanks for help.
Regards,
RK

user588487 wrote:
Actual requirement is I have .sql file which has Create procedure command in it
and i have to conditionally execute the above .sql file so going for a pl/sql block.
Eg:
begin
if variable1 <> variable2 then
@xyz.sql -- contains create or replace procedure statement
insert into tablexyz.....
end if;
end;
Won't work. The PL/SQL code block (also called an anonymous block) is shipped from the client (e.g. SQL*Plus) to the database server. There it is parsed and executed.
It cannot execute SQL*Plus code.
There are 2 basic approaches to address this requirement.
Method 1. Use PL/SQL and SQL to perform the conditional logic checks that SQL*Plus cannot. Use bind variables to "copy" the results between SQL*Plus and PL/SQL, use substitution variables to execute the conditional branch (as a script) in SQL*Plus.
Basic example:
SQL> --// bind variable for passing data to PL/SQL code and
SQL> --// to receive data from PL/SQL code
SQL> var status varchar2(100)
SQL>
SQL> declare
  2          function ExistsTable( tableName varchar2 ) return boolean is
  3                  i       integer;
  4          begin
  5                  select 1 into i
  6                  from    user_objects
  7                  where   object_type = 'TABLE'
  8                  and     object_name = tableName;
  9                  return( true );
10          exception when NO_DATA_FOUND then
11                  return( false );
12          end;
13  begin
14          --// determine if table exists
15          if not ExistsTable( 'FOOTAB' ) then
16                  --// table does not exists and SQL*Plus client
17                  --// needs to run the footab client script
18                  :status := 'footab.sql';
19          else
20                  :status := 'do-nothing.sql';
21          end if;
22  end;
23  /
PL/SQL procedure successfully completed.
SQL>
SQL> --// use a substitution variable to determine what to do
SQL> set define on
SQL> col STATUS new_value SCRIPT
SQL> select :status as STATUS from dual;
STATUS
footab.sql
SQL>
SQL> --// execute the relevant script (i.e. execute the conditional
SQL> --// branch of the PL/SQL IF condition
SQL> @ &SCRIPT
SQL> --// file: footab.sql
SQL>
SQL> create table footab(
  2          id      number primary key,
  3          col1    number,
  4          col2    date
  5  ) organization index
  6  /
Table created.
SQL>
SQL> --//eof
// running the same steps when the table does exist
SQL> --// bind variable for passing data to PL/SQL code and
SQL> --// to receive data from PL/SQL code
SQL> var status varchar2(100)
SQL>
SQL> declare
  2          function ExistsTable( tableName varchar2 ) return boolean is
  3                  i       integer;
  4          begin
  5                  select 1 into i
  6                  from    user_objects
  7                  where   object_type = 'TABLE'
  8                  and     object_name = tableName;
  9                  return( true );
10          exception when NO_DATA_FOUND then
11                  return( false );
12          end;
13  begin
14          --// determine if table exists
15          if not ExistsTable( 'FOOTAB' ) then
16                  --// table does not exists and SQL*Plus client
17                  --// needs to run the footab client script
18                  :status := 'footab.sql';
19          else
20                  :status := 'do-nothing.sql';
21          end if;
22  end;
23  /
PL/SQL procedure successfully completed.
SQL>
SQL> --// use a substitution variable to determine what to do
SQL> set define on
SQL> col STATUS new_value SCRIPT
SQL> select :status as STATUS from dual;
STATUS
do-nothing.sql
SQL>
SQL> --// execute the relevant script (i.e. execute the conditional
SQL> --// branch of the PL/SQL IF condition
SQL> @ &SCRIPT
SQL> prompt Nothing to do...
Nothing to do...
SQL> Method 2. Move all "client scripting" to the server. You can still use .sql files. These need to contain valid DDL that can be parsed and executed. On the server, the .sql files are loaded into a table.
This can be a physical load (e.g. using <i>DBMS_LOB.LoadFromFile()</i>). Or you can keep the .sql files on the server and use BFILE pointers instead to the files.
You can now use execute immediate to execute the contents of a .sql file as a CLOB that was read from the table containing the .sql scripts.
To be honest - I have used both methods extensively in the past and no longer bother using either. Table exists when running the table create script? So what. If the table should not exist, use server exceptions in SQL*Plus to cease processing and exit. If it does not matter whether the table exists or not, why be concern with running the script to create the table if the table already exists?

Similar Messages

  • Ampersand substitution in create or replace procedure statement

    Hi Guys,
    I wonder why my ampersand substitution does not work in a create or replace stored procedure statement.
    CREATE OR REPLACE PROCEDURE UPDATE_DIM_SALES AS
    UNDEFINE DimSales;
    UNDEFINE FactTable;
    DEFINE DimSales = 'TESTTAB';
    DEFINE FactTable = myfact;
    BEGIN
    Error(5,20): PLS-00103: Encountered the symbol "=" when expecting one of the following: := . ( @ % ; not null range default character
    If I then assign the value with := I get the error "invalid table" later on for the INSERT statemnt:
    CREATE OR REPLACE PROCEDURE UPDATE_DIM_SALES AS
    UNDEFINE DimSales;
    UNDEFINE FactTable;
    DEFINE DimSales := 'x2';
    DEFINE FactTable := 'x1';
    BEGIN
    INSERT INTO &DimSales  (column1, column2,...)
    Why does ampersand substitution not work within a stored procedure?

    Hi,
    Thanks for the suggestion.
    The IF---ELSE Logic I have to write is quite complex.
    I dont think joins will not do the trick and limiting the collection size to smaller than 4000 seems not very practical. there
    is no poin using a collection if I have to use X amout of them.
    UNDEFINE DimSALES;
    UNDEFINE FactTable;
    DEFINE DimSALES = 'TESTTAB';
    DEFINE FactTable = 'testfact';
    --Collect all distinct SELLERNr into materialized views
    CREATE MATERIALIZED VIEW v1 AS select distinct SELLERnr from &FactTable;
    CREATE MATERIALIZED VIEW v2 AS select distinct SELLER_ID from &DimSALES;
    DECLARE
    v_SELLERNr VarChar(9);
    CURSOR v1_cursor IS Select * from v1;
    l_exists INTEGER;
    BEGIN
    OPEN v1_cursor;
    LOOP
    FETCH v1_cursor INTO v_SELLERNr;
    EXIT WHEN v1_cursor%NOTFOUND;
    SELECT COUNT(*) INTO l_exists FROM v2 WHERE SELLER_id =v_SELLERNr AND ROWNUM = 1;
    IF l_exists <> 1 THEN
    INSERT INTO &DimSALES (K_SALES,REG,BVL,DS, VS,RS,SELLER_ID,VK,VALID_FROM)
    (SELECT SEQ_DIM_SALES.NEXTVAL ,REG, BVL,DS, VS,RS,SELLERNR,VK,sysdate from &FactTable where SELLERNR =v_SELLERNr);
    commit;
    ELSE
    --Update old combination(s), invalidate (DATE)
    UPDATE &DimSALES SET VALID_TO = SYSDATE -1 WHERE REG||BVL||DS||VS||RS||SELLERNR||VK IN(
    --In case the SELLER and combinations exists and differs from what is in the dimension then invalidate old combinations and insert new ones
    SELECT * FROM(
    SELECT REG||BVL||DS||VS||RS||SELLERNR||VK WHERE SELLERNR = v_SELLERNr FROM &FactTable;
    MINUS
    SELECT REG||BVL||DS||VS||RS||SELLERNR||VK WHERE SELLERNR = v_SELLERNr FROM &DimSALES;)
    commit;
    --Insert new combination
    INSERT INTO &DimSALES (K_SALES,REG,BVL,DS, VS,RS,SELLER_ID,VK,VALID_FROM)
    (SELECT SEQ_DIM_SALES.NEXTVAL ,REG, BVL,DS, VS,RS,SELLERNR,VK,sysdate from &FactTable where SELLERNR =v_SELLERNr) subselect;
    WHERE &DimSALES.SELLER_Id=v_SELLERNr AND subselect.REG||BVL||DS||VS||RS||SELLERNR||VK NOT IN &DimSALES.REG||BVL||DS||VS||RS||SELLERNR||VK
    commit;
    END IF;
    END LOOP;
    CLOSE v1_cursor;
    END;
    DROP MATERIALIZED VIEW v1;
    DROP MATERIALIZED VIEW v2;
    -----------------

  • CREATE OR REPLACE PROCEDURE return data like SELECT statement

    "SELECT * FROM SEARCH_KEYWORD" is successfully done and return the data of the tables. Now, I want to run that on server side using PROCEDURE.
    I successfully executed the below scripts. Please teach me how to call the sp_test procedure. OR if you have other way or maybe my scripts are wrong.
    CREATE OR REPLACE PACKAGE GLOBALPKG
    AS
         TYPE RCT1 IS REF CURSOR;
         TRANCOUNT INTEGER := 0;
         IDENTITY INTEGER;
    END;
    CREATE OR REPLACE PROCEDURE LPG.sp_test
         RCT1 IN OUT      GLOBALPKG.RCT1
    AS
    BEGIN
         OPEN RCT1 FOR
         SELECT *
         FROM SEARCH_KEYWORD;
    END;
    Here is my table definition:
    CREATE TABLE LPG.SEARCH_KEYWORD
    FRACTION VARCHAR2(50),
    KEYWORD VARCHAR2(50),
    PURPOSE VARCHAR2(50),
    REMARKS VARCHAR2(50),
    DATE_INSERTED DATE DEFAULT sysdate
    PCTFREE 10
    PCTUSED 40
    MAXTRANS 255
    TABLESPACE SYSTEM
    STORAGE(INITIAL 64K MINEXTENTS 1 MAXEXTENTS 2147483645 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
    NOCACHE
    LOGGING
    Eros
    Japan

    Wrong forum. You should ask this question in the SQL and PL/SQL forum.
    Couple of comments though. Oracle is not SQL-Server. So calling a procedure that returns a ref cursor is different from a T-SQL macro procedure that functions like a view.
    Also, there is no need to use the SQL-Server standard (and silly one at that) of prefixing stored procedures using the text "sp_". In fact, the whole concept of Hungarian-like notation is something of the past and has no place in today's paradigm of software engineering.
    As for calling a a proc that returns a ref cursor, from SQL*Plus it will look as follows:
    SQL> var c refcursor
    SQL>
    SQL> exec LPG.sp_test( :c )
    SQL> print c
    Ref cursor needs to be supported by the client language you use to make this call to Oracle.

  • CREATE OR REPLACE PROCEDURE dq_setAllCollOptionsForColl (srcCollId INT, s

    CREATE OR REPLACE PROCEDURE dq_setAllCollOptionsForColl
    (srcCollId INT,
    collId INT)
    AS
    BEGIN
    INSERT INTO dq_spidering_options
    SELECT collId, id_type, file_types, file_extns, sub_directories,
    max_files, min_file_size, max_file_size, protocols_to_fetch, reanalysis_option,
    page_download_timeout, page_download_retries, page_download_pause, thread_count FROM dq_spidering_options
    WHERE id = srcCollId AND id_type = 'S';
    INSERT INTO dq_exclude_includes
    SELECT collId, id_type, entity, type from dq_exclude_includes WHERE id = srcCollId AND id_type = 'S'
    EXEC dq_setSiteOptionsForSites srcCollId, collId
    END dq_setAllCollOptionsForColl;
    how do i fix this?

    how do i fix this? Well, for us to say how, you need to tell what's wrong?
    To start with, EXEC is a SQL*Plus command not to be used within stored procedures. also, you seem to be calling another stored procedure with two parameters. you need to change that line as:
    dq_setSiteOptionsForSites(srcCollId, collId) ;

  • How to alter a button's enabled state from a script?

    How do I enable a button's enabled state from a script?
    The problem is, that I can't figure out how to reference that
    button!!! Let's say I have this script:
    pbPreviewTest.enabled() = lbTest.length >= 1;
    OK... well how do I get my script to be able to access
    pvPreviewTest and lbTest?
    I got this mxml...
    <mx:Button id="pbPreviewTest" label="Preview Test"
    right="5" top="5" enabled="false"/>
    and this also:
    <mx:DataGrid id="lbTest" height="413" width="100%" y="31"
    draggableColumns="false">
    but it doesn't seem to work :(

    This is my mxml, how do I access pbPreviewTest from the
    application script?
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="
    http://www.adobe.com/2006/mxml"
    layout="absolute">
    <mx:Panel layout="absolute" top="0" bottom="0" left="0"
    right="0">
    <mx:Script>...
    </mx:Script>
    <mx:TextInput x="6" y="5" width="162"/>
    <mx:Button x="176" y="5" label="S" width="22"/>
    <mx:Button x="202" y="5" label="B" width="22"/>
    <mx:VDividedBox id="div1" x="0" y="35" height="100%"
    width="100%">
    <mx:HDividedBox width="100%" height="159">
    <mx:DataGrid id="lbPaths"
    initialize="lbPaths.dataProvider = acPaths" height="100%"
    sortableColumns="false" draggableColumns="false">
    <mx:columns>
    <mx:DataGridColumn headerText="Path"
    dataField="Name"/>
    </mx:columns>
    </mx:DataGrid>
    <mx:DataGrid id="lbView" height="100%" width="176"
    sortableColumns="false" draggableColumns="false">
    <mx:columns>
    <mx:DataGridColumn headerText="View"
    dataField="col3"/>
    </mx:columns>
    </mx:DataGrid>
    <mx:DataGrid id="lbQuestions" height="100%"
    draggableColumns="false">
    <mx:columns>
    <mx:DataGridColumn headerText="Title"
    dataField="col1"/>
    <mx:DataGridColumn headerText="Questions"
    dataField="col2"/>
    <mx:DataGridColumn headerText="Level"
    dataField="col3"/>
    <mx:DataGridColumn headerText="Apparatus"
    dataField="col3"/>
    </mx:columns>
    </mx:DataGrid>
    </mx:HDividedBox>
    <mx:Canvas id="cn1" width="100%" height="100%">
    <mx:Text x="3" y="7" text="Questions in Test:"
    width="209"/>
    <mx:DataGrid id="lbTest" height="413" width="100%" y="31"
    draggableColumns="false">
    <mx:columns>
    <mx:DataGridColumn headerText="No." dataField="col1"/>
    <mx:DataGridColumn headerText="Title"
    dataField="col2"/>
    <mx:DataGridColumn headerText="Question"
    dataField="col3"/>
    <mx:DataGridColumn headerText="Level"
    dataField="col4"/>
    <mx:DataGridColumn headerText="Apparatus"
    dataField="col5"/>
    </mx:columns>
    </mx:DataGrid>
    <mx:Button id="pbPreviewTest" label="Preview Test"
    right="5" top="5" enabled="false"/>
    </mx:Canvas>
    </mx:VDividedBox>
    <mx:Button x="300" y="5" label="Add"/>
    <mx:Button x="357" y="5" label="Remove"/>
    <mx:Button label="Preview Question" enabled="false"
    right="4" top="5"/>
    </mx:Panel>
    </mx:Application>

  • How To Execute SQL Statements From Shell Scripts?

    I need to extecute some SELECT statements from a shell scripts. Could anybody kindly tell me how to do that, or which document i should refer to ? Thank you very much!

    You can execute SQLPlus with the SQL in a file (sqlplus -s @<sql-script>).

  • Calling SQL statements from Shell scripts

    Hi,
    I want to call external package procedures, declare some variables & do some oracle validations in the shell script.
    How SQL environment is set in shell script & is this one time process or I have to write few statements before every SQL statement.
    Please explain with an example.
    Thanks..

    is this one time process Yes. Example :
    $ cat script.sh
    export ORACLE_HOME=/home/oracle/base/OraHome10
    export ORACLE_SID=db102
    export PATH=$ORACLE_HOME/bin:$PATH
    sqlplus -s / as sysdba << EOF
    select to_char(sysdate,'dd/mm/yyyy hh24:mi:ss') date_time
    from dual;
    exit
    EOF
    sqlplus -s / as sysdba << EOF
    col global_name for a60
    select * from global_name;
    exit
    EOF
    $ ./script.sh
    DATE_TIME
    27/02/2008 11:11:27
    GLOBAL_NAME
    DB102
    $

  • Calling SQL statement from a script problem

    Hello,
    I have a script e.g query.sh:
    #!/bin/sh
    sqlplus -s ${ORACLE_USER} << HIC
    set heading off
    set newpage none
    SELECT 'ALTER TABLE '||'TEST_TABLE'||' ADD PARTITION '||' P'|| TO_CHAR(TRUNC(sysdate+7), 'IYYY')||'W'|| TO_CHAR(TRUNC(sysdate+7), 'IW')||' VALUES LESS THAN(TO_DATE('''|| TO_CHAR(sysdate + 14, 'YYYYMMDD')||''',''YYYYMMDD''));' FROM DUAL;
    exit
    HIC
    This will actually give me: ALTER TABLE TEST_TABLE ADD PARTITION P2010W46 VALUES LESS THAN(TO_DATE('20101122','yyyymmdd'));
    I am executing this output from the second script. e.g create_part.sh
    #!/bin/sh
    SQL=`/home/bill/scripts/query.sh`
    sqlplus ${ORACLE_USER} << EOF
    set serveroutput on size 1000000
    set heading off
    $SQL
    exit
    EOF
    When I am running the 2nd script I am getting:
    SQL> SQL> SQL> SQL> 2 ALTER TABLE test_table ADD PARTITION P2010W46 VALUES LESS THAN(TO_DATE('20101122','yyy
    ERROR at line 1:
    ORA-01861: literal does not match format string
    I suspect that the output from the 1st script wraps to a second line, and it failes to execute properly.
    Oracle is 9i
    Please suggest a way to overcome this problem.
    Thank you in advance.

    If you are not passing in any variable values that you need the shell to substitute intot he source then placing the SQL into a separate .sql file and then just using start scriptname from the shell can simplify the code especially if any shell script meta-characters like '$' appear in the SQL. Otherwise you have to escape the meta-characters.
    sqlplus /nolog <<EOF
    start script_name
    exit
    EOF
    It is also possible to write the sqlplus script to accept substitution variable from the caller so the line above would look like start script_name $var1 $var2
    HTH -- Mark D Powell --

  • Executing system command (third party program) from extend script without showing console on windows

    I am using following code on mac:
    app.system("/path/to/external/executable &");
    It runs external program in background (without showing console/terminal).
    On windows I tried many things like:
    app.system('start "" "/path/to/external/executable"');
    app.system('start "" /B "/path/to/external/executable"');
    And I was also trying to solve it using visual basic.
    Unfortunately everytime I use app.system(...) then windows console is showed on the screen for half of the second, then it disappears and progrm runs in background. Is it possible to avoid showing console window? Maybe there is another way of executing third party program?

    You can try to save a vbscript :
    Dim objShell
    Set objShell = WScript.CreateObject( "WScript.Shell" )
    objShell.Run("""\path\to\external\executable"""), 0, True
    Set objShell = Nothing
    than just execute it from javascript: 
    var vbFile = new File("path to your vbscript file")
    vb.execute();

  • Stored Procedure Call from Bean Error - PLS-00201

              Hello all,
              I am using the java stored procedure code in the examples dir of weblogic51/examples/jdbc/...
              with one exception. I created the stored procedure as another user with more
              permissions than
              the user that the jdbc connection will be established with. I created a public
              synonym so the stored
              procedure doesn't have to be refered to as "username.proc_squareInt". I keep
              getting the following
              errors. The web user has execute permissions and I tried calling it both with
              the owner.proc_name
              and proc_name (which I know won't work since it won't be able to find it).
              Any help would be greatly appreciated.
              Sincerely,
              Michael Prinsen
              Tue Jul 17 13:47:41 MDT 2001:<E> <WebAppServletContext-et> Root cause of ServletException
              java.sql.SQLException: ORA-06550: line 1, column 7:
              PLS-00201: identifier 'WTHDBM.PROC_SQUAREINT' must be declared
              ORA-06550: line 1, column 7:
              PL/SQL: Statement ignored
                   at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:114)
                   at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:208)
                   at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:542)
                   at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1330)
                   at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteFetch(TTC7Protocol.java:757)
                   at oracle.jdbc.driver.OracleStatement.executeNonQuery(OracleStatement.java:1313)
                   at oracle.jdbc.driver.OracleStatement.doExecuteOther(OracleStatement.java:1232)
                   at oracle.jdbc.driver.OracleStatement.doExecuteWithBatch(OracleStatement.java:1353)
                   at oracle.jdbc.driver.OracleStatement.doExecute(OracleStatement.java:1760)
                   at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1807)
                   at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:332)
                   at oracle.jdbc.driver.OraclePreparedStatement.execute(OraclePreparedStatement.java:376)
                   at weblogic.jdbc.pool.PreparedStatement.execute(PreparedStatement.java:35)
                   at csu.et.testBean.getWeatherData1(testBean.java:46)
                   at jsp_servlet._test._tester._jspService(_tester.java:107)
                   at weblogic.servlet.jsp.JspBase.service(JspBase.java:27)
                   at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:120)
                   at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:138)
                   at weblogic.servlet.internal.ServletContextImpl.invokeServlet(ServletContextImpl.java:915)
                   at weblogic.servlet.internal.ServletContextImpl.invokeServlet(ServletContextImpl.java:879)
                   at weblogic.servlet.internal.ServletContextManager.invokeServlet(ServletContextManager.java:269)
                   at weblogic.socket.MuxableSocketHTTP.invokeServlet(MuxableSocketHTTP.java:365)
                   at weblogic.socket.MuxableSocketHTTP.execute(MuxableSocketHTTP.java:253)
                   at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:129)
              // START CODE
              package csu.et;
              import java.io.*;
              import java.sql.*;
              import java.util.*;
              import java.text.*;
              import java.beans.*;
              import java.math.*;
              import java.util.Date;
              import java.util.Locale;
              import csu.util.*;
              public class testBean {
              public String getWeatherData1() throws SQLException {
              Connection conn = null;
              conn = CSUConnection.getConnection("etSelectConnectionPool");
              // Create a stored proc - (CREATED ALREADY)
              // Statement stmt1 = conn.createStatement();
              // stmt1.execute("CREATE OR REPLACE PROCEDURE proc_squareInt " +
              // "(field1 IN OUT INTEGER, " +
              // " field2 OUT INTEGER) IS " +
              // "BEGIN field2 := field1 * field1; " +
              // "field1 := field1 * field1; END proc_squareInt;");
              // stmt1.close();
              String sql = "{call proc_squareInt(?, ?)}";
              CallableStatement cstmt1 = conn.prepareCall(sql);
              cstmt1.registerOutParameter(2, java.sql.Types.INTEGER);
              for (int i = 0; i < 5; i++) {
              cstmt1.setInt(1, i);
              cstmt1.execute();
              System.out.println(i + " " + cstmt1.getInt(1) + " " + cstmt1.getInt(2));
              cstmt1.close();
              conn.close();
              return("hard-coded stuff");
              //END CODE
              

    this is probably an oracle related issue, and has very little to do with
              Weblogic transactions.
              your easiest way to debug this is to open a SQL/Plus window, log in as user
              WTHDBM and try to run the command
              "execute proc_squareInt(5,5);"
              "execute owner.proc_squareInt(5,5);"
              if this doesn't work, consult Oracle technet on how to setup synonyms and
              permissions
              Filip
              ~
              Namaste - I bow to the divine in you
              ~
              Filip Hanik
              Software Architect
              [email protected]
              www.filip.net
              "Michael Prinsen" <[email protected]> wrote in message
              news:[email protected]...
              >
              > Hello all,
              >
              > I am using the java stored procedure code in the examples dir of
              weblogic51/examples/jdbc/...
              > with one exception. I created the stored procedure as another user with
              more
              > permissions than
              > the user that the jdbc connection will be established with. I created a
              public
              > synonym so the stored
              > procedure doesn't have to be refered to as "username.proc_squareInt". I
              keep
              > getting the following
              > errors. The web user has execute permissions and I tried calling it both
              with
              > the owner.proc_name
              > and proc_name (which I know won't work since it won't be able to find it).
              >
              > Any help would be greatly appreciated.
              >
              > Sincerely,
              >
              > Michael Prinsen
              >
              > Tue Jul 17 13:47:41 MDT 2001:<E> <WebAppServletContext-et> Root cause of
              ServletException
              > java.sql.SQLException: ORA-06550: line 1, column 7:
              > PLS-00201: identifier 'WTHDBM.PROC_SQUAREINT' must be declared
              > ORA-06550: line 1, column 7:
              > PL/SQL: Statement ignored
              >
              > at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:114)
              > at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:208)
              > at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:542)
              > at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1330)
              > at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteFetch(TTC7Protocol.java:757)
              > at
              oracle.jdbc.driver.OracleStatement.executeNonQuery(OracleStatement.java:1313
              > at
              oracle.jdbc.driver.OracleStatement.doExecuteOther(OracleStatement.java:1232)
              > at
              oracle.jdbc.driver.OracleStatement.doExecuteWithBatch(OracleStatement.java:1
              353)
              > at oracle.jdbc.driver.OracleStatement.doExecute(OracleStatement.java:1760)
              > at
              oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java
              :1807)
              > at
              oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedState
              ment.java:332)
              > at
              oracle.jdbc.driver.OraclePreparedStatement.execute(OraclePreparedStatement.j
              ava:376)
              > at weblogic.jdbc.pool.PreparedStatement.execute(PreparedStatement.java:35)
              > at csu.et.testBean.getWeatherData1(testBean.java:46)
              > at jsp_servlet._test._tester._jspService(_tester.java:107)
              > at weblogic.servlet.jsp.JspBase.service(JspBase.java:27)
              > at
              weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java
              :120)
              > at
              weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java
              :138)
              > at
              weblogic.servlet.internal.ServletContextImpl.invokeServlet(ServletContextImp
              l.java:915)
              > at
              weblogic.servlet.internal.ServletContextImpl.invokeServlet(ServletContextImp
              l.java:879)
              > at
              weblogic.servlet.internal.ServletContextManager.invokeServlet(ServletContext
              Manager.java:269)
              > at
              weblogic.socket.MuxableSocketHTTP.invokeServlet(MuxableSocketHTTP.java:365)
              > at weblogic.socket.MuxableSocketHTTP.execute(MuxableSocketHTTP.java:253)
              > at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:129)
              >
              >
              >
              > // START CODE
              >
              > package csu.et;
              >
              > import java.io.*;
              > import java.sql.*;
              > import java.util.*;
              > import java.text.*;
              > import java.beans.*;
              > import java.math.*;
              > import java.util.Date;
              > import java.util.Locale;
              > import csu.util.*;
              >
              > public class testBean {
              >
              > public String getWeatherData1() throws SQLException
              >
              > Connection conn = null;
              > conn = CSUConnection.getConnection("etSelectConnectionPool");
              >
              > // Create a stored proc - (CREATED ALREADY)
              > // Statement stmt1 = conn.createStatement();
              > // stmt1.execute("CREATE OR REPLACE PROCEDURE proc_squareInt " +
              > // "(field1 IN OUT INTEGER, " +
              > // " field2 OUT INTEGER) IS " +
              > // "BEGIN field2 := field1 * field1; " +
              > // "field1 := field1 * field1; END proc_squareInt;");
              > // stmt1.close();
              >
              > String sql = "{call proc_squareInt(?, ?)}";
              > CallableStatement cstmt1 = conn.prepareCall(sql);
              >
              > cstmt1.registerOutParameter(2, java.sql.Types.INTEGER);
              > for (int i = 0; i < 5; i++) {
              > cstmt1.setInt(1, i);
              > cstmt1.execute();
              > System.out.println(i + " " + cstmt1.getInt(1) + " " +
              cstmt1.getInt(2));
              > }
              >
              > cstmt1.close();
              > conn.close();
              > return("hard-coded stuff");
              > }
              >
              > }
              >
              > file://END CODE
              

  • Execute immediate issue while calling a procedure from plsql block

    Hi all,
    I have the following simple code ,my execute immediate is not working(I am pasting the error below as well)
    CREATE OR REPLACE PROCEDURE CALL_RAHUL_PROCEDURES
    AS
    strng varchar2(1000);
    BEGIN
    for i in (select proc_name,flag,id from rahul_procedures order by id)
    loop
    if (i.flag = 'Y')
    then
    strng := 'exec '||i.proc_name||'(''rahul'')';
    dbms_output.put_line(strng);
    execute immediate strng;
    end if;
    end loop;
    END CALL_RAHUL_PROCEDURES;
    Error:
    Connecting to the database INQDWD.
    ORA-00900: invalid SQL statement
    ORA-06512: at "ETLADMIN.CALL_RAHUL_PROCEDURES", line 17
    ORA-06512: at line 2
    exec RAHUL_HELLO_WORLD2('rahul');
    Process exited.
    Disconnecting from the database INQDWD.
    data in rahul_procedures table :
    Proc_name flag Id
    RAHUL_HELLO_WORLD     N     1
    RAHUL_HELLO_WORLD2     Y     2
    RAHUL_HELLO_WORLD     N     3
    RAHUL_HELLO_WORLD3     N     4
    please help.
    Regards
    Rahul

    Mac_Freak_Rahul wrote:
    Well I have to call 26 procedures one by one and the names of the procedures would be in a table'rahul_procedures' Which is 100% wrong.
    Data is stored in tables, program code is stored in procedures or view defintions.
    http://en.wikipedia.org/wiki/Data_%28computing%29
    >
    Data vs programs
    Typically, different files are used to store programs vs data. Executable files contain programs; all other files are data files.
    >
    So you have just violated the primary distinction between data and program code.
    I dont find anything strange in my question,Only because you do not appear to know what you are doing or the difference between data and program code.
    http://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:1943344500346351703
    >
    ugh, what an ugly "design". I can see your life will be full of performance issues, strange 'bugs', and other unpleasant side effects. I mean, it all looks "so cool", but it'll be a nightmare to maintain and enhance.
    but then you have the issue of binds, which will be intractable. You'd have to know the binds at compile time, but you have hidden all of your sql in a magic generic table - so you cannot possibly know your binds at compile time.
    I would suggest you discard all of this code (I am DEAD SERIOUS) and start over. This is a bad idea from the get go. Or at least do me a favor and do not use plsql (you make it look like a good database implementation, but it isn't)
    The objective here is to store SQL Statements in a Table(a sql repository) and just call the required SQL from the application using the sqlid using the sql_execute procedure. ...
    CHANGE YOUR OBJECTIVE.
    How about this for a good objective:
    the objective here is to store sql statement in a plsql routine (a sql repository, you call a procedure and we run sql) and just call the required sql form the applicatoin using the STORED PROCEDURE
    sorry, can I think of hacks to get you going? yes, application contexts come to mind - a fixed number of binds comes to mind. Am I going to work them out? No - it is the wrong way to approach a database application.

  • Executing an Oracle Stored Procedure from Sender JDBC adapter

    I could really use some help from someone who had done this before. 
    I've read the help about using the JDBC sender adapter, but it's not helping enough.
    I found this line: "Specify an SQL EXECUTE statement to execute a stored procedure, which contains exactly one SELECT statement.
    The expression must correspond to the SQL variant supported by the relevant JDBC driver. It can also contain table JOINs."
    That's definately what we want to do, but we can't figure out the syntax.
    The procedure in oracle looks like this:
    CREATE OR REPLACE PROCEDURE test_ref_cursor
    ( cur_generic IN OUT result_sets.cur_generic)
    as
    BEGIN
    Open cur_generic for
    select
       proposal_number,
       to_char(sequence_number),
       column_name,
       column_value,
       update_timestamp,
       update_user
       from
       coeus.sap_test;
    END test_ref_cursor;
    And we have tried every kind of statement we can think of, but the file adapter always gives us an "invalid sql statement" error.
    Does anyone know what syntax we need to put in the "Query SQL Statement" in the JDBC sender adapter in order to call this procedure?  Or is there something wrong with the procedure that is causing the error?
    <i>I will absolutely return and give points, but PLEASE read my whole post before answering and do not just link me to or quote the help for configuring a sender JDBC adapter or blogs that are about the JDBC adapter in general but do not deal with the issues I am having. Thank you.</i>

    Hi Vanda,
    Unfortunately, the sender JDBC adapter does not support Oracle's store procedure/function.  Unlike stored procedures from other database vendors, Oracle returns a cursor, not a resultset.  The sender JDBC adapter must send a resultset to XI.
    There are 2 possible ways you can accomplish this:
    1.  Use BPM and call the Oracle stored procedure using a receiver adapter via a asynch-synch bridge.
    2.  Develop a user-module for the adapter, which can be used with a sender adapter.
    Thanks
    Prasad

  • Procedure hangs while create or replace!

    Dear All,
    My Database is Oracle 11g RAC.
    I did few changes in one of my procedure and wanted to re-create it using CREATE OR REPLACE procedure...
    The statement hangs for a long time and the concurrency in OEM raises up to a very high level. I tried to find the blocking sessions but for some time there was no blocking session.
    I also tried stopping the activities on the tables used in this procedure.
    Kindly suggest me what should I do in this situation. I have also tried running the query directly from the server.
    Regards, Imran

    Hi,
    check for any locks & kill it , execute on each instance or use gv$
    alter session set nls_date_format='dd-mon-yy hh24:mi:ss';
    select /*+ CHOOSE */ a.sid, a.serial#,vp.spid,a.last_call_et,a.logon_time,a.status,sw.event, a.username,a.osuser, a.status,
    a.program,a.MACHINE, a.type ptype,b.owner, b.object, b.type
    from v$session a, v$access b,v$session_wait sw, v$process vp
    where a.sid=b.sid and b.sid=sw.sid  and a.paddr=vp.addr
    and b.type<>'NON-EXISTENT'
    and (b.owner is not null) and (b.owner<>'SYSTEM')  and (b.owner<>'SYS')
    and upper(b.object) like '%&obj_name%'
    ORDER BY 3;Thanks,
    Ajay More
    http://moreajays.blogspot.com

  • Execute create trigger script in a procedure

    Is it possible to create a trigger with pl/sql?
    I have made a procedure thats makes the create or replace trigger statement.
    (when i copy and past the statement the trigger is created succesvol)
    How can i execute the create trigger statement on the end of the procedure?
    Thanks.

    Well, then proceed with dynamic SQL.
    Or, in my opinion much better: produce a SQL script with variables for table name and trigger name.
    Then run this script with the appropriate values every time you have created a table.
    Cheers,
    Guido
    Edited by: Guido on Oct 22, 2008 10:30 AM

  • How to create a stored procedure that accepts an array of args from Java?

    I am to be creating a stored procedure that accepts an array of arguments from Java. How to create this? thanks
    Sam

    Not a PL/SQL question really, but a Java one. The client call is done via ThinJDBC/OCI to PL/SQL, This call must be valid and match the parameters and data types of the PL/SQL procedure.
    E.g. Let's say I define the following array (collection) structure in Oracle:
    SQL> create or replace type TStrings as table of varchar2(4000);
    Then I use this as dynamic array input for a PL/SQL proc:
    create or replace procedure foo( string_array IN TStrings )...
    The client making the call to PL/SQL needs to ensure that it passes a proper TStrings array structure.. The Oracle Call Interface (OCI) supports this on the client side - allowing the client to construct an OCI variable that can be passed as a TStrings data type to SQL. Unsure just what JDBC supports in this regard.
    An alternative method, and a bit of a dirty hack, is to construct the array dynamically - but as this does not use bind variables, it is not a great idea.
    E.g. the client does the call as follows: begin
      foo( TStrings( 'Tom', 'Dick', 'Harry' ) );
    end;Where the TStrings constructor is created by the client by stringing together variables to create a dynamic SQL statement. A bind var call would look like this instead (and scale much better on the Oracle server side):begin
      foo( :MYSTRINGS );
    end;I'm pretty sure these concepts are covered in the Oracle Java Developer manuals...

Maybe you are looking for

  • How do I write/use performance monitor to run an action when something happens?

    I notice that I get a popup if desktop resources are over-used asking me if I want to turn off the glass desktop. That's fine. I've been looking in Performance Monitor for how this is done, as I have a program that periodically runs amok and starts i

  • Query display as normal

    Hello Guru: I have created the query and the result like this. Customer   Product  Sales Volume 1                A            100                   B            200 Result                      300 I preferred to show like this Customer   Product  Sal

  • AME: Parallel notification is not working

    Hi, While setting up AME for Invoice Apporval(in R 12.1.2), even after configuring action type(approval-group chain of authority) ordering mode as "parallel" and voting menthod as "First Responder Wins", AME is not sending notification to all the mem

  • Is SWCV required to be present in production SLD? Debate

    I have DEV and QA XI systems pointing to one SLD and Production XI is on another SLD. I created Product and Software Component Version in DEV SLD and developed my scenario. After transporting to QA and subsequently to Production, the scenario runs fi

  • Labview end of file encountere​d

    After the crash I can't open the vi. Automatic backup is on. But in LVAutoSave folder i found only old archives. Is there any way to recover corrupted file or find a backup. LabView suppose to backup VIs every 5 minutes. Thanks, Nick Attachments: OA_