Java versus PL/SQL Stored Procedure Issues

I am getting a result that is 30 times slower for Java when compared with PLSQL. Can you tell me if that is normal or am I missing something?
Thanks in advance for your help,
Gaurav Pal
Java Developer,
SCJP 1.1, SCJP 2, SCJD 2
Timing results
---------------- Java ------------------------
Total Time taken for 10 calls: 4667
Result: 466 Time: 466
---------------- PLSQL ------------------------
Total Time taken for 10 calls: 150
Result: 466 Time: 15
Java Code
public static int getCursorCount()
int count = 0;
//define iterator for select
count_iter myIter = null;
try
#sql myIter = { SELECT lastname FROM employee };
while(myIter.next())
count++;
myIter.close();
catch(SQLException excp)
return count;
PL/SQL Code
function get_count_cursor_sf
return
number
is
cursor count_cursor is
select lastname from employee;
v_return_count number := 0;
v_name employee.lastname%type;
begin
open count_cursor;
fetch count_cursor into v_name;
while (count_cursor%found) loop
fetch count_cursor into v_name;
v_return_count := v_return_count + 1;
end loop;
--Return the variable
return v_return_count;
end ;
Calling Code
public class DBCall
public static void main(String args[])
try
makeJavaCalls();
makePLSQLCalls();
catch(Exception excp)
excp.printStackTrace();
public static Connection getConnection() throws Exception
Class.forName("oracle.jdbc.driver.OracleDriver");
return DriverManager.getConnection("jdbc:oracle:thin:@10.0.0.3:1521:oracleee","rda","rdauser");
public static void makePLSQLCalls() throws Exception
int count = 10;
long time = 0;
int result = 0;
while(count > 0)
Connection conn = getConnection();
CallableStatement cs = conn.prepareCall("{? = call rda_plsql_pkg.get_count_cursor_sf()}");
cs.registerOutParameter(1, Types.INTEGER);
long before = System.currentTimeMillis();
cs.execute();
result = cs.getInt(1);
long after = System.currentTimeMillis();
time = time + (after - before);
cs.close();
conn.close();
count--;
System.out.println("---------------- PLSQL ------------------------");
System.out.println("Total Time taken for 10 calls: " + time);
System.out.println("Result: " + result + " Time: " + (time/10));
public static void makeJavaCalls() throws Exception
int count = 10;
long time = 0;
int result = 0;
while(count > 0)
Connection conn = getConnection();
CallableStatement cs = conn.prepareCall("{? = call dorknight.getcursorcount()}");
cs.registerOutParameter(1, Types.INTEGER);
long before = System.currentTimeMillis();
cs.execute();
result = cs.getInt(1);
long after = System.currentTimeMillis();
time = time + (after - before);
cs.close();
conn.close();
count--;
System.out.println("---------------- Java ------------------------");
System.out.println("Total Time taken for 10 calls: " + time);
System.out.println("Result: " + result + " Time: " + (time/10));
null

A big contributor to the behavior seen here is that there is a one-time overhead per session (= per database connection) to start the JavaVM and also (in 8.1.6 and earlier) to initialize the SQLJ runtime (via reflection).
Keeping the same connection for subsequent calls to Java (which is the more typical scenario, anyway) will result in a rather considerable speedup.

Similar Messages

  • How to send a Varying Array param to a PL/SQL Stored Procedure from Java

    * I am VERY new to jdbc, and even somewhat new to Java
    * I'm using Java 1.5, Oracle 10g.
    * I need to call the following PL/SQL Stored Procedure from Java:
    procedure setEventStatus
    i_deQueueStatus in deQueueStatus_type
    *deQueueStatus_type is the following (an array of deQueueStatus_OBJ):
    CREATE OR REPLACE TYPE deQueueStatus_OBJ as object
    eventID number (20),
    dequeuestatus varchar2(20)
    CREATE OR REPLACE TYPE deQueueStatus_TYPE IS VARYING ARRAY(500) of deQueueStatus_obj
    *I have created a Java object as follows:
    public class EventQueueDeQueueStatus
         long      eventID;
         String      dequeueStatus;
         EventQueueDeQueueStatus(long eventID, String dequeueStatus)
              this.eventID = eventID;
              this.dequeueStatus = dequeueStatus;
    I have an ArrayList of these.
    I need to pass this list to the Stored Procedure. How do I create a java.sql.Array so I can call CallableStatement.setArray to set the parameter? Or do I use something else? I have tried setObject with both the ArrayList and also with a primitive array, but got "Invalid Column Type" both times.
    Any help would be greatly appreciated. I just got this task today, and I have to make it work by Tuesday :-( !
    Thanks,
    Kathy

    Kathy,
    Search the archives of this forum and the JDBC forum for the terms STRUCT and ARRAY and you can find some sample code on the JDBC How-To Documents page and the JDBC Samples which can both be accessed from this page:
    http://www.oracle.com/technology/tech/java/sqlj_jdbc/index.html
    Good Luck,
    Avi.

  • PL/SQL Stored procedures vs C# code.

    Hi All
    We are going to start designing a kind of transactional application with huge volume of data (150 million records per month). Our selected DB engine is Oracle 10.g while C# is selected development language.
    Because of big volume of data performance is one of the most important factors for us, and the technical design should gain the best level of performance.
    What i'm looking for and studing for it is to define which kind of operation shall be done by Stored Procedure which will be written by PL/SQL or by C# classes?
    I don't interested in to handle complicated and complex jobs using PL/SQL stored procedures while the performance really deserve it.

    Hello,
    Well, my philosophy is to leverage the database as much as possible. I have worked with applications that had no "select", "insert", "update" or "delete" statements in them. Instead, stored procedures and functions inside of PL/SQL packages and bodies were used. Some people will argue strongly against that, but I belong to the "thick database" group rather than the "the database is just a persistence layer that I have to deal with" group. To me it makes sense to co-locate the code that works on the data with the data. If you are working with large volumes of data, I find the bulk operations available via PL/SQL to be very handy.
    Here's an AskTom thread that deals with this general issue:
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:12083187196917
    Whilst the thread is primarily about Java, you can substitute just about any other language and the meaning will still carry over.
    Regards,
    Mark

  • Executing a shell script from pl/sql stored procedure

    Hi,
    I have Oracle 8i on HP-UX.
    I am passing a shell script name as a parameter to a user defined function from a pl/sql stored procedure. This user defined function has insterface to a user defined Java class file in Aurora java virtual machine which is written using runtime class which can execute any OS command or any shell script. I am getting any OS command run successfully, but could not run my own shell script. It's is not getting environment variables of my own, so not getting executed. So please suggest how can get these env variables in my shell script and also suggest other sucurity concerns to be taken into consideration.
    If you have any questions please let me know.
    This is really a very urgent issue.....
    Please help me.
    Thanks
    Srinivasa Rao Kolla

    Your best bet is to use the dbms_pipe builtin package to send the command to the host

  • Why doesn't SSRS like an IF Statement in my SQL Stored Procedure???

    I have multiple IF Statements at the end of my SQL Stored Procedure Process that utilizes a @ReportTypeName Parameter to produce the chosen report result set
    IF @ReportTypeName = 'HMO-POS New To HFHP - No Prior Year Member Spans'
    BEGIN
    SELECT DISTINCT
    [#TempTable_Distinct_Individual_Member_All_Info].[INDV Member Contract Nbr],
    [#TempTable_Distinct_Individual_Member_All_Info].[INDV Member Subscriber Member Nbr],
    [#TempTable_Distinct_Individual_Member_All_Info].[INDV Benefit Pkg],
    [#TempTable_Distinct_Individual_Member_All_Info].[INDV Benefit Plan Name],
    [#TempTable_Distinct_Individual_Member_All_Info].[INDV Division Nbr],
    [#TempTable_Distinct_Individual_Member_All_Info].[INDV MEMBER EFF DATE],
    [#TempTable_Distinct_Individual_Member_All_Info].[INDV MEMBER NBR],
    [#TempTable_Distinct_Individual_Member_All_Info].[INDV MEMBER FIRST NAME],
    [#TempTable_Distinct_Individual_Member_All_Info].[INDV MEMBER LAST NAME],
    [#TempTable_Distinct_Individual_Member_All_Info].[INDV Broker Name],
    [#TempTable_Distinct_Individual_Member_All_Info].[INDV MEMBER ADDRESS 1],
    [#TempTable_Distinct_Individual_Member_All_Info].[INDV MEMBER CITY],
    [#TempTable_Distinct_Individual_Member_All_Info].[INDV MEMBER STATE],
    [#TempTable_Distinct_Individual_Member_All_Info].[INDV MEMBER ZIPCODE],
    [#TempTable_Distinct_Individual_Member_All_Info].[INDV MEMBER PHONE1],
    [#TempTable_Distinct_Individual_Member_All_Info].[INDV MEMBER PHONE2],
    [#TempTable_Distinct_Individual_Member_All_Info].[INDV MEMBER PHONE3],
    [#TempTable_Distinct_Individual_Member_All_Info].[INDV MEMBER EMAIL],
    CONVERT(VARCHAR,CAST(CONVERT(VARCHAR, [#TempTable_Distinct_Individual_Member_All_Info].[INDV MEMBER YMDBIRTH]) AS DATETIME),101) AS [INDV MEMBER BirthDate],
    FLOOR((CAST (GETDATE() AS INTEGER) - CAST(CONVERT(DATETIME, CONVERT(CHAR(8), [#TempTable_Distinct_Individual_Member_All_Info].[INDV MEMBER YMDBIRTH])) AS INTEGER)) / 365.25) AS [INDV MEMBER AGE]
    FROM [#TempTable_Distinct_Individual_Member_All_Info]
    WHERE (CHARINDEX('HMO',LTRIM(RTRIM([#TempTable_Distinct_Individual_Member_All_Info].[INDV Benefit Plan Name])),1) > 0
    OR CHARINDEX('POS',LTRIM(RTRIM([#TempTable_Distinct_Individual_Member_All_Info].[INDV Benefit Plan Name])),1) > 0)
    AND [#TempTable_Distinct_Individual_Member_All_Info].[INDV MEMBER NBR] NOT IN
    (SELECT [#TempTable_Distinct_Individual_Member_Prior_Year_Spans].[INDV MEMBER NBR]
    FROM [#TempTable_Distinct_Individual_Member_Prior_Year_Spans])
    ORDER BY [#TempTable_Distinct_Individual_Member_All_Info].[INDV MEMBER NBR]
    END
    IF @ReportTypeName = 'HMO-POS Renewals'
    BEGIN
    SELECT DISTINCT
    [#TempTable_Distinct_Individual_Member_All_Info].[INDV Member Contract Nbr],
    [#TempTable_Distinct_Individual_Member_All_Info].[INDV Member Subscriber Member Nbr],
    [#TempTable_Distinct_Individual_Member_All_Info].[INDV Benefit Pkg],
    [#TempTable_Distinct_Individual_Member_All_Info].[INDV Benefit Plan Name],
    [#TempTable_Distinct_Individual_Member_All_Info].[INDV Division Nbr],
    [#TempTable_Distinct_Individual_Member_All_Info].[INDV MEMBER EFF DATE],
    [#TempTable_Distinct_Individual_Member_All_Info].[INDV MEMBER NBR],
    [#TempTable_Distinct_Individual_Member_All_Info].[INDV MEMBER FIRST NAME],
    [#TempTable_Distinct_Individual_Member_All_Info].[INDV MEMBER LAST NAME],
    [#TempTable_Distinct_Individual_Member_All_Info].[INDV Broker Name],
    [#TempTable_Distinct_Individual_Member_All_Info].[INDV MEMBER ADDRESS 1],
    [#TempTable_Distinct_Individual_Member_All_Info].[INDV MEMBER CITY],
    [#TempTable_Distinct_Individual_Member_All_Info].[INDV MEMBER STATE],
    [#TempTable_Distinct_Individual_Member_All_Info].[INDV MEMBER ZIPCODE],
    [#TempTable_Distinct_Individual_Member_All_Info].[INDV MEMBER PHONE1],
    [#TempTable_Distinct_Individual_Member_All_Info].[INDV MEMBER PHONE2],
    [#TempTable_Distinct_Individual_Member_All_Info].[INDV MEMBER PHONE3],
    [#TempTable_Distinct_Individual_Member_All_Info].[INDV MEMBER EMAIL],
    CONVERT(VARCHAR,CAST(CONVERT(VARCHAR, [#TempTable_Distinct_Individual_Member_All_Info].[INDV MEMBER YMDBIRTH]) AS DATETIME),101) AS [INDV MEMBER BirthDate],
    FLOOR((CAST (GETDATE() AS INTEGER) - CAST(CONVERT(DATETIME, CONVERT(CHAR(8), [#TempTable_Distinct_Individual_Member_All_Info].[INDV MEMBER YMDBIRTH])) AS INTEGER)) / 365.25) AS [INDV MEMBER AGE]
    FROM [#TempTable_Distinct_Individual_Member_All_Info]
    INNER JOIN [#TempTable_Distinct_Individual_Member_Prior_Year_Spans]
    ON [#TempTable_Distinct_Individual_Member_Prior_Year_Spans].[INDV MEMBER NBR] = [#TempTable_Distinct_Individual_Member_All_Info].[INDV MEMBER NBR]
    WHERE (CHARINDEX('HMO',LTRIM(RTRIM([#TempTable_Distinct_Individual_Member_All_Info].[INDV Benefit Plan Name])),1) > 0
    OR CHARINDEX('POS',LTRIM(RTRIM([#TempTable_Distinct_Individual_Member_All_Info].[INDV Benefit Plan Name])),1) > 0)
    ORDER BY [#TempTable_Distinct_Individual_Member_All_Info].[INDV MEMBER NBR]
    END
    Microsoft Visual Studio and SQL Server Reporting Services did not like this! When I added my dataset and parameters accordingly, my Dataset had no fields...almost as if running the Stored Procedure in the background to get its Metadata was not working. I
    know this works because I tested it as a result of a straight EXEC Command. Why doesn't Microsoft Visual Studio and SQL Server Reporting Services not like this IF? I did end up getting around this by parameterizing the WHERE clause based on the @ReportTypeName
    chosen.
    WHERE (@ReportTypeName = 'HMO-POS New To HFHP - No Prior Year Member Spans'
    AND (CHARINDEX('HMO',LTRIM(RTRIM([#TempTable_Distinct_Individual_Member_All_Info].[INDV Benefit Plan Name])),1) > 0
    OR CHARINDEX('POS',LTRIM(RTRIM([#TempTable_Distinct_Individual_Member_All_Info].[INDV Benefit Plan Name])),1) > 0)
    AND [#TempTable_Distinct_Individual_Member_All_Info].[INDV MEMBER NBR] NOT IN
    (SELECT [#TempTable_Distinct_Individual_Member_Prior_Year_Spans].[INDV MEMBER NBR]
    FROM [#TempTable_Distinct_Individual_Member_Prior_Year_Spans]))
    OR (@ReportTypeName = 'HMO-POS Renewals'
    AND (CHARINDEX('HMO',LTRIM(RTRIM([#TempTable_Distinct_Individual_Member_All_Info].[INDV Benefit Plan Name])),1) > 0
    OR CHARINDEX('POS',LTRIM(RTRIM([#TempTable_Distinct_Individual_Member_All_Info].[INDV Benefit Plan Name])),1) > 0)
    AND [#TempTable_Distinct_Individual_Member_All_Info].[INDV MEMBER NBR] IN
    (SELECT [#TempTable_Distinct_Individual_Member_Prior_Year_Spans].[INDV MEMBER NBR]
    FROM [#TempTable_Distinct_Individual_Member_Prior_Year_Spans]))
    I appreciate your review and am hopeful for a reply.
    Thanks!

    Hi ITBobbyP,
    I have tested on my local environment and can reproduce the issue, the issue can be caused by the temp table you are using which will also cause the data not display.
    I have use below sample table and record to have a test and details information below for your reference:
    Right click the DataSet to select the "DataSet Properties" and click the query designer to execute the stored procedure by click the "!" to check if you can get the data:
    If you got some error, the issue can be cause by the temp table invalid, so please make sure you have add the query to create and insert  recored to temp table like below:
    CREATE PROCEDURE vickytest0311_1
    @ReportTypeName nvarchar(50)
    AS
    create table #VickyTest
    column1 int,
    column2 varchar(20)
    insert into #VickyTest values (1,'Test1')
    insert into #VickyTest values (2,'Test2')
    insert into #VickyTest values (3,'Test3')
    IF @ReportTypeName ='Test1'
    BEGIN
    select * from #VickyTest
    where Column1=1
    END
    IF @ReportTypeName ='Test2'
    BEGIN
    select * from #VickyTest
    where Column1=2
    END
    GO
    3. I recommend you to not use the temp table and you will not need to add the create and insert statement in the stored procedure.
    4. If you still got no data, please try to click the "Refresh fields" as below:
    If you still have any problem, please feel free to ask.
    Regards,
    Vicky Liu
    Vicky Liu
    TechNet Community Support

  • How to call PL-SQL/stored procedure in Creator

    Anybody can tell how to call PL-SQL/Stored procedures inside creator...

    Hi!!!
    You can see this topic http://forum.sun.com/jive/thread.jspa?threadID=106046
    There is how to call oracle stored procedures. Also I put a lot of links in these topic doing reference stored procedures. I have one that it tells specially how to call oracle stored procedures from java, is in spanish but you can understand the code.;-)
    http://yoprogramador.vampisol.com/index.php?title=pl_sql_oracle_desde_java&more=1&c=1&tb=1&pb=1
    Byeee

  • PL/SQL stored procedure?

    Hi,
    Is any body could help me to execute
    an PL/SQL stored procedure via JDev3.1
    (using Oracle conection, No JDBC).
    Please provide sample code if possible?
    Thanks in Advance.
    Reza

    Hi
    you could use JPublisher Wizard in JDeveloper to generate Java Wrapper classes for pl/sql stored procedures.
    check out the online demos http://technet.oracle.com/products/jdev/info/jdev/jpublisher/s000.html
    Also there is information in the online doc.
    Check the release notes for supported database versions.
    raghu

  • Error calling PL/SQL stored procedure

    Hi,
    I'm pretty new to JDeveloper having used NetBeans for the last few years.
    I'm getting an error when trying to call a PL/SQL stored procedure. When I click on any of the oracle errors I get an "unable to find source file" message. The errors occurs in call.execute(). The error message and Java code are listed below. Any help is much appreciated.
    Cheers,
    Stevie
    Errors:
    Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 33
         at java.lang.String.charAt(String.java:558)
         at oracle.jdbc.driver.OracleSql.handleODBC(OracleSql.java:877)
         at oracle.jdbc.driver.OracleSql.parse(OracleSql.java:811)
         at oracle.jdbc.driver.OracleSql.getSql(OracleSql.java:284)
         at oracle.jdbc.driver.OracleSql.getSqlBytes(OracleSql.java:538)
         at oracle.jdbc.driver.T4CCallableStatement.doOall8(T4CCallableStatement.java:169)
         at oracle.jdbc.driver.T4CCallableStatement.execute_for_rows(T4CCallableStatement.java:873)
         at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1161)
         at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3001)
         at oracle.jdbc.driver.OraclePreparedStatement.execute(OraclePreparedStatement.java:3093)
         at oracle.jdbc.driver.OracleCallableStatement.execute(OracleCallableStatement.java:4286)
         at oracle.CallPLSQL.callLMO(CallPLSQL.java:118)
         at oracle.TestHarness.main(TestHarness.java:18)
    Jave Code:
    package oracle;
    import java.sql.CallableStatement;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.SQLException;
    import java.sql.Types;
    public class CallPLSQL {
    private Connection conn;
    public CallPLSQL() {
    *Constructor.
    try {
    //Register Oracle Database Drive
    DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
    //set connection
    String connectionString="jdbc:oracle:thin:TSD/TSD@DEV:1526:DEVELOP";
    this.setConn(DriverManager.getConnection(connectionString,"TSD", "TSD"));
    } catch (SQLException ex) {
    public int callproc () throws SQLException {
    CallableStatement call;
    String callString = "{call proc" +
    call = conn.prepareCall(callString);
    call.setInt(1, 120289);
    call.setInt(2, 2008);
    call.registerOutParameter(3, Types.INTEGER);
    call.registerOutParameter(4, Types.INTEGER);
    call.registerOutParameter(5, Types.INTEGER);
    call.registerOutParameter(6, Types.DATE);
    call.registerOutParameter(7, Types.VARCHAR);
    call.registerOutParameter(8, Types.INTEGER);
    call.registerOutParameter(9, Types.INTEGER);
    call.execute();
    int i = call.getInt("app_id");
    return i;
    public void setConn(Connection conn) {
    this.conn = conn;
    public Connection getConn() {
    return conn;
    }

    I've fixed it now. I'd missed a } in prepareCall. What a doughball.

  • MS SQL Stored Procedure problem

    Hi,
    I am using BO XI R2, Crystal Report XI and MS SQL Database.
    I found a strange error when generating the report using my java application if the crystal report is using MS SQL stored procedure. The error encountered :
    com.crystaldecisions.sdk.occa.managedreports.ras.internal.a: Cannot open report document. --- Custom table prefix specified in the InfoStore does not exist.  This is a configuration problem. Please contact your system administrator.
    cause:com.crystaldecisions.sdk.occa.report.lib.ReportSDKServerException: Custom table prefix specified in the InfoStore does not exist.  This is a configuration problem. Please contact your system administrator.---- Error code:-2147467259 Error code name:failed
    detail:Cannot open report document. --- Custom table prefix specified in the InfoStore does not exist.  This is a configuration problem. Please contact your system administrator.
    This is when the code executed is:
       reportClientDocument = reportAppFactory.openDocument(report, 0, Locale.ENGLISH);
    If the report does not use the stored procedure, it's ok.
    If i run the report  (with stored procedure) from CMC using the default table prefix (in database config tab), it's able to generate the report.
    If i select custom table prefix and specify the custom table prefix value with the same value as in the default table prefix, it could not generate the report and error stated that the table could not be found.
    Please enlighten me if you have use MS SQL database for reporting with BO XI R2.
    Thanks.

    That means it's not a SDK-specific error. 
    Once it's resolved in InfoView, it'll likely be resolved with your app.
    You might want to open a support case with SAP. 
    Sincerely,
    Ted Ueda

  • Very Odd PL/SQL Stored Procedure Behavior

    I'm writing a jsp/struts front-end for a legacy app that makes extensive use of stored procedures. I've sucessfully created a login page, a search page, and a master record detail/edit page. On the master record detail there are a series of subordinate data grids, each with links to individual pages for record editing.
    If I edit the master record and click my save button (a commit action), the appropriate stored proc is called and everything works as it should.
    BUT, if I click on the edit link to a subordinate table, I am taken to the screen, I can make changes, and when I click save (another commmit event) the stored procedure for that table is not called. No errors, the struts action takes me back to the previous screen (correctly), but nothing is saved.
    The weird part is, once I've returned to the master record page, if I edit the master record and click the same save button as before, the stored procedure for the subordinate table that I had just looked at is fired.
    I know my struts actions are correct, since the pages navigate correctly (at least, I 'think' I know that). I used the same code in the EO Impl to set up my call to the stored procs.
    Does anybody have ANY idea what might be causing this? I'm lost and confused at this point.
    (EO Impl Code below)
    /*doesn't print dodml until I click save on the master record...this is the code for the child. */
    protected void doDML(int operation, TransactionEvent e)
    System.out.println("dodml");
    switch (operation) {
    case DML_INSERT: {
    callInsertExternalNumber("I");
    break;
    case DML_UPDATE: {
    callInsertExternalNumber("U");
    break;
    void callInsertExternalNumber(String function) {
    CallableStatement st = null;
    try {
    System.out.println("calling stored proc");
    String stmt = "BEGIN mySchema.InsertNumber(?,?,?,?,?,?,?); END;";
    DBTransaction tr = getDBTransaction();
    st = tr.createCallableStatement(stmt,1);
    if (getExternalKey() != null) {
    st.setLong(1,getExternalKey().longValue());
    ...etc. etc. The calling stored proc doesn't get printed until I click save on the master record.

    Hi
    you could use JPublisher Wizard in JDeveloper to generate Java Wrapper classes for pl/sql stored procedures.
    check out the online demos http://technet.oracle.com/products/jdev/info/jdev/jpublisher/s000.html
    Also there is information in the online doc.
    Check the release notes for supported database versions.
    raghu

  • Get server output from pl/sql stored procedure

    Hi Colleagues,
    I would like to get and watch the server output of my PL/SQL stored procedure
    when I run my java program and call it from. The Stored proc. uses "dbms_output.put_line".
    If it is clearly and possible (or not), will you send me your answer!
    Thanks a lot
    Ulve

    Hi,
    You can redirect the standard output to the console (i.e., the SQL output) using the
    DBMS_JAVA.SET_OUTPUT() method.
    SQL> SET SERVEROUTPUT ON
    SQL> call dbms_java.set_output (5000);But, the output is only printed when the stored procedure exits, and this setting works only for one call (i.e., the SQL call that immediately follows the invocation of DBMS_JAVA.SET_OUTPUT()). The minumum and default value is 2,000 characters and the maximum is 1,000,000 (1 million) characters. Notice the “SET SERVEROUTPUT ON” which enables displaying the outputs of stored procedures (Java or PL/SQL blocks) in SQL*Plus.
    Kuassi http://db360.blogspot.com

  • Big PL/SQL stored procedure optimization.

    Hi There,
    Can any one let me the basic steps for optimization or tuning of a PL/SQL stored procedure for better performance.
    DB: 11.2.0
    OS: Solaris 10
    looking forward.
    Regards,

    >
    Can any one let me the basic steps for optimization or tuning of a PL/SQL stored procedure for better performance.
    >
    Seriously - how do you expect anyone to give you any specific things to do when you don't provide any specific information about your procedure?
    A procedured is comprised of one or more steps. So to tune it you need to determine which steps are 'slow' and make them 'fast'! ;)
    There are several common causes of performance problems with PL/SQL are:
    1. Using PL/SQL when SQL should have been used. Don't use PL/SQL to begin with - always use SQL unless it just can't do the job required. The 'PL' in PL/SQL means 'Procedural Language' and should be used for transactional (multi-step) processing or when 'procedural' operations are needed that aren't available in SQL.
    2. Using slow-by-slow (row by row) processing instead of BULK processing.
    3. Using multiple nested LOOPs when a more complex query could have allowed a single loop to be used.
    4. Using COMMITs more frequently than required. Search this forum and you will find far too many questions about how to do a COMMIT after 10,000 rows (or some other number). A COMMIT should be performed AFTER a transaction has been completed, not during the middle of it. Frequent commits generally use more resources, degrade performance and risk the famous 'snapshot too old' message.
    The very first step of performance 'tuning' is to first verify that any 'tuning' is even required. Too many people suffer from CTD - compulsive tuning disorder.
    The second step is to identify what step, or steps, of the process are performing below par.
    Which means the best developers are proactive - they plan ahead.
    1. Create an explain plan BEFORE the code goes to production. Once the code has been tested and believed to perform properly an execution plan should be created and SAVED for future reference. That saved plan can then be used later, when you suspect a performance issue, to detect changes that might have affected performance: create a new plan and compare it to the baseline.
    2. Create explains for ALL key queries. As suggested by step #1 performance is all about comparison: performance 'now' COMPARED TO performance 'then'. If the don't know the performance 'then' it can be difficult to know if the performance has changed. If a query has a 'now' execution time of 2 minutes is that 'fast' or 'slow'? Well - compared to WHAT? You can't know 'fast' or 'slow' if you don't know 'then' and 'now'. How fast was it yesterday, last week or last month?
    3. Instrument your procedural code. That means measure, for EACH STEP, how long it took to execute and how much data it worked with. That information needs to be logged. Your logging and data collection can be static (it ALWAYS happens) or dynamic. Oracle's own code is HEAVILY instrumented. Some operations and activity are always logged and available in the data dicitionary views or various performance reports such as AWR.
    Other operations, such as the extended trace facility, only collect data on request.
    IMHO your first step should be to begin the 'proactive' steps above.

  • Pl/sql stored procedure as data source

    Hi I am a newbie
    I have a pl/sql stored procedure inside a package which uses a SYS_REFCURSOR as it returns a result set.
    Can I use this procedure as a Data Source using the wizard?
    When I use the Data source configuration wizard I get a list with only the tables and views.I don't see any stored procedures
    Thanks

    Here is a sample procedure..
    CREATE OR REPLACE PROCEDURE TEST_USER.TEST_PROCEDURE1 ( p_cursor OUT SYS_REFCURSOR)
    AS
    BEGIN
    OPEN p_cursor FOR
    SELECT C1,C2
    FROM TEST_USER.test_table4procedure;
    END;
    When I execute the procedure, I see the results. The goal is to put the results of the procedure into a different table.
    Unfortunately I have close to 0 zero knowledge in both java and jython.
    Please help.
    NOTE: For the life of me, I have no clue why the "other" system wants it to be a stored procedure, when we can use a view/table and make everybody's life easier (aka K.I.S.S.)
    Regards,
    Dave Null

  • Unable to use the values returned by a PL/SQL stored procedure in a XSQL page

    Hi,
    I've been messing around with XML and XSQL in particular. I was trying to write a xsql page to display a report with account totals...I have the following .xsql which calls a PL/SQL stored procedure :
    <?xml version="1.0"?>
    <xsql:query connection="pfcdm" xmlns:xsql="urn:oracle-xsql">
    <xsql:set-session-param name="zasset_total" value="100">
    <xsql:dml connection="pfcdm">
    rraman.sp_vw_id(zasset_total,zinvm_total,zmkt_val);
    </xsql:dml>
    </xsql:set-session-param>
    select 'Asset total is {@zasset_total}' as "ASSET_TOTAL" from dual
    </xsql:query>
    My procedure sp_vw_id returns the values that it should. But, I am not sure how to declare variables within a page, and to output the return values. There is very scanty documentation on the usage of <xsql:dml> or <xsql:ref-cursor-function>.
    Any response would be greatly appreciated.
    Thanks,
    Raja

    Here is the example from the Oracle9i (complete rewrite) of the XSQL Chapter in our Oracle documentation.
    Question
    I using <xsql:dml> to call a stored procedure which has one OUT parameter, but I was not able to see any results. The executed code results in the following statement:
    <xsql-status action="xsql:dml" rows="0"/>
    Answer
    You cannot set parameter values by binding them in the position of OUT variables in this release using <xsql:dml>. Only IN parameters are supported for binding. You can create a wrapper procedure that constructs XML elements using the HTP package and then your XSQL page can invoke the wrapper procedure using <xsql:include-owa> instead.
    For an example, suppose you had the following procedure:
    CREATE OR REPLACE PROCEDURE addmult(arg1 NUMBER,
    arg2 NUMBER,
    sumval OUT NUMBER,
    prodval OUT NUMBER) IS
    BEGIN
    sumval := arg1 + arg2;
    prodval := arg1 * arg2;
    END;You could write the following procedure to "wrap" it, taking all of the IN arguments that the procedure above expects, and then "encoding" the OUT values as a little XML datagram that you print to the OWA page buffer:
    CREATE OR REPLACE PROCEDURE addmultwrapper(arg1 NUMBER, arg2 NUMBER) IS
    sumval NUMBER;
    prodval NUMBER;
    xml VARCHAR2(2000);
    BEGIN
    -- Call the procedure with OUT values
    addmult(arg1,arg2,sumval,prodval);
    -- Then produce XML that encodes the OUT values
    xml := '<addmult>'&#0124; &#0124;
    '<sum>'&#0124; &#0124;sumval&#0124; &#0124;'</sum>'&#0124; &#0124;
    '<product>'&#0124; &#0124;prodval&#0124; &#0124;'</product>'&#0124; &#0124;
    '</addmult>';
    -- Print the XML result to the OWA page buffer for return
    HTP.P(xml);
    END;This way, you can build an XSQL page like this that calls the wrapper procedure:
    <page connection="demo" xmlns:xsql="urn:oracle-xsql">
    <xsql:include-owa bind-params="arg1 arg2">
    BEGIN addmultwrapper(?,?); END;
    </xsql:include-owa>
    </page>This allows a request like:
    http://yourserver.com/addmult.xsql?arg1=30&arg2=45
    to return an XML datagram that reflects the OUT values like this:
    <page> <addmult><sum>75</sum><product>1350</product></addmult>
    </page>

  • Added new parm to an existing SQL stored procedure CR 11 doesn't like it

    Hi
    I have added a new parameter to an existing SQL stored procedure (SQL 2000).  This stored procedure is currently being called from a Crystal XI report.  It prompts for a date which works great.  (The report was created with this parameter).  I added a new parameter to the stored procedure.  When I do a preview in Crystal, it prompts for the new parameter, but is NULL when I look at the SQL query and it brings back no data.  If I try to verify the database, it tells me that I am missing parameter @ProcessType (varchar(5))--(name of new parameter).  I have physically added this parameter to the crystal report with the select expert and still no luck.  I have already tried renaming the procedure but am unable to update datasource location because of this parameter.  The report is very detailed and I do NOT want to create a new report.

    Unfortunately, I have tried and retried to do this.  Nothing changes.  I usually would get a message like database has changed, proceeding to fix report.  I don't get this.  It merely tells me database is up to date and only returns the 1 parameter, yet when I go to the datasouce and try to update it, it tells me that I have not supplied the new parameter.
    I have tried everything, from closing Crystal reports and then going so far as to reboot my machine, just in case their was some kind of caching going on.
    I have even asked other people I work with to look at it to make sure I am not doing something dumb...

Maybe you are looking for

  • How do I change the Apple ID that iCloud uses to sync the iPad?

    How do I change an iPad's iCloud Apple ID without deleting that entire iCloud account? When I go to Settings>iCloud on this iPad, the Apple ID email address is not an active field, so I cannot enter the new Apple ID. The iPad is currently syncing suc

  • HP Photosmart Premium All-in-One Printer - C309g photo printing - paper feeding

    Windows 7, wireless printing Printing on 6x4 photos, either borderless or with a white frame. The paper is fed from the photo paper tray on an angle it would seem since all the photos come out printed on an angle on the paper.

  • Setting different editors in different cells in a single column

    Hi, My approach to setting different editors like JTextField,JComboBox etc to different cells in a single column is not upto fully satisfactory. As compiling the same code lower than 1.5 gives error in that line. My approach is as follows: ..........

  • Problem downloading all of my purchases

    Hi everyone, I have noticed after reformatting my computer and reinstalling iTunes when i try to re download all of my past purchases at once. I tunes will only allow me to download about 255 songs. I have significantly more then this. So my only oth

  • Error (Overflow in  RFC - XI)

    Hi. I'm working with a XI -> RFC -> XI scenario. When i send the info from XI to RFC, works fine. When i return the info from async RFC to XI, in SM58 i get this message : java.nio.BufferOverflowException How can i solve this problem? Thanks.