Peformance of Functin in a procedure
i have a proceudure which inserts data into a table using cursor
the select query of the cursor is having a function also
When i execute this procedure it is taking one hour to load 50000 rows
but the same select query of the procedure is giving me data in 40 secs
When i include the function inside my select query of the cursor it takes 5 mins to load 50000 rows
when i execute teh select query it is taking 1.5 mins
Please let me know whether the use of functin will affect the query to this extent(1 hour to 5 mins)
Iam not using any business logic
just inserting to the table
select empno,fget(empno) from emp--Execute in 20 secs
in Toad but in procedure it take 30 mins to insert
select empno,ename from emp--Execute in 1 min in Toad
but in procedure it take 3 mins to insertOk, ignore the Toad aspect of things, because Toad doesn't execute things in exactly the same way as plain old running SQL or PL/SQL through sql*plus.
In simple terms, what oracle has is two engines, one for SQL and the other for PL/SQL. If you write pure SQL using only "built in" functionality then your SQL is likely to perform well in comparison to using "user-defined" functions within it. If you call your own functions in an SQL query, then that function is called for each row of your data. Every time your function (PL/SQL remember) is called from SQL Oracle has to do what is called context switching. Context switching between the two engines is a major cause of performance problems.
Lesson: Don't use PL/SQL where the same can be achieved solely through SQL.
Similar Messages
-
Request some help, over procedure's performance uses regular expressions for its functinality
Hi All,
Below is the procedure, having functionalities of populating two tables. For first table, its a simple insertion process but for second table, we need to break the soruce record as per business requirement and then insert into the table. [Have used regular expressions for that]
Procedure works fine but it takes around 23 mins for processing 1mm of rows.
Since this procedure would be used, parallely by different ETL processes, so append hint is not recommended.
Is there any ways to improve its performance, or any suggestion if my approach is not optimized? Thanks for all help in advance.
CREATE OR REPLACE PROCEDURE SONARDBO.PRC_PROCESS_EXCEPTIONS_LOGS_TT
P_PROCESS_ID IN NUMBER,
P_FEED_ID IN NUMBER,
P_TABLE_NAME IN VARCHAR2,
P_FEED_RECORD IN VARCHAR2,
P_EXCEPTION_RECORD IN VARCHAR2
IS
PRAGMA AUTONOMOUS_TRANSACTION;
V_EXCEPTION_LOG_ID EXCEPTION_LOG.EXCEPTION_LOG_ID%TYPE;
BEGIN
V_EXCEPTION_LOG_ID :=EXCEPTION_LOG_SEQ.NEXTVAL;
INSERT INTO SONARDBO.EXCEPTION_LOG
EXCEPTION_LOG_ID, PROCESS_DATE, PROCESS_ID,EXCEPTION_CODE,FEED_ID,SP_NAME
,ATTRIBUTE_NAME,TABLE_NAME,EXCEPTION_RECORD
,DATA_STRUCTURE
,CREATED_BY,CREATED_TS
VALUES
( V_EXCEPTION_LOG_ID
,TRUNC(SYSDATE)
,P_PROCESS_ID
,'N/A'
,P_FEED_ID
,NULL
,NULL
,P_TABLE_NAME
,P_FEED_RECORD
,NULL
,USER
,SYSDATE
INSERT INTO EXCEPTION_ATTR_LOG
EXCEPTION_ATTR_ID,EXCEPTION_LOG_ID,EXCEPTION_CODE,ATTRIBUTE_NAME,SP_NAME,TABLE_NAME,CREATED_BY,CREATED_TS,ATTRIBUTE_VALUE
SELECT
EXCEPTION_ATTR_LOG_SEQ.NEXTVAL EXCEPTION_ATTR_ID
,V_EXCEPTION_LOG_ID EXCEPTION_LOG_ID
,REGEXP_SUBSTR(str,'[^|]*',1,1) EXCEPTION_CODE
,REGEXP_SUBSTR(str,'[^|]+',1,2) ATTRIBUTE_NAME
,'N/A' SP_NAME
,p_table_name
,USER
,SYSDATE
,REGEXP_SUBSTR(str,'[^|]+',1,3) ATTRIBUTE_VALUE
FROM
SELECT
REGEXP_SUBSTR(P_EXCEPTION_RECORD, '([^^])+', 1,t2.COLUMN_VALUE) str
FROM
DUAL t1 CROSS JOIN
TABLE
CAST
MULTISET
SELECT LEVEL
FROM DUAL
CONNECT BY LEVEL <= REGEXP_COUNT(P_EXCEPTION_RECORD, '([^^])+')
AS SYS.odciNumberList
) t2
WHERE REGEXP_SUBSTR(str,'[^|]*',1,1) IS NOT NULL
COMMIT;
EXCEPTION
WHEN OTHERS THEN
ROLLBACK;
RAISE;
END;
Many Thanks,
ArpitRegex's are known to be CPU intensive specially when dealing with large number of rows.
If you have to reduce the processing time, you need to tune the Select statements.
One suggested change could be to change the following query
SELECT
REGEXP_SUBSTR(P_EXCEPTION_RECORD, '([^^])+', 1,t2.COLUMN_VALUE) str
FROM
DUAL t1 CROSS JOIN
TABLE
CAST
MULTISET
SELECT LEVEL
FROM DUAL
CONNECT BY LEVEL <= REGEXP_COUNT(P_EXCEPTION_RECORD, '([^^])+')
AS SYS.odciNumberList
) t2
to
SELECT REGEXP_SUBSTR(P_EXCEPTION_RECORD, '([^^])+', 1,level) str
FROM DUAL
CONNECT BY LEVEL <= REGEXP_COUNT(P_EXCEPTION_RECORD, '([^^])+')
Before looking for any performance benefit, you need to ensure that this does not change your output.
How many substrings are you expecting in the P_EXCEPTION_RECORD? If less than 5, it will be better to opt for SUBSTR and INSTR combination as it might work well with the number of records you are working with. Only trouble is, you will have to write different SUBSTR and INSTR statements for each column to be fetched.
How are you calling this procedure? Is it not possible to work with Collections? Delimited strings are not a very good option as it requires splitting of the data every time you need to refer to. -
Returning Multiple Rows From DBAdapter Calling PL/SQL Procedure
Oracle XE 10g Express Edition
JDeveloper 11.1.1.2.0
WebLogic Server 11g
Guys,
I have a table of orders, which I need to interrogate, and pass back any matching rows which meet certain criteria (e.g. status = 'OPEN').
However, rather than create a DBAdapter using an Operation Type of "Peform an Operation on a Table/Select", I need to use an Operation Type of "Call a Stored Procedure or Function".
I therefore need the procedure to return all the matching rows, rather than a single row.
I have looked at declaring return parameters for the procedure of the following types:
RECORD - is good because it allows me to return the elements of the row with their correct datatypes, but does not meet my needs because it will only support the return of a single row.
VARRAY - good because it can contain many row elements, but not good because it only supports a single row return, and also because all elements of the VARRAY must be of the same data type.
TABLE - good because it can contain many rows, but bad because each row can contain only two elements - the index element and the data element.
I think I could first define a RECORD (to hold a row), and then define a TABLE, with the data element being the RECORD, but I have found JDeveloper very fussy indeed when dealing with 'non-standard' data types in the DBAdapter.
Apologies if I am missing something obvious, but can anyone suggest a way of doing this?
Many thanks in advance.
Edited by: user2541290 on 17-Feb-2010 02:48Hi, I've been able to create process that seems to work. My platform is a but different but I don't think this is important for your question.
Here is the PL/SQL code. Just make Db Adapter for Calling stored procedure and it returns all rows!
Be aware of possible limitations on how manyrows you could return in one select! This can have severe impact on performance.
Succes.
Jos Baan
CREATE OR REPLACE PACKAGE lab2_multiple_rows IS
-- Author : 801455
-- Created : 18-2-2010 8:05:52
-- Purpose :
-- Public type declarations
TYPE rrows IS RECORD(
mutdat DATE,
opmerking VARCHAR2(20));
TYPE trows IS TABLE OF rrows INDEX BY BINARY_INTEGER;
-- Public constant declarations
-- Public variable declarations
-- Public function and procedure declarations
FUNCTION retrows RETURN trows;
END lab2_multiple_rows;
CREATE OR REPLACE PACKAGE BODY lab2_multiple_rows IS
-- Private type declarations
-- Private constant declarations
-- Private variable declarations
-- Function and procedure implementations
FUNCTION retrows RETURN trows IS
lrows trows;
lidx binary_integer := 1;
BEGIN
FOR rsql IN (SELECT t.* FROM jba_transactions t ORDER BY t.mutdat)
LOOP
lrows(lidx).mutdat := rsql.mutdat;
lrows(lidx).opmerking := rsql.opmerking;
lidx := lidx + 1;
END LOOP;
RETURN(lrows);
END;
BEGIN
-- Initialization
NULL;
END lab2_multiple_rows;
Edited by: Baan, Jos on 18-feb-2010 8:53 -
Can anyone give me the detailed steps for the payment procedure of the customer once we have created the invoice .Kindly give me the T-codes and tables been hit by the transaction so that I can track payments recieved by the customer.Thanx
Hello Sam,
The basic process of payment when you have created an Billing document (With Accounting Document) is as follows:
You have to essential run a transaction code on SAP system called F-28 so that the finiance related standard table are impacted and uncleared accounting document are cleared. These tables are BSID and BSAD.
After peforming this above step, then kindly run a transaction code called "FBL5N" to check the net receivables/Overdues for a customer or else you can also use the t-code S_ALR_87012172 for viewing the net pending amount for a customer in local currency .
Hope this information helps in clearing your concept about payment.
Regards,
Sarthak -
Calling JPA from a Java Stored Procedure
Is it possible to call JPA from a java stored procedure? If so, does anyone have example? How do you setup the persistence.xml?
How does the peformance compare with straight JDBC in a java stored procedure?
Thanks for any help!
JohnnyHi Johnny:
Basically you can run any JDK 1.5 framework inside your Oracle 11g JVM, I have experience integrating Lucene IR library as a new [Domain Index for Oracle 11g/10g|http://docs.google.com/View?id=ddgw7sjp_54fgj9kg] .
I am not familiar with JPA internals but my advice is howto handle the connection inside the OJVM and the configuration files.
Some time ago I took a look to SpringFramework integration and I found that writing a new ApplicationContext class which handles the loading of beans.xml from XMLDB repository instead a file should be enough to work.
Another important point is the life cycle of the [Oracle internal JVM|http://download.oracle.com/docs/cd/E11882_01/java.112/e10588/chtwo.htm#BABHGJFI]. Unlike an standard JVM the OJVM is created once you first connect from the middle tier at OCI level and remains in execution during the connection pool existence.
I mean, if you connect using a JDBC pool the JVM will remains running across multiple soft open/close connections of your middle tier application. This is good because you can read your persistence.xml file using a Singleton class and this expensive operation will be re-used by multiple open/close operation done from the middle tier.
I suggest you do a simple Proof of Concept with a Hello World application and check if it works.
Remember that any security issues will be notified to the .trc files, security issues are related to the strong security layer configured by default inside the OJVM, for example you can not read any files from the OS file system without an specific grant, you need another grant to access to the class loader and so on, but you can simply grant this specific needs to a database role and then grant this role to the user which connect to the OJVM.
Another important point is related to the [End-of-Call Optimization|http://download.oracle.com/docs/cd/E11882_01/java.112/e10588/chtwo.htm#BABIFAAI] this can be useful if you want to perform some clean up in your Singleton class at the level of per-statement execution.
Best regards, Marcelo -
is it possible to create ,update ,delete the already existing values i nthe database with writeback functinality?(if that field is coming from the dimension table,fact table)
is there any restrictions apply when applying this?Yes - look at the manuals the examples are for insert and update, insert is awkward in that you need to be updating to a table with all null values....
I did this by creating a table, inserting as usual but with values(NULL, NULL, NULL) and using a view with a trigger to then point the data to a different table.
With a little imagination, utilising triggers and a 'insert', 'delete', 'update' drop list - you could have all of the behaviours available by what the trigger based on one value you passed to it....
Or, you could do this all via a procedure.
Security of your data in terms of validations can all be neatly wrapped up that way also.
Hope this helps,
Robert. -
Pricing procedure of free goods
Could anyone please tell me the effect of pricing procedure in free godds?And what is the difference between pricing procedure in free goods(IMG->Sales and Distribution->Basic Funcions->Free Goods) and pricing procedure in pricing(IMG->Sales and Distribution->Basic Funcions->Pricing)
Hi Wei Zhang,
When there are more than 2 materials say material A which is of some price, and material B which is Free of cost, then the item category will be different for those. TAN for Mat A and TANN for materail B.
Pricing is depends upon the customer pricing procedure and document pricing procedure along with the Sales Area.
When there are free Goods, Again yu have two conditions
1. Give 100 % discount on free goods.
2. Or charge 0 value for that.
This pricing procedure you can do in free goods priocing procedure.
Hope this will help.
Thanks,
Raja -
Can not select from data dictionary view from a procedure
Hi,
I wonder, which privilege is missing here:
my schema has this roles and privs:
GRANT CONNECT, RESOURCE TO cb ;
GRANT CREATE SESSION TO cb ;
GRANT SELECT_CATALOG_ROLE TO cb ;
GRANT CREATE SYNONYM TO CB;
GRANT CREATE VIEW TO CB;
I create a procedure:
create or replace procedure dd_test as
begin
dbms_output.enable(2000000);
for r in (select table_name from sys.dba_tab_partitions where owner = 'CB') loop
dbms_output.put_line(r.table_name);
end loop;
end;
sho err
4/38 PL/SQL: ORA-00942: table or view does not exist
When I run the core statement form sql prompt, it works !
so what privilege is missing here ???
thanks for any hint, Lao DeHi,
thanks for that reply, after doing that I can not select this DD-view from sql-prompt anymore (which I don't wonder ;-). Can you tell me, what idea you had behind that test ?
I found another instance, where the procedure works and I will compare those privileges, but it's hard to sort out that complex structure of nested roles and sys_privs.
How ever, I will update here, when I found the missing privilege.
regards LaoDe -
Unable to capture the parameter values from a PL/SQL procedure
hi.
i'm trying to capture the parameter values of a PL/SQL procedure by calling inside a anonymous block but i'm getting a "reference to uninitialized collection error" ORA-06531.
Please help me regarding.
i'm using following block for calling the procedure.
declare
err_cd varchar2(1000);
err_txt VARCHAR2(5000);
no_of_recs number;
out_sign_tab search_sign_tab_type:=search_sign_tab_type(search_sign_type(NULL,NULL,NULL,NULL,NULL));
cntr_var number:=0;
begin
rt843pq('DWS','3000552485',out_sign_tab,no_of_recs,err_cd,err_txt);
dbms_output.put_line('The error is ' ||err_cd);
dbms_output.put_line('The error is ' ||err_txt);
dbms_output.put_line('The cntr is ' ||cntr_var);
for incr in 1 .. OUT_SIGN_TAB.count
loop
cntr_var := cntr_var + 1 ;
Dbms_output.put_line(OUT_SIGN_TAB(incr).ref_no||','||OUT_SIGN_TAB(incr).ciref_no||','||OUT_SIGN_TAB(incr).ac_no||','||OUT_SIGN_TAB(incr).txn_type||','||OUT_SIGN_TAB(incr).objid);
end loop;
end;
Error is thrown on "for incr in 1 .. OUT_SIGN_TAB.count" this line
Following is some related information.
the 3rd parameter of the procedure is a out parameter. it is a type of a PL/SQL table (SEARCH_SIGN_TAB_TYPE) which is available in database as follows.
TYPE "SEARCH_SIGN_TAB_TYPE" IS TABLE OF SEARCH_SIGN_TYPE
TYPE "SEARCH_SIGN_TYPE" AS OBJECT
(ref_no VARCHAR2(22),
ciref_no VARCHAR2(352),
ac_no VARCHAR2(22),
txn_type VARCHAR2(301),
objid VARCHAR2(1024))............We don't have your rt843pq procedure, but when commenting that line out, everything works:
SQL> create TYPE "SEARCH_SIGN_TYPE" AS OBJECT
2 (ref_no VARCHAR2(22),
3 ciref_no VARCHAR2(352),
4 ac_no VARCHAR2(22),
5 txn_type VARCHAR2(301),
6 objid VARCHAR2(1024))
7 /
Type is aangemaakt.
SQL> create type "SEARCH_SIGN_TAB_TYPE" IS TABLE OF SEARCH_SIGN_TYPE
2 /
Type is aangemaakt.
SQL> declare
2 err_cd varchar2(1000);
3 err_txt VARCHAR2(5000);
4 no_of_recs number;
5 out_sign_tab search_sign_tab_type:=search_sign_tab_type(search_sign_type(NULL,NULL,NULL,NULL,NULL));
6 cntr_var number:=0;
7 begin
8 -- rt843pq('DWS','3000552485',out_sign_tab,no_of_recs,err_cd,err_txt);
9 dbms_output.put_line('The error is ' ||err_cd);
10 dbms_output.put_line('The error is ' ||err_txt);
11 dbms_output.put_line('The cntr is ' ||cntr_var);
12 for incr in 1 .. OUT_SIGN_TAB.count
13 loop
14 cntr_var := cntr_var + 1 ;
15 Dbms_output.put_line(OUT_SIGN_TAB(incr).ref_no||','||OUT_SIGN_TAB(incr).ciref_no||','||OUT_SIGN_TAB(incr).ac_no||','||OUT_SIGN
TAB(incr).txntype||','||OUT_SIGN_TAB(incr).objid);
16 end loop;
17 end;
18 /
The error is
The error is
The cntr is 0
PL/SQL-procedure is geslaagd.Regards,
Rob. -
Get Attribute values from a page and procedure exception handling?
Hi All,
I have created new page with two input attributes not based on any VO. This page is created to capture two values and pass these to an AM method upon pressing OK button. The method in AM will call a procedure with two in parameter expecting the two values captured from the above said page.
I have two questions, first one how to capture the values entered by the page in the controller class and advises me how to handle exceptions when my procedure fails.
I can not use something like this since this page is not based on a VO
String fromName = (String)vo.getCurrentRow().getAttribute("FromName");
Do I have to create a dummy VO like select '' name1, '' name2 from dual?
Thanks for the help.Hi,
Actually you can capture the parameters on the page like this way
String test = (String)pageContext.getParameter("id of the text input bean");
Now in procedure you can take an out parameter which stores the error messages on exception
and return that out parameter in java.
and then you can throw exception on page using OAException class.
Thanks
Gaurav Sharma -
Get variable values from a stored procedure
I am using SQL 2008R2 and I want to replace a view inside a stored procedure with a new stored procedure to return multiple variable values. Currently I am using the code below to get values for 4 different variables. I would rather get the 4 variables
from a stored procedure (which returns all of these 4 values and more) but not sure how to do so. Below is the code for getting the 4 variable values in my current sp.
DECLARE @TotalCarb real;
DECLARE @TotalPro real;
DECLARE @TotalFat real;
DECLARE @TotalLiquid real;
SELECT @TotalCarb = ISNULL(TotCarb,0),
@TotalPro = ISNULL(TotPro,0),
@TotalFat = ISNULL(TotFat,0),
@TotalLiquid = ISNULL(TotLiq,0)
FROM dbo.vw_ActualFoodTotals
WHERE (MealID = @MealID);You can replace the view with inline table valued user-defined function:
http://www.sqlusa.com/bestpractices/training/scripts/userdefinedfunction/
See example: SQL create INLINE table-valued function like a parametrized view
Kalman Toth Database & OLAP Architect
SQL Server 2014 Design & Programming
New Book / Kindle: Exam 70-461 Bootcamp: Querying Microsoft SQL Server 2012 -
Pointbase : How can I create a stored procedure with Pointbase database?
Hello,
Excuse me for my english, I'm not anglophone. I try to create a stored procedure.
This is my file SampleExternalMethods.java :
import java.sql.*; //import com.pointbase.jdbc.jdbcInOutDoubleWrapper; public class SampleExternalMethods { // A connection object to allow database callback static Connection conn = null; static Statement l_stmt; static Statement m_stmt; static CallableStatement m_callStmt = null; static ResultSet l_rs = null; public static void main(String[] args) { try { String url = "jdbc:pointbase:server://localhost/pointbaseDB"; String username = "PBPUBLIC"; String password = "PBPUBLIC"; conn = DriverManager.getConnection(url, username, password); doCreateProcedure(); doInvokeProcedure(); } catch (SQLException e) { e.printStackTrace(); } finally { if (m_stmt != null) { try { m_stmt.close(); } catch (Exception e) { e.printStackTrace(); } } if (m_callStmt != null) { try { m_callStmt.close(); } catch (Exception e) { e.printStackTrace(); } } if (conn != null) { try { conn.close(); } catch (Exception e) { e.printStackTrace(); } } } } public static void getCountry(String Iso_Code) { try { // Query the database for the country iso code l_stmt = conn.createStatement(); l_rs = l_stmt.executeQuery( "SELECT * FROM countries" + " WHERE country_iso_code ='" + Iso_Code + "'"); //Affichage du résultat de la requête l_rs.next(); System.out.print(l_rs.getString(1) + " - "); System.out.print(l_rs.getString(2) + " - "); System.out.println(l_rs.getString(3)); // Close the result set l_rs.close(); } catch (SQLException e) { e.printStackTrace(); } finally { if (l_rs != null) { try { l_rs.close(); } catch (Exception e) { e.printStackTrace(); } } if (l_stmt != null) { try { l_stmt.close(); } catch (Exception e) { e.printStackTrace(); } } } } public static void doCreateProcedure() throws SQLException { // SQL statement to create a stored procedure String SQL_CREATE_PROC = "CREATE PROCEDURE getCountry(IN P1 VARCHAR(30))" + " LANGUAGE JAVA" + " SPECIFIC getCountry" + " NO SQL" + " EXTERNAL NAME \"SampleExternalMethods::getCountry\"" + " PARAMETER STYLE SQL"; // Create a SQL statement m_stmt = conn.createStatement(); // Execute the SQL m_stmt.executeUpdate(SQL_CREATE_PROC); // Close the statement //m_stmt.close(); } public static void doInvokeProcedure() throws SQLException { // Create SQL to invoke stored procedures String SQL_USE_PROC = "{ call getCountry(?) }"; // Create a callable statement with three binding parameters m_callStmt = conn.prepareCall(SQL_USE_PROC); m_callStmt.setString(1, "CA"); m_callStmt.executeQuery(); // Close the callable statement //m_callStmt.close(); } }
Afterwards, I have read this note in a Pointbase document:
To invoke the dateConvert external Java method from a stored function, you must use the
CREATE FUNCTION statement. The dateConvert external Java method is called from the
class, SampleExternalMethods.
In order for the database to access this external Java method, the class SampleExternalMethods
must be included in the database CLASSPATH. For PointBase Embedded - Server Option, it
must be in the Server CLASSPATH, but not in the Client CLASSPATH.
If PointBase Server is run with the Java Security Manager, in the java policy file grant
’com.pointbase.sp.spPermission’ to the class that implements the external Java method.
An "spPermission" consists of a class name with no action. The class name is a name of a class
that could be used in creating a Stored Procedure in PointBase. The naming convention follows
the hierarchical property naming convention and that is supported by
"java.security.BasicPermission". An asterisk may appear by itself, or if immediately preceded
by ".", may appear at the end of the name, to signify a wildcard match. The name cannot
contain any white spaces.
I'm not sure, but I suppose that I must include the class SampleExternalMethods in a .jar file.
The database CLASSPATH could be : C:\Sun\AppServer\pointbase\lib\
These my files in this database CLASSPATH:
pbclient.jar
pbembedded.jar
pbtools.jar
pbupgrade.jar
I have tryed to include the class SampleExternalMethods in pbclient.jar and pbembedded.jar with this command:
jar -uf pbembedded.jar SampleExternalMethods
Afterwards I do that,
1) Start Pointbase
2) Configuration of classpath
set classpath=C:\Sun\AppServer\pointbase\lib\pbclient.jar
set classpath=%classpath%;D:\J2EE\Ch07Code\Ch07_06
I precise that my file SampleExternalMethods is into D:\J2EE\Ch07Code\Ch07_06\Ch07.
Then, I run the program:
D:\J2EE\Ch07Code\Ch07_06>java -Djdbc.drivers=com.pointbase.jdbc.jdbcUniversalDriver Ch07.SampleExternalMethods
But I have an error message:
Exception in thread "main" java.lang.NoClassDefFoundError: Ch07.SampleExternalMethods (wrong name: SampleExternalMethods)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.DefineClass(ClassLoader.java:539)
The problem, I suppose, comes from that the class SampleExternalMethods
must be included in the database CLASSPATH, but there is a pbserver.jar with pointbase normally, but I didn't find it. That's why I use pbembedded.jar or pbclient.jar in order to include the class SampleExternalMethods. May be I must start from C:\Sun\AppServer\pointbase\lib\ instead of D:\J2EE\Ch07Code\Ch07_06\Ch07?
Please, can somebody helps me?
Thank you in advance.
cagou!jschell wrote:
And I doubt you can recurse like that for embedded java. You must have a class that does the functionality and another class that creates the proc.
>And I doubt you can recurse like that for embedded java. You must have a class that does the functionality and another class that creates the proc.
>
And I doubt you can recurse like that for embedded java. You must have a class that does the functionality and another class that creates the proc.
Thank you for your response, I have done two classes:
SampleExternalMethods.java:
package Ch07;
import java.sql.*;*
*public class SampleExternalMethods*
*public static void getCountry(String Iso_Code)*
*// A connection object to allow database callback*
*Connection l_conn = null;*
*Statement l_stmt = null;*
*ResultSet l_rs = null;*
*try*
*String url = "jdbc:pointbase:server://localhost/pointbaseDB";*
*String username = "PBPUBLIC";*
*String password = "PBPUBLIC";*
*l_conn = DriverManager.getConnection(url, username, password);*
*// Query the database for the country iso code*
*l_stmt = l_conn.createStatement();*
*l_rs = l_stmt.executeQuery( "SELECT* FROM PBPUBLIC.COUNTRIES"
+" WHERE country_iso_code ='"+ Iso_Code +"'");+
+//Affichage du résultat de la requête+
+l_rs.next();+
+System.out.print(l_rs.getString(1)+ " - ");
System.out.print(l_rs.getString(2) +" - ");+
+System.out.println(l_rs.getString(3));+
+// Close the result set+
+l_rs.close();+
+} catch (SQLException e) {+
+e.printStackTrace();+
+} finally {+
+if (l_rs != null) {+
+try {+
+l_rs.close();+
+} catch (Exception e) {+
+e.printStackTrace();+
+}+
+}+
+if (l_stmt != null) {+
+try {+
+l_stmt.close();+
+} catch (Exception e) {+
+e.printStackTrace();+
+}+
+}+
+if (l_conn != null) {+
+try {+
+l_conn.close();+
+} catch (Exception e) {+
+e.printStackTrace();+
+}+
+}+
+}+
+}+
+}+
CreateMethods.java:
+package Ch07;+
+import java.sql.*;+
+public class CreateMethods+
+{+
+// A connection object to allow database callback+
+static Connection m_conn = null;+
+static Statement m_stmt;+
+static CallableStatement m_callStmt = null;+
+public static void main(String[] args)+
+{+
+try+
+{+
+String url = "jdbc:pointbase:server://localhost/pointbaseDB";+
+String username = "PBPUBLIC";+
+String password = "PBPUBLIC";+
+m_conn = DriverManager.getConnection(url, username, password);+
+doCreateProcedure();+
+doInvokeProcedure();+
+} catch (SQLException e) {+
+e.printStackTrace();+
+} finally {+
+if (m_stmt != null) {+
+try {+
+m_stmt.close();+
+} catch (Exception e) {+
+e.printStackTrace();+
+}+
+}+
+if (m_callStmt != null) {+
+try {+
+m_callStmt.close();+
+} catch (Exception e) {+
+e.printStackTrace();+
+}+
+}+
+if (m_conn != null) {+
+try {+
+m_conn.close();+
+} catch (Exception e) {+
+e.printStackTrace();+
+}+
+}+
+}+
+}+
+public static void doCreateProcedure() throws SQLException {+
+// SQL statement to create a stored procedure+
+String SQL_CREATE_PROC = "CREATE PROCEDURE PBPUBLIC.getCountry(IN P1 VARCHAR(30))"+
" LANGUAGE JAVA"
+" SPECIFIC getCountry"+
" NO SQL"
+" EXTERNAL NAME \"SampleExternalMethods::getCountry\""+
" PARAMETER STYLE SQL";
// Create a SQL statement
m_stmt = m_conn.createStatement();
// Execute the SQL
m_stmt.executeUpdate(SQL_CREATE_PROC);
// Close the statement
//m_stmt.close();
public static void doInvokeProcedure() throws SQLException {
// Create SQL to invoke stored procedures
String SQL_USE_PROC = "{ call getCountry(?) }";
// Create a callable statement with three binding parameters
m_callStmt = m_conn.prepareCall(SQL_USE_PROC);
m_callStmt.setString(2, "CA");
m_callStmt.executeQuery();
// Close the callable statement
//m_callStmt.close();
}But I have the same error message that previously.
I have read this note and I suppose that the problem is linked:
If PointBase Server is run with the Java Security Manager, in the java policy file grant
*com.pointbase.sp.spPermission to the class that implements the external Java method.*
An "spPermission" consists of a class name with no action. The class name is a name of a class
that could be used in creating a Stored Procedure in PointBase. The naming convention follows
the hierarchical property naming convention and that is supported by
*"java.security.BasicPermission". An asterisk may appear by itself, or if immediately preceded*
by ".", may appear at the end of the name, to signify a wildcard match. The name cannot
contain any white spaces.
Can you explain me what I must to do in order to solve this problem of spPermission.
Thanks. -
How to view the returned data from a stored procedure in TOAD?
Hi,
I created ref cursor in the stored procedure to return data. The stored procedure works fine, just want to view the result in TOAD. The BEGIN... EXEC... END can execute the stored procedure, but how to make the result display?
Thanks!Right click the editor and choose
"Prompt For Substitution Variables".
Run for example the following code:
DECLARE
PROCEDURE p (cur OUT sys_refcursor)
AS
BEGIN
OPEN cur FOR
SELECT *
FROM DUAL;
END p;
BEGIN
p (:cur);
END;
The result will display in Toad's Data Grid!
Regards Michael -
Error while running a stored procedure in SBO
Hi all,
i have a stored procedure that i run in my sbo. When i run the stored procedure i get the following error :
1). [Microsoft][SQL Server Native Client 10.0][SQL Server]Warning: Null value is eliminated by an aggregate or other SET operation.
'Servicecontracten' (OCTR) 05/10/2011 18:03:36 -1
i launch my sp like this :
exec [spu_DS_HistProjektUserVeldenViewBetalingen] (i pass no parameters while testing. i put them fix in my sp)
my stored procedure looks like this :
USE [def1]
GO
/****** Object: StoredProcedure [dbo].[spu_DS_HistProjektUserVeldenViewBetalingen] Script Date: 10/05/2011 18:03:05 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- Batch submitted through debugger: SQLQuery2.sql|8|0|C:\Users\kvanhauwaert\AppData\Local\Temp\~vs2A98.sql
ALTER PROCEDURE [dbo].[spu_DS_HistProjektUserVeldenViewBetalingen]
/* @project_number varchar(20),
@billperiod_type varchar(10) */
AS
BEGIN
SELECT isnull(lijnnr,0) as lijnnr, isnull(fase,'') as fase, isnull(factuurbedrag,0) as factuurbedrag,
isnull(billperiod_type,'') as billperiod_type
INTO #tempDS_HistProjektUserVeldenViewBetalingen
FROM DS_HistProjektUserVeldenViewBetalingen t1
WHERE project_number = '08053A'
SELECT isnull(lijnnr,0) as lijnnr, isnull(fase,'') as fase , isnull(factuurbedrag,0) as factuurbedrag,
(select sum(isnull(factuurbedrag,0)) from #tempDS_HistProjektUserVeldenViewBetalingen where lijnnr <= t1.lijnnr) as lijntotaal,
(select sum(isnull(factuurbedrag,0)) from #tempDS_HistProjektUserVeldenViewBetalingen where lijnnr <= t1.lijnNr and billperiod_type = '110-01' ) as lijntotaalKetting
FROM #tempDS_HistProjektUserVeldenViewBetalingen t1
WHERE fase,'') is not null
ORDER BY t1.fase
DROP TABLE #tempDS_HistProjektUserVeldenViewBetalingen
END
GO
Somebody has a clue what i'm doing wrong ?
thnxThanks Gordon for your reply.
i've changed my sp to :
USE [def1]
GO
/****** Object: StoredProcedure [dbo].[spu_DS_HistProjektUserVeldenViewBetalingen] Script Date: 10/05/2011 18:56:34 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- Batch submitted through debugger: SQLQuery2.sql|8|0|C:\Users\kvanhauwaert\AppData\Local\Temp\~vs2A98.sql
CREATE PROCEDURE [dbo].[spu_DS_HistProjektUserVeldenViewBetalingen]
/* @project_number varchar(20),
@billperiod_type varchar(10) */
AS
BEGIN
SELECT isnull(lijnnr,0) as lijnnr, isnull(fase,'') as fase, isnull(factuurbedrag,0) as factuurbedrag,
isnull(billperiod_type,'') as billperiod_type
INTO #tempDS_HistProjektUserVeldenViewBetalingen
FROM DS_HistProjektUserVeldenViewBetalingen t1
WHERE isnull(project_number,'') = '08053A'
SELECT isnull(lijnnr,0) as lijnnr, isnull(fase,'') as fase , isnull(factuurbedrag,0) as factuurbedrag,
(select sum(isnull(factuurbedrag,0)) from #tempDS_HistProjektUserVeldenViewBetalingen where isnull(lijnnr,0) <= isnull(t1.lijnnr,0)) as lijntotaal,
(select sum(isnull(factuurbedrag,0)) from #tempDS_HistProjektUserVeldenViewBetalingen where isnull(lijnnr,0) <= isnull(t1.lijnNr,0) and isnull(billperiod_type,'') = '110-01' ) as lijntotaalKetting
FROM #tempDS_HistProjektUserVeldenViewBetalingen t1
WHERE isnull(fase,'') <> ''
ORDER BY t1.fase
DROP TABLE #tempDS_HistProjektUserVeldenViewBetalingen
END
GO
but that didn't solved my problem. Any other idea's ?
kind regards.
Kurt -
Error while opening two cursors in same procedure...
Hi :
I have written following Procedure:
Declare
procedure pro_canefortnight_master Is
kr_caneperiodid integer;
last_caneperiod_id number(10,0);
kr_forthnightid integer;
last_forthnight_id number(10,0);
ref_caneperiodid integer;
ref_seasonyrid integer;
ctr integer:= 1;
CURSOR comp_cur IS select * from CMS_SEASON_YEAR_MASTER ;
comp_rec comp_cur%ROWTYPE;
BEGIN
OPEN comp_cur;
FETCH comp_cur INTO comp_rec;
WHILE comp_cur%FOUND
LOOP
kr_caneperiodid:= comp_rec.SEASON_YR_ID;
select max(crayom_db.cr_cane_calender.cr_cane_calender_ID) into last_caneperiod_id from crayom_db.cr_cane_calender;
if last_caneperiod_id <> 0 then
last_caneperiod_id:= last_caneperiod_id + 1;
else
last_caneperiod_id:= 1000000;
end if;
insert into crayom_db.CR_CANE_CALENDER(cr_cane_calender_ID,ad_client_id, ad_org_id, isactive, created, createdby, updated, updatedby,CR_CANE_CALENDER_NAME,DESCRIPTION) values(last_caneperiod_id,11,11,comp_rec.current_season,sysdate,100,sysdate,11,comp_rec.DESC_MA,comp_rec.DESC_EN);
COMMIT;
/*insert into crayom_db.CR_IdBackup(kr_cultivationtypeid,cr_cultivationtypeid) values(kr_cultivationtypeid, last_cultivationtype_id);*/
insert into crayom_db.temp(kr_bpartnerid,cr_bpartnerid) values(comp_rec.season_yr_id,last_caneperiod_id);
commit;
FETCH comp_cur INTO comp_rec;
End LOOP;
close comp_cur;
CURSOR comp_cur1 IS select * from CMS_FORTH_NIGHT_MASTER ;
comp_rec1 comp_cur1%ROWTYPE;
OPEN comp_cur1;
FETCH comp_cur1 INTO comp_rec1;
WHILE comp_cur1%FOUND
LOOP
kr_forthnightid:= comp_rec1.forthnight_id;
select max(crayom_db.cr_cane_calender_period.cr_cane_calender_period_ID) into last_forthnight_id from crayom_db.cr_cane_calender_period;
if last_forthnight_id <> 0 then
last_forthnight_id:= last_forthnight_id + 1;
else
last_forthnight_id:= 1000000;
end if;
if ref_seasonyrid <> comp_rec1.season_yr_id then
ref_seasonyrid:= comp_rec1.season_yr_id;
else
ctr:= ctr + 1;
end if;
SELECT cr_bpartnerid into ref_caneperiodid from crayom_db.temp where kr_bpartnerid = comp_rec1.season_yr_id;
dbms_output.put_line(ref_caneperiodid);
insert into crayom_db.CR_CANE_CALENDER_period(cr_cane_calender_period_ID,ad_client_id, ad_org_id, isactive, created, createdby, updated, updatedby,Enddate,name, startdate, cr_cane_calender_id) values(last_forthnight_id,11,11,comp_rec1.current_season,sysdate,100,sysdate,11,comp_rec1.end_date,'ForthNight' || ctr, comp_rec1.start_date,ref_caneperiodid);
commit;
FETCH comp_cur1 INTO comp_rec1;
End LOOP;
close comp_cur1;
END;
BEGIN
pro_canefortnight_master();
END;
But I am getting following Error:
Error report:
ORA-06550: line 429, column 8:
PLS-00103: Encountered the symbol "COMP_CUR1" when expecting one of the following:
:= . ( @ % ;
ORA-06550: line 433, column 1:
PLS-00103: Encountered the symbol "FETCH" when expecting one of the following:
begin function package pragma procedure subtype type use
<an identifier> <a double-quoted delimited-identifier> form
current cursor
The symbol "begi
ORA-06550: line 472, column 1:
PLS-00103: Encountered the symbol "BEGIN" when expecting one of the following:
end not pragma final instantiable order overriding static
member constructor map
ORA-06550: line 477, column 4:
PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following:
end not pragma final instantiable order overriding static
member constructor map
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
Can any body help me?
Thank You.
Edited by: [email protected] on Oct 22, 2009 4:36 AM[email protected] wrote:
CURSOR comp_cur1 IS select * from CMS_FORTH_NIGHT_MASTER ;
comp_rec1 comp_cur1%ROWTYPE;This is probably the issue. All variable definitions, including cursors, must be in the DEFINE section of a procedure (between either DECLARE ... BEGIN or AS/IS ... BEGIN).
In addition I wanted to note the following:
1. When posting it is helpful to identify your Oracle version (e.g. 10.2.0.4).
2. Any code that is posted should be placed between \ tags to improve readability.
3. It looks like the code is doing "slow by slow" processing (a.k.a single record processing). It could probably be made much cleaner, maintainable and better performing by possibly using INSERT .. AS SELECT ... or something along those lines.
Maybe you are looking for
-
Premiere Pro CC - Program Monitor shows only black screen
Hi All, I am hoping someone out there can help me (and I am sure many others) with this problem. I was using Premiere Pro CS6 and was half way through a project when I upgraded to Premiere Pro CC. This was fine and I finished the project, however soo
-
How do I specify different emails for a form to send to based on different selections?
How do I specify different emails for a form to send to based on different selections? Creating a form that can be sent to an email address is simple enoug but my problem I can't figure out. There is a drop down menu on the form and based on what th
-
Populate a field in Forms with a blob
I am trying to populate a field in Forms using a blob from an Oracle database. When we try to run the query to reference the field we get an error that states this cannot be done in this context. Is there a way to accomplish this. Thank you.
-
No detail when approving Journal via Notifications Window
Hello, User approving Journal Entry via Notifications Window can not see the Journal Detail. His responsibility has Journals / Post and Inquiry / Journal. Is the Journals / Entry access needed to be able to see the Journal Detail? Thanks, Syvelle
-
Hi, Is oracle still providing support for IDS 9i R2? Thanks in advance.