Execute Immediate with SQL in Stored Procedure

Dear Experts, Please help / guide on below statement which i want to execute in stored procedure,
EXECUTE IMMEDIATE 'INSERT INTO TABLE
SELECT COUNT(AGENTID) FROM TABLE_1 A,
TABLE_2 B, TABLE_3 C
WHERE A.COL = B.COL AND B.COL = C.COL AND
DT BETWEEN TRUNC(SYSDATE-1) + 1/24 + 0/12/60/60 AND TRUNC(SYSDATE-1) + 25/24 - 0/12/60/60';
Edited by: DBA on Dec 3, 2011 3:57 PM

So what's the problem? The only thing I can see is:
INSERT INTO TABLETABLE is reserved word, so name your table differently.
Also, I am assuming the above statement is actually generated from some variables based on some conditions, otherwise why would you need dynamic SQL, just issue:
INSERT INTO TABLE
SELECT COUNT(AGENTID) FROM TABLE_1 A,
TABLE_2 B, TABLE_3 C
WHERE A.COL = B.COL AND B.COL = C.COL AND
DT BETWEEN TRUNC(SYSDATE-1) + 1/24 + 0/12/60/60 AND TRUNC(SYSDATE-1) + 25/24 - 0/12/60/60;

Similar Messages

  • Unable to execute EXECUTE IMMEDIATE statement in a stored procedure...

    Hi People,
    I use oracle 10g.In which i tried a procedure with follwing code and am thrown with the error that says,
    SQL>   create or replace procedure ptable(ptab varchar2) is
      2  lstmt varchar(200);
      3  begin
      4  lstmt:='CREATE TABLE '||ptab||'(a int,b varchar2(30)) ';
      5  execute immediate lstmt;
      6  end;
      7  /
    Procedure created.
    SQL>  exec ptable('hos');
    BEGIN ptable('hos'); END;
    ERROR at line 1:
    ORA-01031: insufficient privileges
    ORA-06512: at "VIDYA.PTABLE", line 5
    ORA-06512: at line 1Procedure has been created but error occurs while executing it.why do i get this error even though i possess DBA privilege?.which permission is lagging for me?.help me with ur suggestions.thanks in advance.
    With Regards
    VIDS

    Yep Yep.Perfect.It was the CREATE ANY TABLE privilege which i was lagging.I granted it to my schema and now got created with the table.Thanku so much for such a quick reply :).
    With Regards
    VIDS

  • How to use lexical parameters with Sql Server Stored Procedure?

    Hi,
    I'm developing a BI Publisher report on a sql server database. I need to execute a stored procedure to dynamically build the query by replacing the lexical parameters with the values of varaibles of the stored procedure. With Oracle stored procedures, I have used data template and had reference the varaiable in SP by prefixing it with '&'.
    It doesn't work if I try to do the same thing with SQL server. Is there anyone who has come across the similar situation? Please let me know if anyone has got any ideas...
    Thanks in Advance
    Rag

    TopLink currently doesn't support multiple ResultSets. Multiple ResultSets support is considered for a future release.

  • Failure of EXECUTE IMMEDIATE when in a stored procedure

    Hello,
    this concerns behaviour observed in Oracle 10g on Windows.
    As user "system", I execute from the command line the following:
    SQL> select COUNT(1) from sys.dba_sequences;
    COUNT(1)
    645
    Again I try the same thing from the command line:
    SQL> declare
    2 CNT INTEGER:=0;
    3 STMT VARCHAR2(300);
    4 BEGIN
    5 STMT:='select COUNT(1) from SYS.DBA_SEQUENCES';
    6 EXECUTE IMMEDIATE STMT INTO CNT;
    7 dbms_output.put_line('CNT='||CNT);
    8 end;
    9 /
    CNT=645
    So far so good, clearly this table exists and I have sufficient privileges to access SYS.DBA_SEQUENCES as user system.
    However, if I put this in a stored procedure in a script TEST_SEQ.sql and then execute, I get ORA-00942:
    1. Create or replace Procedure TEST_A1
    2. IS
    3. CNT INTEGER:=0;
    4. STMT VARCHAR2(300);
    5.
    6. BEGIN
    7. STMT:='select COUNT(1) from SYS.DBA_SEQUENCES';
    8.     EXECUTE IMMEDIATE STMT INTO CNT;
    9.     dbms_output.put_line('CNT='||CNT);
    10. END;
    SQL> @ TEST_SEQ.sql
    SQL> exec TEST_A1;
    ORA-00942: Table or view does not exist
    ORA-06512: At "SYSTEM.TEST_A1", line 8
    ORA-06512: At line 1
    Why now does this table not seem to exist when accessed from a stored procedure?

    http://www.google.com/search?btnG=1&q=ora-0942+procedure
    Sybrand Bakker
    Senior Oracle DBA
    Experts: those who do read documentation.

  • Help with running a stored procedure

    Hi, could anybody help me with debugging this stored procedure:
    extraction_date in varchar2
    as
    begin
    execute immediate '
         declare
         /* Output file handler */
         fileHandler UTL_FILE.FILE_TYPE;
         asset_id VARCHAR2(60) := '''';
    cursor c_table is
         SELECT "ASSET ID"
         FROM REUT_MAIN_BOND
         WHERE MATURITY > TO_DATE(' || extraction_date || ', "MM-DD-YYYY");
         row c_table%ROWTYPE;
    begin
    fileHandler := UTL_FILE.FOPEN(''TEMP'', ''northfielddescupdate.in'', ''w'',32000);
         for row in c_table
         loop
         asset_id := row.ASSET;
         UTL_FILE.PUTF(fileHandler, ''asset_id'', ''\n'');
    end loop;
         UTL_FILE.FCLOSE(fileHandler);
    end;';
    commit;     
    end;
    when I run it - SQL> exec create_in_file('08102004')
    it gives me the following errors:
    ERROR at line 1:
    ORA-06550: line 8, column 11:
    PL/SQL: ORA-06553: PLS-103: Encountered the symbol "CALL" when expecting one of
    the following:
    <an identifier> <a double-quoted delimited-identifier>
    ORA-06553: PLS-112: end-of-line in quoted identifier
    ORA-06550: line 7, column 2:
    PL/SQL: SQL Statement ignored
    ORA-06550: line 6, column 8:
    PLS-00341: declaration of cursor 'C_TABLE' is incomplete or malformed
    ORA-06550: line 10, column 5:
    PL/SQL: Item ignored
    ORA-06550: line 15, column 14:
    PLS-00364: loop index variable 'ROW' use is invalid
    ORA-06550: line 15, column 2:
    PL/SQL: Statement ignored
    ORA-06512: at "PETAR_NORTHFIELD.CREATE_IN_FILE", line 6
    ORA-06512: at line 1
    Thank you for your help

    Q #1 (and possibly the only question) - why are you using NDS for this?

  • Executing a Variable in a Stored Procedure containing an Update Statement

    Hi,
    I have created a Stored Procedure, it has one input parameter. Inside the Stored Procedure there are 5 other variables are declared, based on the input parameter 4 of these variables are populated.
    Fifth variable is a a concatenation of text and some of these variables and creates a dynamic Update Statement. Once it is created I want to execute this variable but it is not executing.
    Could someone please help me in knowing how to execute a variable within a stored procedure that contains an update statement.
    Thanks for your help.
    Thanks
    Vineesh
    vineesh1701

    If you have set up the variable so that it contains a valid sql update, it should work.  For example, see below, which does do an update
    use tempdb
    go
    Create Table #Test(i int);
    Insert #Test(i) Values(1);
    go
    Create Procedure TestProc As
    Begin
    Declare @SQL nvarchar(250);
    Set @SQL = 'Update #Test Set i = 2';
    --Print @SQL;
    Exec sp_executesql @SQL;
    End
    go
    Exec TestProc
    -- Test Result
    Select * From #Test;
    go
    Drop Procedure TestProc;
    go
    Drop Table #Test;
    One thing I would recommend while testing is that you print out or select the variable that contains the dynamic sql.  (Like the above code where I have a print statement.  That lets you see exactly what you are executing and if there is any problem
    with the update command. 
    As Naomi said, to get anything more than general help, you will probably have to show us your code and the parameter values you are passing when you execute the stored proc.
    Tom

  • Can I issue this command in PL/SQL: EXECUTE IMMEDIATE '@filename.sql';

    can I issue this command in PL/SQL: EXECUTE IMMEDIATE '@filename.sql';

    Hi,
    Rather the opening a new process (sqlplus), a new connection (need password) etc... I would rather read and execute the file in pl/sql.
    I do not know if someone wrote it already, but here is a quick and dirty code for doing that with UTL_FILE.GET_LINE
    Here, I am only processing some DML statements and no SELECT statements. Correct it as you like !
    CREATE OR REPLACE PROCEDURE run_script ( dir_name IN VARCHAR2,file_name IN VARCHAR2)
    IS
    vSFile UTL_FILE.FILE_TYPE;
    vCmd VARCHAR2(200);
    vNewLine VARCHAR2(200);
    BEGIN
        vSFile := UTL_FILE.FOPEN(dir_name, file_name,'r');
        vCmd := NULL;
        IF UTL_FILE.IS_OPEN(vSFile) THEN
        LOOP
            BEGIN
                UTL_FILE.GET_LINE(vSFile, vNewLine);
                if (vCmd is null) THEN
                    if (upper(vNewLine) like 'INSERT%' or upper(vNewLine) like 'UPDATE%' or upper(vNewLine) like 'DELETE%') THEN
                        if (vNewLine like '%;') THEN
                            /* we have a single line command, execute it now */
                            dbms_output.put_line(substr(vNewLine,1, length(vNewLine)-1));
                            execute immediate substr(vNewLine,1, length(vNewLine)-1);
                        else
                            /* we have a command over multiple line, set vCmd */
                            vCmd := vNewLine;
                        end if;
                    else
                        /* ignore the rest like spool, prompt, accept, errors, host, @, ... */
                        null;
                    end if;
                else
                    if (vNewLine like '%;') THEN
                        /* we have a the last line of the command, execute it now */
                        vCmd := vCmd || ' ' || substr(vNewLine,1, length(vNewLine)-1);
                        dbms_output.put_line(vCmd);
                        execute immediate vCmd;
                        vCmd := null;
                    else
                        /* keep concatenating to vCmd */
                        vCmd := vCmd ||' '|| vNewLine;
                    end if;
                end if;
            EXCEPTION
                WHEN NO_DATA_FOUND THEN
                    EXIT;
                END;
        END LOOP;
        COMMIT;
        END IF;
        UTL_FILE.FCLOSE(vSFile);
    EXCEPTION
        WHEN utl_file.invalid_path THEN
            RAISE_APPLICATION_ERROR (-20052, 'Invalid File Location');
        WHEN utl_file.read_error THEN
            RAISE_APPLICATION_ERROR (-20055, 'Read Error');
        WHEN others THEN
            RAISE_APPLICATION_ERROR (-20099, 'Unknown Error');
    END run_script;
    set serverout on
    create directory scriptdir as '/home/oracle';
    grant read,write on directory to scott;
    exec run_script('SCRIPTDIR', 'test.sql')

  • Execute immediate with a string longer than 32767

    hello,
    is there a possibility to make an execute immediate with a statement, that is longer than the 32767 max. bytes for varchar`s? We get in a CLOB SQL-Statements with data that are longer than 32767. It would be easy if it were possible to make an execute immediate but because of the length limit it seems impossible. Does anybody know an alternative way to execute the sql-statements in the CLOB-Column?
    Anna

    6 execute immediate to_char(sql_text) into var_num;As a matter of interest have you tried this with a CLOB that is bigger than 32K?
    When I try it the PL/SQL limit gets enforced:
    SQL> declare
      2    c clob;
      3  begin
      4    dbms_lob.createtemporary(c, true);
      5    dbms_lob.writeappend(c, 43, 'CREATE OR REPLACE PROCEDURE big_p AS BEGIN ');
      6    for i in 1..800 loop
      7       dbms_lob.writeappend(c, 6, 'null;'||chr(10));
      8    end loop;
      9    dbms_lob.writeappend(c, 4, 'END;');
    10    execute immediate  to_char(c);
    11  end;
    12  /
    PL/SQL procedure successfully completed.
    SQL>  declare
      2    c clob;
      3  begin
      4    dbms_lob.createtemporary(c, true);
      5    dbms_lob.writeappend(c, 43, 'CREATE OR REPLACE PROCEDURE big_p AS BEGIN ');
      6    for i in 1..8000 loop
      7       dbms_lob.writeappend(c, 6, 'null;'||chr(10));
      8    end loop;
      9    dbms_lob.writeappend(c, 4, 'END;');
    10    execute immediate  to_char(c);
    11  end;
    12  /
    declare
    ERROR at line 1:
    ORA-06502: PL/SQL: numeric or value error
    ORA-06512: at line 10
    SQL> Cheers, APC

  • Converting SQL Server Stored Procedure to Oracle

    Hi there,
    I tried to use SwisSQL to convert my SQL Server stored procedure to Orcale without much success.
    Is there anyone who could help me out with this?
    My SQL Server Stored Procedure is:
    CREATE PROCEDURE [dbo].[SP_BackgroundCheckRequest]
         --MASTER Table
         @MASTER_ID int,
         @PERSONNEL_ID int = NULL,
    @DATE_OF_BIRTH datetime = NULL,
         @GENDER varchar(1) = NULL,
         @COUNTRY_OF_BIRTH varchar(3) = NULL,
    @TOWN_OF_BIRTH varchar(100) = NULL,
         @STATE_OF_BIRTH varchar(50) = NULL,
         @CHECK_CATEGORY varchar(10) = NULL,
         @CHECK_TYPE varchar(10) = NULL,
         @PRIORITY varchar(10) = NULL,
         @PRIORITY_REASON varchar(100) = NULL,
         @SCREENING_LEVEL nchar(1) = NULL,
         @POSITION nchar(50) = NULL,
         @REQUEST_SOURCE varchar(60) = NULL,
         --NAME_TYPE Table
         @NAME_TYPE varchar(5) = NULL,
         @FAMILY_NAME varchar(50) = NULL,
         @FIRST_NAME varchar(50) = NULL,
         @MIDDLE_NAME varchar(50) = NULL,
         @TITLE varchar(10) = NULL,
         @PREFFERED_NAME varchar(40) = NULL,
         @PREVIOUS_NAME varchar(140) = NULL,
         --ADDRESS_TYPE Table
         @ADDRESS_TYPE varchar(10) = NULL,
         @ADDRESS_LINE_1 varchar(30) = NULL,
         @ADDRESS_LINE_2 varchar(30) = NULL,
         @ADDRESS_LINE_3 varchar(30) = NULL,
         @COUNTRY varchar(3) = NULL,
         @SUBURB varchar(50) = NULL,
         @STATE varchar(50) = NULL,
         @POSTCODE varchar(15) = NULL,
         @START_DATE varchar(10) = NULL,
         @END_DATE varchar(10) = NULL,
         --LICENSE_TYPE Table
         @LICENSE_TYPE varchar(5) = NULL,
         @LICENSE_AGENCY varchar(15) = NULL,
         @LICENSE_NUMBER varchar(100) = NULL,
         @LICENSE_SIGHTED varchar(1) = NULL,
         --PHONE_TYPE Table
         @TELEPHONE_TYPE varchar(5) = NULL,
         @TELEPHONE_NUMBER varchar(20) = NULL,
         @MOBILE_TYPE varchar(5) = NULL,
         @MOBILE_NUMBER varchar(20) = NULL,
         @EXTENSION_TYPE varchar(5) = NULL,
         @EXTENSION_NUMBER varchar(20) = NULL,
         --PASSPORT_TYPE Table
         @PASSPORT_TYPE varchar(5) = NULL,
         @PASSPORT_NUMBER varchar(50) = NULL,
         @PASSPORT_COUNTRY varchar(3) = NULL,
         @PASSPORT_SIGHTED varchar(1) = NULL
    AS
    BEGIN TRANSACTION
    INSERT into MASTER (MASTER_ID, PERSONNEL_ID, DATE_OF_BIRTH, GENDER, COUNTRY_OF_BIRTH,
         TOWN_OF_BIRTH, STATE_OF_BIRTH, CHECK_CATEGORY, CHECK_TYPE, PRIORITY, PRIORITY_REASON,
         SCREENING_LEVEL, POSITION, REQUEST_SOURCE)
         VALUES (@MASTER_ID, @PERSONNEL_ID, @DATE_OF_BIRTH, @GENDER, @COUNTRY_OF_BIRTH,
         @TOWN_OF_BIRTH, @STATE_OF_BIRTH, @CHECK_CATEGORY, @CHECK_TYPE, @PRIORITY, @PRIORITY_REASON,
         @SCREENING_LEVEL, @POSITION, @REQUEST_SOURCE)
    IF @@ERROR <> 0
    BEGIN
         ROLLBACK
         RAISERROR ('Error inserting values into MASTER table!', 16, 1)
         RETURN
    END
    INSERT into NAME_TYPE (MASTER_ID,NAME_TYPE,FAMILY_NAME,FIRST_NAME,MIDDLE_NAME,TITLE)
         VALUES (@MASTER_ID,@NAME_TYPE,@FAMILY_NAME,@FIRST_NAME,@MIDDLE_NAME,@TITLE)
    IF @@ERROR <> 0
    BEGIN
         ROLLBACK
         RAISERROR ('Error inserting values into NAME_TYPE table!', 16, 1)
         RETURN
    END
    INSERT into ADDRESS_TYPE (MASTER_ID,TYPE,ADDRESS_LINE_1,ADDRESS_LINE_2,ADDRESS_LINE_3,
              COUNTRY,SUBURB,STATE,POSTCODE,START_DATE,END_DATE)
         VALUES (@MASTER_ID,@ADDRESS_TYPE,@ADDRESS_LINE_1,@ADDRESS_LINE_2,@ADDRESS_LINE_3,
              @COUNTRY,@SUBURB,@STATE,@POSTCODE,@START_DATE,@END_DATE)
    IF @@ERROR <> 0
    BEGIN
         ROLLBACK
         RAISERROR ('Error inserting values into ADDRESS_TYPE table!', 16, 1)
         RETURN
    END
    INSERT into LICENSE_TYPE (MASTER_ID,TYPE,AGENCY,NUMBER,SIGHTED_YN)
         VALUES (@MASTER_ID,@LICENSE_TYPE,@LICENSE_AGENCY,@LICENSE_NUMBER,@LICENSE_SIGHTED)
    IF @@ERROR <> 0
    BEGIN
         ROLLBACK
         RAISERROR ('Error inserting values into LICENSE_TYPE table!', 16, 1)
         RETURN
    END
    INSERT into PHONE_TYPE (MASTER_ID,TYPE,NUMBER)
         VALUES (@MASTER_ID,@TELEPHONE_TYPE,@TELEPHONE_NUMBER)
    IF @@ERROR <> 0
    BEGIN
         ROLLBACK
         RAISERROR ('Error inserting Telephone number into PHONE_TYPE table!', 16, 1)
         RETURN
    END
    IF ((@MOBILE_TYPE <> NULL) AND (@MOBILE_NUMBER <> NULL))
    BEGIN
         INSERT into PHONE_TYPE (MASTER_ID,TYPE,NUMBER)
              VALUES (@MASTER_ID,@MOBILE_TYPE,@MOBILE_NUMBER)
         IF @@ERROR <> 0
         BEGIN
              ROLLBACK
              RAISERROR ('Error inserting Mobile number into PHONE_TYPE table!', 16, 1)
              RETURN
         END
    END
    IF ((@EXTENSION_TYPE <> NULL) AND (@EXTENSION_NUMBER <> NULL))
    BEGIN
         INSERT into PHONE_TYPE (MASTER_ID,TYPE,NUMBER)
              VALUES (@MASTER_ID,@EXTENSION_TYPE,@EXTENSION_NUMBER)
         IF @@ERROR <> 0
         BEGIN
              ROLLBACK
              RAISERROR ('Error inserting Extension number into PHONE_TYPE table!', 16, 1)
              RETURN
         END
    END
    INSERT into PASSPORT_TYPE (MASTER_ID,NUMBER,COUNTRY,SIGHTED_YN)
         VALUES (@MASTER_ID,@PASSPORT_NUMBER,@PASSPORT_COUNTRY,@PASSPORT_SIGHTED)
    IF @@ERROR <> 0
    BEGIN
         ROLLBACK
         RAISERROR ('Error inserting values into PASSPORT_TYPE table!', 16, 1)
         RETURN
    END
    COMMIT

    First, a basic concept. That also illustrates how different Oracle is (and PL/SQL) from SQL-Server (and T-SQL).
    PL/SQL integrates two different languages. The PL language. The SQL language. It allows you to code SQL source code natively inside the PL language. The PL compiler is clever enough to do the rest - make calls to the SQL engine to create SQL cursors, bind PL variable values to bind variables in the SQL code. Etc.
    PL is a "proper" programming language. It is much like Pascal (it is based on Ada, a close family member of Pascal). It is nothing at all like T-SQL.
    Okay, now for the very basic rule for Oracle development.
    Maximize SQL. This means using the SQL language to crunch data. It is the "closest" to the data. It is designed and optimised for dealing with data. Do your data processing using SQL.
    Minimize PL/SQL. This means using the PL language not to crunch data, but to provide the conditional logic. Implement business rules. And then have the SQL language crunch the data as the data processing language.
    Attempting to directly translate T-SQL code into PL/SQL is flawed. It is like trying to make coffee with teabags. Yeah, the tea may have caffeine it, but it is not coffee.
    To do what that T-SQL script does, insert a row into a table, a typical PL/SQL equivalent will look as follows:
    create or replace procedure InsertMaster( masterRow master%rowtype ) authid definer is
    .. types and variables declared here
    begin
      -- masterRow is a record structure that matches the actual MASTER table
      .. apply business rules and validation to the data.. raising user exceptions as needed
      -- e.g. the POSITION column must be upper case
      masterRow.position := upper(masterRow.position);
      -- after the business logic and data validation we can add the row to the table
      -- (PL will make the INSERT call to the SQL engine)
      insert into master values masterRow;
    end;No commit. The caller does the business transaction. It needs to decide when to commit to maintain the integrity of the data in the database. It may need to do several more calls, before committing.
    With this approach, we can give the application schema (the caller) execute privs on this procedure. This procedure is defined with definer rights. This means it runs with the privs of owner of that procedure and MASTER table. It is trusted code. It does all the correct stuff to add a valid and checked row to the MASTER table. So we give the app schema execute privs on the procedure and no insert priv on the MASTER table.
    The only way the caller can add row to the MASTER table is via this trusted procedure of ours.
    And this is a typical approach in Oracle - using the PL/SQL (both PL language and SQL language) code to create an interface to a logical database in Oracle. Abstracting the complexities of SQL from the caller. Moving business and validation into PL. Allowing us the flexibility of modifying business and validation logic, without touching a single byte of caller/client code. Allowing us to manage and tune SQL performance without dealing with (badly designed and coded) SQL from a client - as the SQL resides in PL/SQL packages and procedures and functions.

  • Executing batch file from Java stored procedure hang

    Dears,
    I'm using the following code to execute batch file from Java Stored procedure, which is working fine from Java IDE JDeveloper 10.1.3.4.
    public static String runFile(String drive)
    String result = "";
    String content = "echo off\n" + "vol " + drive + ": | find /i \"Serial Number is\"";
    try {
    File directory = new File(drive + ":");
    File file = File.createTempFile("bb1", ".bat", directory);
    file.deleteOnExit();
    FileWriter fw = new java.io.FileWriter(file);
    fw.write(content);
    fw.close();
    // The next line is the command causing the problem
    Process p = Runtime.getRuntime().exec("cmd.exe /c " + file.getPath());
    BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
    String line;
    while ((line = input.readLine()) != null)
    result += line;
    input.close();
    file.delete();
    result = result.substring( result.lastIndexOf( ' ' )).trim();
    } catch (Exception e) {
    e.printStackTrace();
    result = e.getClass().getName() + " : " + e.getMessage();
    return result;
    The above code is used in getting the volume of a drive on windows, something like "80EC-C230"
    I gave the SYSTEM schema the required privilege to execute the code.
    EXEC DBMS_JAVA.grant_permission('SYSTEM', 'java.io.FilePermission', '&lt;&lt;ALL FILES&gt;&gt;', 'read ,write, execute, delete');
    EXEC DBMS_JAVA.grant_permission('SYSTEM', 'SYS:java.lang.RuntimePermission', 'writeFileDescriptor', '');
    EXEC DBMS_JAVA.grant_permission('SYSTEM', 'SYS:java.lang.RuntimePermission', 'readFileDescriptor', '');
    GRANT JAVAUSERPRIV TO SYSTEM;
    I have used the following to load the class in Oracle 9ir2 DB:
    loadjava -u [system/******@orcl|mailto:system/******@orcl] -v -resolve C:\Server\src\net\dev\Util.java
    CREATE FUNCTION A1(drive IN VARCHAR2) RETURN VARCHAR2 AS LANGUAGE JAVA NAME 'net.dev.Util.a1(java.lang.String) return java.lang.String';
    variable serial1 varchar2(1000);
    call A1( 'C' ) into :serial1;
    The problem that it hangs when I execute the call to the function (I have indicated the line causing the problem in a comment in the code).
    I have seen similar problems on other forums, but no solution posted
    [http://oracle.ittoolbox.com/groups/technical-functional/oracle-jdeveloper-l/run-an-exe-file-using-oracle-database-trigger-1567662]
    I have posted this in JDeveloper forum ([t-853821]) but suggested to post for forum in DB.
    Can anyne help?

    Dear Peter,
    You are totally right, I got this as mistake copy paste. I'm just having a Java utility for running external files outside Oracle DB, this is the method runFile()
    I'm passing it the content of script and names of file to be created on the fly and executed then deleted, sorry for the mistake in creating caller function.
    The main point, how I claim that the line in code where creating external process is the problem. I have tried the code with commenting this line and it was working ok, I made this to make sure of the permission required that I need to give to the schema passing security permission problems.
    The function script is running perfect if I'm executing vbs script outside Oracle using something like "cscript //NoLogo aaa1.vbs", but when I use the command line the call just never returns to me "cmd.exe /c bb1.bat".
    where content of bb1.bat as follows:
    echo off
    vol C: | find /i "Serial Number is"
    The above batch file just get the serial number of hard drive assigned when windows formatted HD.
    Same code runs outside Oracle just fine, but inside Oracle doesn't return if I exectued the following:
    variable serial1 varchar2(1000);
    call A1( 'C' ) into :serial1;
    Never returns
    Thanks for tracing teh issue to that details ;) hope you coul help.

  • How to execute multiple queries in one stored procedure.

    Hi,
    I am Kumar,
    How to execute multiple queries in one stored procedure.
    here is the my requirements,
    1. get the max value from one table and sum of the that value.
    2. insert the values and also sum of the max value.
    using stored procedure
    I am using SQL server 2000 database.
    Please help me.
    Advance thanks
    by,
    Kumar

    This is not a java question and it is not even a problem: your only problem is
    1) lack of knowledge
    2) lack of interest to find a manual
    But you are going to have to change both by actually reading a book or a manual that explains the stored procedure language of SQL Server. It is the same as Sybase I think, so you could also look for a manual for that DBMS.

  • Please Help!!!!! Problem Migrating from sql 2000 stored procedure to PL/SQL

    I have used a tool to convert my sql 2000 stored procedure to Oracle 10g PL/SQL, here is an example
    SQL 2000 Stored Procedure
    CREATE PROCEDURE [GetEmployees]
    AS
    Select * from EMPMST ORDER BY emp_name
    GO
    After Transformation i got 2 files, one was a procedure and other a package
    CREATE OR REPLACE PACKAGE GLOBALPKG
    AS
         TYPE RCT1 IS REF CURSOR;
         TRANCOUNT INTEGER := 0;
         IDENTITY INTEGER;
    END;
    CREATE OR REPLACE PROCEDURE GetEmployees
         RCT1 IN OUT      GLOBALPKG.RCT1
    AS
    BEGIN
         OPEN RCT1 FOR
         SELECT *
         FROM EMPMST
         ORDER BY emp_name;
    END;
    When i execute the procedure GetEmployees i got this error :
    SQL> execute GetEmployees;
    BEGIN GetEmployees; END;
    ERROR at line 1:
    ORA-06550: line 1, column 7:
    PLS-00306: wrong number or types of arguments in call to 'GETEMPLOYEES'
    ORA-06550: line 1, column 7:
    PL/SQL: Statement ignored
    Please Help me in debugging this error. Thanks in advance.

    As the poster above mentioned you cannot call "GetEmployees" without a parameter.
    Note that the procedure declaration has the following line
    RCT1 IN OUT GLOBALPKG.RCT1
    This means that whenever you want to call the procedure you must pass it a variable of type GLOBALPKG.RCT1
    However unless this is merely a homework or learning exercise (i.e. you are not porting the code of a production application) i would strongly recommend that you do not attempt to simply convert the code to PL/SQL.
    The reasoning behind this is that Oracle's architecture will be completely different to the source of the original code and if you attempt to simply port the code (especially using an automatic tool) you will almost certainly hit problems.
    For example the SQL Server's 2000 code may (should be) be written based on SQL Server's locking strategy. Oracle's locking strategy is completly different if you try to use the same techniques as you do in SQL Server the performance will suffer.
    Porting a code or a database schema from one platform to another involves a lot of analysis in order to take advantage of the features of the destination platform.
    As I said this may not be important to you depending on why you are attempting a port.
    Good Luck.

  • How to call a sql server stored procedure from oracle

    Hi all,
    Please anybody tell me how to call a sql server stored procedure from oracle.
    I've made an hsodbc connection and i can do insert, update, fetch data in sql server from oracle. But calling SP gives error. when I tried an SP at oracle that has line like
    "dbo"."CreateReceipt"@hsa
    where CreateReceipt is the SP of sql server and hsa is the DSN, it gives the error that "dbo"."CreateReceipt" should be declared.
    my database version is 10g
    Please help me how can i call it... I need to pass some parameters too to the SP
    thanking you

    hi,
    thank you for the response.
    when i call the sp using DBMS_HS_PASSTHROUGH, without parameters it works successfully, but with parameters it gives the following error
    ORA-28500: connection from ORACLE to a non-Oracle system returned this message:
    [Generic Connectivity Using ODBC][Microsoft][ODBC SQL Server Driver]Invalid parameter number[Microsoft][ODBC SQL Server Driver]Invalid Descriptor Index (SQL State: S1093; SQL Code: 0)
    my code is,
    declare
    c INTEGER;
    nr INTEGER;
    begin
    c := DBMS_HS_PASSTHROUGH.OPEN_CURSOR@hsa;
    DBMS_HS_PASSTHROUGH.PARSE@hsa(c, 'Create_Receipt(?,?)');
    DBMS_HS_PASSTHROUGH.BIND_VARIABLE@hsa(c,1,'abc');
    DBMS_HS_PASSTHROUGH.BIND_VARIABLE@hsa(c,2,'xyz');
    nr:=DBMS_HS_PASSTHROUGH.EXECUTE_NON_QUERY@hsa(c);
    DBMS_HS_PASSTHROUGH.CLOSE_CURSOR@hsa(c);
    end;
    Create_Receipt is the sp which requires two parameters.
    please give me a solution
    thanking you
    sreejith

  • Can a SQL Server stored procedure call an SAP function module?

    Can a SQL Server stored procedure call an SAP function module.? The stored procedure will be called via a trigger when data records are added to a Z table.

    You have two options:
    - the other software can use the RFC SDK and call directly in the system
    - the other software can use a database connect
    Markus

  • How to run a SQL Server Stored Procedure

    I need to run a SQL Server Stored Procedure in answer, the stored procedure use a hash table (temporary table) and I nedd to pass a parameter to stored procedure
    anyone know if is it possible in OBIEE, if yes how.
    thank you
    max

    thank you, but I'm not understand what you mean. I need to run this command in answer "direct access database"
    exec storedprocedure 1,1,1
    if I run this I receive thi error:
    error : [nQSError: 16001] ODBC error state: S0002 code: 208 message: [Microsoft][ODBC SQL Server Driver][SQL Server]object name '#TempList' not valid.. [nQSError: 16002] Cannot obtain number of columns for the query result. (HY000).
    here is the code of stored procedure:
    ROC [dbo].[GetOrderListmax]
    @OrderList varchar(500)
    AS
    BEGIN
    SET NOCOUNT ON
    CREATE TABLE #TempList
    OrderID int
    DECLARE @OrderID varchar(10), @Pos int
    SET @OrderList = LTRIM(RTRIM(@OrderList))+ ','
    SET @Pos = CHARINDEX(',', @OrderList, 1)
    IF REPLACE(@OrderList, ',', '') <> ''
    BEGIN
    WHILE @Pos > 0
    BEGIN
    SET @OrderID = LTRIM(RTRIM(LEFT(@OrderList, @Pos - 1)))
    IF @OrderID <> ''
    BEGIN
    INSERT INTO #TempList (OrderID) VALUES (CAST(@OrderID AS int)) --Use Appropriate conversion
    END
    SET @OrderList = RIGHT(@OrderList, LEN(@OrderList) - @Pos)
    SET @Pos = CHARINDEX(',', @OrderList, 1)
    END
    END
    SELECT o.OrderID, CustomerID, EmployeeID, OrderDate
    FROM dbo.Orders AS o
    JOIN
    #TempList t
    ON o.OrderID = t.OrderID
    END

Maybe you are looking for

  • Mapping with xml-schema XML-data to relational tables

    Hello, is it possible to map data from xml documents to relational tables with xml-schema? I mean not in nested tables but in relational tables with primary and foreign keys! With SQL Server 2005 it is very easy, I dont believe that Oracle couldn't d

  • Office or i work

    i am a previous user of windows now will be with mac pro. which office software is better? iwork or office 2011. i love the templetes of keynote, pages and numbers,they have much higher scence of beauty in work than office in windows, But what about

  • SOAP & Proxies

    >>SOAP What is use & advantage of SOAP adapter.. any example scenario on this.. >>Proxies 1. <b>Can't</b> we use ABAP Proxy (directly with out IDOC or RFC Adapter) to communicate with SAP R/3 Versions 4.6C and Below? 2. Can we use Java Proxy to commu

  • Drop parent table

    how to drop a parent table??? if there is hundreds of child table,then it is not possible to disable all the Foreign key one by one...

  • How to clear in the report

    I have some delivery numbers delivery I have triggered GI to site, but there are still some items pending at GIT report.  Could you help to check the reason and indicate how to clear them in the report.