Use of Java packages in Java stored procedures? (Oracle 10.2)

Hi all-
Does Oracle's Java stored procedures support Java packages? In all the examples I've seen, packages are never used, and when I added one to a test file, it compiled it just fine, but referencing the class from the package itself resulted in a compiling error.
In other words, it seems to make absolutely no difference if I preface my Java class with
package com.mycompany.whatever;
and while I can "import com.mycompany.whatever.MyClass" in another Java file, it seems to not care at all whether I do so or not.
Thanks for any clarification,
Ilford

Hi Ilford:
Sure you can use fully package notation in your Java classes.
Look at this Java source code:
http://dbprism.cvs.sourceforge.net/dbprism/cms-2.1/src/com/prism/cms/core/
All of them are Java Stored procedures.
Best regards, Marcelo.

Similar Messages

  • Using SQL Loader script in a Stored Procedure

    Can I use SQL Loader script in a stored procedure and then execute it from a front-end appl.? The reason for this seemingly convoluted solution is that the users don't want a batch load though the records volume is quite high (around 1 mil). Other loads using ODBC connection or OLE DB seem to be inferior to SQL Loader.

    I would suggest a couple of solutions:
    1. Have a cgi script that can upload the file to the server from a web ui, then have the cgi script call the sql*loader file, and it will insert into the database.
    2. You can try to use External tables. This is avaliable in 9i and onwards. You will be able to make any sql DML on the external table.
    I would normally use sql*loader, move the data to a staging table with nologging, and paralle loading. After it has been loaded into the staging table I would process it into my main tables. Have used this approach with up to 60 million records in one load.
    You can do calls to C procedures, Pro*C procedures through PLSQL, as well as java calls, or use Java stored procedures.
    My experience is that SQL*Loader is the fastest way to load data into the database.

  • Re-compiling a package in a stored procedure

    Hi All,
    We are using Oracle 10g. I have coded a stored procedure that does many things one of which is re-creating a Materialized View using Dynamic SQL. However, when this Materialized View is created, a package that this stored procedure needs, becomes invalid. What is the syntax for recompiling the package using Dynamic SQL? I tried something like script listed below, but I am getting "*ORA-24344: success with compilation error*" error message. I like to re-compile the package before it's use in this stored procedure.
    DECLARE
          v_sql         VARCHAR2 (1000);
          object_name   VARCHAR2 (50) := 'TEST.PS2_FNS366';
    BEGIN
           dbms_output.put_line('This is a test.');
           v_sql := 'Alter package ' || object_name || ' compile  package';
           dbms_output.put_line (v_sql);
           EXECUTE IMMEDIATE v_sql;
           v_sql := 'Alter package ' || object_name || ' compile  body';
           dbms_output.put_line (v_sql);
           EXECUTE IMMEDIATE v_sql;     
    END;Thanks,
    Seyed

    Hi Justin,
    I agree with you. Initially, I didn't want to use materialized view in the stored procedure to load a table, but I a kind of was forced into it. I first tried using an Oracle View, but then the Oracle package using it was not finding the view. Then I tried to grant select to it, that failed too. That is when I decided to use a materialized view because, at least I could issue the needed grants.
    After seeing your e-mail and Frank's, I went back to my original plan. I re-created the old view and then tried to give it the right grants. Here is what I tried and the resulting error message:
    GRANT SELECT ON STUDENT.v_ben_reg_case_number TO SCOTT A grant similar to above results in ORA-01720: grant option does not exit for one of the underlying tables. Our DBA tried granting a developer role a system privilege called under_any_role, but that didn't solve it either.
    Thank you for your assistance,
    Seyed

  • Call a function inside a package from a stored procedure

    Hello:
    I am kind of new to the stored procedure. Does anyone know how to call a function inside a package from another stored procedure?
    I have a existing function (func_b) inside a package (pack_a) and it returns a cursor. I want to call this function from a stored procedure (proc_c) so that I use the data inside the cursor.
    can I do the following in proc_c:
    my_cursor1 SYS_REFCURSOR;
    begin
    my_cursor1 := exec pack_a.func_b
    end
    It will be very helpful if anyone can point me to any reading or example. Thank you very much for your information.

    guys:
    Thank you for your information so far. I need some more help here. I was able to run the function in my stored procedure. However, I was not able to print the result on the screen to view the cursor result, although I am using dbms_output.put_line statement inside my stored procedure.
    I use the following statement to execute my stored procedure on sql*plus. I can tell the stored procedure is executed successfully, but I did see anything printed:
    DECLARE TEMP VARCHAR2(100);
    BEGIN PROC_LAWS_CAD_NAME_SEARCH('LPD', 'TEST DEVICE ID', 'TEST LAST NAME', 'TEST FIRST NAME', 'F', '11112009', TEMP); END;
    I tried to use 'set serveroutput on' and got the following error:
    ERROR:
    ORA-06502: PL/SQL: numeric or value error: host bind array too small
    ORA-06512: at line 1
    I am kind of confused now. thank you for your help.
    Jack
    Here is my procedure:
    create or replace
    PROCEDURE PROC_SEARCH
    ( AGENCY_ID IN VARCHAR2,
    DEVICE_ID IN VARCHAR2,
    L_NAME IN VARCHAR2,
    F_NAME IN VARCHAR2,
    SEX IN VARCHAR2,
    DOB IN VARCHAR2,
    CAD_NAME_SCH_RESULT_STR OUT VARCHAR2)
    AS
    v_agy_id varchar2(10);
    v_device_id varchar2(20);
    v_l_name varchar2(25);
    v_f_name varchar2(15);
    v_sex varchar2(1);
    v_dob date;
    -- this cursor is going to be used to store a list of warrant matching
    -- name search criteria
    cad_srch_cursor sys_refcursor;
    objSrch SEARCH_RESULT_TEMP%ROWTYPE;
    BEGIN
    cad_srch_cursor := SEARCH_PKG.SEARCH('TESTING', 'TESTER', null, null,null, null, getPhonetic('TESTING'));
    LOOP
    FETCH cad_srch_cursor INTO objSrch;
    EXIT WHEN cad_srch_cursor%NOTFOUND;
    --insert into SEARCH_RESULT_TEMP (name_last) values (objSrch.name_last);
    CAD_NAME_SCH_RESULT_STR := objSrch.name_last;
    dbms_output.put_line('First:'||objSrch.name_first||':Last:'||objSrch.name_last||':Middle:'||objSrch.name_middle);
    end LOOP;
    END PROC_LAWS_SEARCH;
    -----------------------------------------

  • How to get a list of values used in the WHERE filter of stored procedures and functions in SQL Server

    How can I get a list of values (one or more) used in the WHERE filter of stored procedures and functions in SQL Server?
    How can get a list of values as shown (highlighted) in the sample stored procedure below?
    ALTER PROC [dbo].[sp_LoanInfo_Data_Extract] AS
    SELECT   [LOAN_ACCT].PROD_DT,
                  [LOAN_ACCT].ACCT_NBR, 
                  [LOAN_NOTE2].OFCR_CD, 
                  [LOAN_NOTE1].CURR_PRIN_BAL_AMT, 
                  [LOAN_NOTE2].BR_NBR,
    INTO #Table1
    FROM
                    dbo.[LOAN_NOTE1],
                    dbo.[LOAN_NOTE2],
                    dbo.[LOAN_ACCT]
    WHERE
                    [LOAN_ACCT].PROD_DT = [LOAN_NOTE1].PROD_DT
                    and
                    [LOAN_ACCT].ACCT_NBR = [LOAN_NOTE1].ACCT_NBR
                    and
                    [LOAN_NOTE1].PROD_DT = [LOAN_NOTE2].PROD_DT
                    and
                    [LOAN_NOTE1].MSTR_ACCT_NBR = [LOAN_NOTE2].MSTR_ACCT_NBR
                    and
                    [LOAN_ACCT].PROD_DT = '2015-03-10'
                    and
                    [LOAN_ACCT].ACCT_STAT_CD IN
    ('A','D')
                    and
                    [LOAN_NOTE2].LOAN_STAT_CD IN
    ('J','Z')
    Lenfinkel

    Hi LenFinkel,
    May I know what is purpose of this requirement, as olaf said,you may parse the T-SQL code (or the execution plan), which is not that easy.
    I have noticed that the condition values in your Stored Procedure(SP) are hard coded and among them there is a date values, I believe some day you may have to alter the SP when the date expires. So why not declare 3 parameters of the SP instead hard coding?
    For multiple values paramter you can use a
    table-valued parameter. Then there's no problem getting the values.
    If you could elaborate your purpose, we may help to find better workaround.
    Eric Zhang
    TechNet Community Support

  • Empty strings when passing a Java object to a Stored Procedure

    Hi,
    I'm using the interface SQLData to pass Java objects to StoredProcedures. All the object's attributes 'arrive' to the Stored Procedure ok, except the strings, which are empty.
    Here is my Oracle object:
    TYPE OBJ_ASJFF_OBJ1 IS OBJECT (
    ARG1 CHAR(3),
    ARG2 NUMBER(4),
    ARG3 CHAR(4),
    ARG4 NUMBER(7),
    ARG5 NUMBER(13,2),
    ARG6 CHAR(1));
    The nested table of that object:
    TYPE TAB_ASJFF_OBJ1 AS TABLE OF OBJ_ASJFF_OBJ1;
    The procedure declaration:
    PROCEDURE Pup_Instaura_Processo (                              x_crCert IN TAB_ASJFF_OBJ1,
    x_cResult OUT CHAR(4)
    My SQLData implementation:
    public void writeSQL(SQLOutput stream) throws SQLException {
                   stream.writeString(getArg1());     
                   stream.writeInt(getArg2().intValue());
                   stream.writeString(getArg3());          
                   stream.writeLong(getArg4().longValue());     
                   stream.writeBigDecimal(getArg5());
                   stream.writeString(getArg6());
    Can anybody help me?
    Thanks in advance
    Rui Gonçalves

    not exactly what you wanted but ingredients can be found at
    - JPublisher's docuemntation (especially "Type Mapping Support Through PL/SQL Conversion Functions")
    - http://otn.oracle.com/sample_code/tech/java/jsp/Oracle9iJSPSamples.html (Best Hotels PL/SQL Sample )
    - http://otn.oracle.com/tech/xml/xdk_sample/xdksample_093001i.html
    hope this helps
    Kuassi
    I have a Java Stored procedure which takes an instance of a different java object as its parameter.
    I need to do this from a pl/sql package - can anyone point me to a sample etc (looked on the website but don't see one) ?
    Andrew

  • How to call a java method in a Stored procedure

    Hi.,
    I was trying to call a method in a stored procedure
    This was my procedure
    CREATE OR REPLACE PROCEDURE proc_copy_file(sr_file VARCHAR2,dt_file VARCHAR2)
    AS LANGUAGE JAVA
    NAME 'FileCopy.copyfile(String,String)'; // calling a java method
    /   this was my java method
    CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED "FileCopy" as
    import java.io.File;
      import java.io.IOException;
      import java.io.FileReader;
      import java.io.FileWriter;
      import javax.imageio.stream.FileImageInputStream;
      import javax.imageio.stream.FileImageOutputStream;
      import java.security.AccessControlException;
      public class FileCopy {
          // Define variable(s).
              private static int c;
              private static File file1,file2;
              private static FileReader inTextFile;
              private static FileWriter outTextFile;
              private static FileImageInputStream inImageFile;
              private static FileImageOutputStream outImageFile;
              // Define copyText() method.
              public static void copyfile(String fromFile,String toFile) throws AccessControlException
                // Create files from canonical file names.
                file1 = new File(fromFile);
                file2 = new File(toFile);
                // Copy file(s).
                try
                  // Define and initialize FileReader(s).
                  inTextFile  = new FileReader(file1);
                  outTextFile = new FileWriter(file2);
                  // Read character-by-character.
                  while ((c = inTextFile.read()) != -1) {
                    outTextFile.write(c); }
                  // Close Stream(s).
                  inTextFile.close();
                  outTextFile.close(); }
                catch (IOException e) {
                  System.out.println ("-------"); }
             // return 1;
          public static void main(String[] args){
                          switch(args.length){
                                  case 0: System.out.println("File has not mentioned.");
                                                  System.exit(0);
                                  case 1: System.out.println("Destination file has not mentioned.");
                                                  System.exit(0);
                                  case 2: copyfile(args[0],args[1]);
                                                  System.exit(0);
                                  default : System.out.println("Multiple files are not allow.");
                                                    System.exit(0);
    };while i am executing this method i m getting error as
    ORA-29531: NO METHOD COPYFILE IN CLASS FILECOPY
    ORA-06512: AT "RMVER721.PROC_COPY_FILE", LINE 1could anyone help me

    Looks like it is a matter of not quite the same namespace for String object.
    I can get it to work by the java source containing:
              public static void copyfile(java.lang.String fromFile,java.lang.String toFile) throws AccessControlExceptionAnd the PL/SQL source:
    NAME 'FileCopy.copyfile(java.lang.String,java.lang.String)'; // calling a java methodSeems like when you just use "String", then the namespace resolving in the java source is not the same as the namespace resolving in the PL/SQL?
    Addendum:
    You do not need to put java.lang.String in the java source, String will do (java.lang is by default "imported"?)
    But in the PL/SQL source java.lang namespace prefix is needed - java.lang is not "imported" here.
    Edited by: Kim Berg Hansen on Nov 23, 2011 1:07 PM

  • Passing of ResultSet to Stored Procedure(Oracle 8i)  from Java

    My requirement is such that I want to send a resultset to a stored procedure(In oracle8i). Through Java API's.
    The input parameter to the PLSQL is a ref cursor.
    I am trying to send the resultSet using CallableStatement of java but it is throwing an Inavlid column type error.
    So firstly is it possible to send a resultset to Oracle through java. If yes, then please suggest me as to how it can be done?

    Rajeev,
    I remember seeing something on Oracle's MetaLink Web site, saying that this is not supported. Sorry, but I can't give you any more details -- I don't remember (and I'm too lazy to look :-)
    I also think that I found that MetaLink article via a posting to one of these (i.e. Oracle) forums. Perhaps a search of the forum archives will help?
    Good Luck,
    Avi.

  • Java and Sybase nested stored procedures.

    Hi!
    I have nested Sybase stored procedures, the main procedure calls a helper stored proc.
    The main procedure returns 2 result sets before calling the helper store proc and helper store proc returns 1 resultset. After the helper store proc is called, the main store proc returns 2 more resultset. When I run it using SQL client tool the main procedure(and it's helper) execute well and returns rows.
    I need to call this store proc in a java code and display all the resultset in screen. I am using Statement:execute(<exec sp>) to execute the store proc and then statement.getResultSet() to get each resultset. The loop is controlled by statement.getMoreResults() .
    It displays the first 2 resultsets from main Store Proc. Then the control goes to helper store proc. It executes the helper store proc and displays the resultset from helper. But then it stops there and doesnot
    come back to main store proc to execute the remaining resultset.
    What I suspect is that, the statement object is getting overlaid when the call goes to helper proc.
    Any idea as to how to code to handle multiple nested resultset ?
    ~ RNS.
    My Sybase stored procedure code looks like -
    =======================================================================
    create procedure main_proc
    @param1 int
    as
    select getdate()
    select @@servername
    declare @return_val int
    exec proc2 @param1, @return_val out
    select myCol1,
    myCol2,
    myCol3=@return_val
    from mytable
    select db_name()
    ===========================================================================
    Sybase Code for proc2
    create procedure proc2
    @param1 int,
    @param2 int out
    as
    begin
    if something exists(select * from table where whereClause)
    select @param2="TRUE"
    else
    select @param2="FALSE"
    select getdate()
    end
    go
    GRANT EXECUTE...
    EXEC sp_procxmode 'dbo.proc2,'unchained'
    go
    ====================================================================
    Code snippet :-
    do {
    int iit=0;
    rs=stmt.getResultSet();
    if ( rs != null ) {
    ResultSetMetaData rsd = rs.getMetaData();
    int nocols = rsd.getColumnCount();
    for (int i=1; i<=nocols; i++)
    System.out.println(rsd.getColumnName(i)));
    while (rs.next())
    for (int i=1; i<=nocols; i++)
    System.out.println(rs.getString(rsd.getColumnName(i));
    } while (stmt.getMoreResults());

    I'm not 100% sure about this, but my guess is that this is caused by the TDS protocol (used by Sybase). TDS makes no difference between the stored procedure you are calling and the "inner" stored procedure, so the driver just returns update counts and result sets as they are generated, regardless of who generated them.
    Another guess (as I don't know what driver you are using) is that execute() returns the first result (update count or ResultSet), as opposed to executeQuery(), which returns the first ResultSet (probably discarding the update count). You can make sure of this by calling getMoreResults(); you should get your ResultSet at some point.
    Alin.

  • Java Script in a Stored Procedure

    I have a stored procedure. I use HTP Pacakge to generate the Page with HTML tags.
    I need to include a Javascript file in the stored procedure . I donno the path where the JS file resides in the Appserver meaning the context root.
    Any help in educating me the location where JS ,CSS,IMAGE files are placed
    in the appserver is most welcome.
    I am using Oracle 10g DB and Oracle 10g App server.

    The App Server has an Apache-based HTTP server. It uses the standard Apache config files - you can probably look at the $ORACLE_HOME/Apache/Apache/config/httpd.conf to find the document root.
    The $ORACLE_HOME is the App Server's Home, not the database's Home

  • Getting error code 1 when calling SSIS package from a stored procedure (SQL Server 2008 R2)

    Hello,
    I am trying to execute a SSIS package from SQL Server 2008 R2 stored procedure but getting error code 1 (as per my knowledge, error code description is as below:
    0 The package executed successfully.
    1 The package failed.
    3 The package was canceled by the user.
    4 The utility was unable to locate the requested package. The package could not be found.
    5 The utility was unable to load the requested package. The package could not be loaded.
    6 The utility encountered an internal error of syntactic or semantic errors in the command line.
    Details:
    I have a stored procedure named "Execute_SSIS_Package" (see below sp) which executes 'Import_EMS_Response' SSIS package (when I execute this package directly from SQL Server BID it works fine it means package itself is correct) and calling
    it from SQL as:- EXEC Execute_SSIS_Package 'Import_EMS_Response'.
    Here I receives error code 1.
    Can anyone help me to resolve this issue please?
    Thanks in advance!
    CREATE PROCEDURE [dbo].[Execute_SSIS_Package]
     @strPackage nvarchar(100)
    AS
    BEGIN
     -- SET NOCOUNT ON added to prevent extra result sets from
     -- interfering with SELECT statements.
     SET NOCOUNT ON;
     DECLARE @cmd VARCHAR(8000)
     DECLARE @Result int
     DECLARE @Environment VARCHAR(100)
        SELECT @Environment = Waarde
     FROM  Sys_Settings
     WHERE Optie = 'Omgeving'
     --print @Environment
     SET @strPackage = '"\W2250_NGSQLSERVER\BVT\' + @Environment + '\' + @strPackage + '"'
     SET @cmd = 'dtexec /SQL ' + @strPackage +  ' /SERVER "w2250\NGSQLSERVER"  /Decrypt "BVT_SSIS" /CHECKPOINTING OFF /REPORTING E'
     --print @cmd
     EXECUTE @Result = master..xp_cmdshell @cmd, NO_OUTPUT
     --print @Result
    END

    It has something to do with the security.
    E.g. cmdshell is not enabled or the caller has not rights over the package.
    There could be a syntax error, too.
    I suggest you make the package runnable off a SQL Agent job then trigger the job from the stored proc with
    sp_start_job <job name>
    Arthur
    MyBlog
    Twitter

  • Using an IN Clause in a Stored Procedure

    Hello All:
    I have come to the conclusion that my stored procedure is having a problem with the use of an IN clause using a parameterized query.
    I have in my Stored Procedure the following: AND oh.status_flag IN (p_OrderStatus)
    The p_OrderStatus will contain values along the lines of:
    1). p_OrderStatus = 'X'
    2). p_OrderStatus = 'X', 'S', 'W'
    In my .Net code, I am setting the parameter value as being:
    oCommand.Parameters.Add("p_OrderStatus", OracleDbType.Varchar2).Value = Status;
    However: this isn't working as something in the IN clause doesn't seem to work as I expected, but if I do the same query through a TORA window, it brings back values.
    What is causing this to stop working once I move it to a Stored Procedure and how do I fix it (either the .Net side or the Oracle Side, which I assume it would be something on the Oracle side of things).
    Any help is greatly appreciated
    Thanks
    Andy

    One way I've found to get around this is to have .net pass in a comma seperated list of values into the procedure, then have the procedure split it up into a table and use that in the IN. There's probably a better way to do it, but this works:
    create or replace
    TYPE "STRINGTABLETYPE" AS TABLE OF VARCHAR2(30);
    create or replace
    FUNCTION "FUNC_STR2STRTBL"
    ( p_str in varchar2 ) return
    stringTableType
    as
    l_str long default p_str || ',';
    l_n number;
    l_data stringTableType := stringTabletype();
    begin
    loop
    l_n := instr( l_str, ',' );
    exit when (nvl(l_n,0) = 0);
    l_data.extend;
    l_data( l_data.count ) := ltrim(rtrim(substr(l_str,1,l_n-1)));
    l_str := substr( l_str, l_n+1 );
    end loop;
    return l_data;
    end;
    Then in your actual query procedure, you can do something like this:
    SELECT * FROM table WHERE column IN (select * from THE (select cast(FUNC_STR2TBL(parameter) as STRINGTABLETYPE) from dual))

  • How to use Bpel output as input in stored procedure

    I am a SOA beginner. The scenario is to use the output from a BPEL process in a stored procedure as input and validate it against the data in the database. The data received from BPEL is compared with fields from different tables.
    It is basically a business process data validation.
    Will the output of BPEL be a Xml file and how it can b used in query of a procedure?
    Edited by: 869091 on Jun 29, 2011 12:14 AM

    The output from the BPEL process will be in XML format.
    Your requirement is not clear, please state it properly what are you trying to do.
    -Yatan

  • 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.

  • Problem in package run inside stored procedure

    i have ssis package to import data from excel to database.
    package is running correctly inside BIDS.
    but when i run package under stored procedure it is giving error :
    Error:   Code: 0xC0014023
       Source: loop sheets in excel
       Description: The GetEnumerator method of the ForEach Enumerator has failed with error 0x80040E21 "(null)". This occurs when the ForEach Enumerator cannot enumerate.

    Hi BI_DEV_19,
    Does the package connects with network resources? If so, try set the job step to run under a proxy account that is created based on a domain account. In BIDS, the package runs under the Windows account that you log onto the operating system.
    The error message “The GetEnumerator method of the ForEach Enumerator has failed with error 0x80040E21” may occur because the ADODB.dll file is corrupted or missing.  You can check whether the ADODB.dll exists in the following folder:
    C:\program files (x86)\Microsoft.NET\Primary Interop Assemblies
    In this situation, you can back up the existing ADODB.dll file, and copy one from another machine to this server.
    Regards,
    Mike Yin
    TechNet Community Support

Maybe you are looking for