Recursive stored procedure
Hi,
I have a table with the following fields:
material component
a material contents one or more components and it could happen that a material could content itself in whatever level. For example:
material component material component material component
g001 j001 j001 mm03 t005 g001
g001 j002 j001 t005 t005 s002
g001 m001
g001 s002
I need to develop a stored procedure which stops when a component begins with m or s or when there is a loop. In the example the sp should stop in the t005 material because it contents the s002 (begins with s) component and the g001 is a loop. In case of
the g001 material shouls stop in m001 ans s002 components, should stop in j002 because this component has no components and should stop in the j001 component because finishes in the t005 material.
I developed a sp with loops which works when I have only one or two level but now there are more level and is impossible with my sp.
This is the first time I work with recursion in sp. I have seen the typical factorial algorithm with sp but I think my problem is a little more complicated.
Please, could anybody help me?
Thanks a lot in advance.
Please post DDL, so that people do not have to guess what the keys, constraints, Declarative Referential Integrity, data types, etc. in your schema are. Learn how to follow ISO-11179 data element naming conventions and formatting rules. Temporal data should
use ISO-8601 formats. Code should be in Standard SQL as much as possible and not local dialect.
This is minimal polite behavior on SQL forums. What are you so rude to everyone here? Now we have to guess at everything to do your job for you.
>> I have a table with the following fields: <<
No, you do not. Columns are not fields (read the ANSI standard and find what an field really id!), tables are not files and records are not rows.
>> material component material contents one or more components and it could happen that a material could content itself in whatever level. <<
No, that would lead to infinite recursion in the parts explosion.
>> I need to develop a stored procedure which stops when a component begins with m or s or when there is a loop. <<
You have never had a course in basic software engineering. This procedure would be controlled by its external data.
In the example the sp should stop in the t005 material because it contents the s002 (begins with s) component and the g001 is a loop. In case of the g001 material should stop in m001 ans s002 components, should stop in j002 because this component has no components
and should stop in the j001 component because finishes in the t005 material.
>> I developed a sp with loops .. <<
Declarative languages like SQL do not use loops. You are just using T-SQL to keep writing your old COBOL programs
>> This is the first time I work with recursion in sp. I have seen the typical factorial algorithm with sp but I think my problem is a little more complicated. <<
No, your mindset is wrong. Use a nested sets model. I have a chapter on the parts explosion problem in my books on trees. I would give you more, but your ASCII picture is useless.
--CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
in Sets / Trees and Hierarchies in SQL
Similar Messages
-
Wrapped in a function and/or stored procedure, recursive CTE stops working
This query builds an hierarchical tree from a single table with the typical
value/reports_to_value columns.
When running in SQL manager returns like 7 records (note i'm avoiding infinite
loop by blocking top level value)
WITH c
AS
SELECT deptid, reports_to_dept
FROM glo_tree
WHERE deptid = '18538'
UNION ALL
SELECT t.deptid, t.reports_to_dept
FROM glo_tree T
INNER JOIN c
ON t.deptid = c.reports_to_dept
where t.deptid <> '00001'
SELECT deptid
FROM c
However, the exact same query, if wrapped in a function and/or stored procedure,
returns 0 records (no error message whatsoever)
CREATE FUNCTION [dbo].[checkDept] (@deptid varchar(16))
RETURNS TABLE
AS
RETURN
WITH c
AS
SELECT deptid, reports_to_dept
FROM glo_tree
WHERE deptid = @deptid
UNION ALL
SELECT t.deptid, t.reports_to_dept
FROM glo_tree T
INNER JOIN c
ON t.deptid = c.reports_to_dept
SELECT deptid
FROM c
GO
CREATE PROCEDURE [dbo].[getDept] (@deptid varchar(16))
AS
SELECT deptid
FROM dbo.checkDept(@deptid)
Then call them like:
select * FROM checkDept('18538')exec getDept @deptid='18538'
Both return nothingThanks Patrick, i don't think it can do that, i call it like:
select * FROM checkDept('18538')exec getDept @deptid='18538'Just to make sure, i've changed the function like:WHERE ltrim(rtrim(deptid)) = @deptidStill the same thing -
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. -
MaxDB 7.6 carshes on calling stored procedure with driver 7.6
Hi All,
Recently I upgraded MaxDB from v7.5 to v7.6 after several hiccups I am almost done but one strange problem remains. I have a stored procedure which is used for generating Bill Of Material (recursive cursor). The said stored procedure uses some views (if that matters at all). If I call that stored procedure using JDBC driver v7.5 then all works well and if JDBC driver v7.6 is used to call the stored procedure it simply crashes the database. Does not it sound strange
Does anyone have any clues?
Thanks,
VinodHi Marco,
Here is the stored procedure, which causes database crash-
START -
[code]CREATE DBPROC shortlist_all_month (IN schedule VARCHAR(14)) RETURNS CURSOR AS
$CURSOR = 'bom';
BEGIN
CREATE TABLE temp.bom_view
(bom_version, main_item_code, sub_item_code, sub_item_qty, bom_item_remarks) AS
SELECT bom_version, main_item_code, sub_item_code, sub_item_qty, bom_item_remarks
FROM suman.mfg_bom_m
WHERE bom_version = (SELECT MAX(bom_version) FROM suman.mfg_bom_m M
WHERE M.main_item_code = mfg_bom_m.main_item_code);
DECLARE :$CURSOR CURSOR FOR
WITH RECURSIVE PX (main, sub, qty, super_main) AS
(SELECT main_item_code, sub_item_code, sub_item_qty, main_item_code
FROM temp.bom_view WHERE main_item_code IN (
SELECT schedule_plan_item FROM suman.ppc_schedule_m WHERE schedule_code = :schedule)
UNION ALL
SELECT main_item_code, sub_item_code, sub_item_qty, super_main
FROM temp.bom_view B, suman.PX
WHERE sub = B.main_item_code)
SELECT sub AS sub_item_code, item_item_desc, item_mfg_flag, stock_item_qty,
SUM(qty * schedule_plan_qty) AS req_qty, (stock_item_qty - SUM(qty * schedule_plan_qty)) AS short_qty
FROM suman.PX B, suman.ppc_schedule_m S, suman.mfg_item_p I, suman.mfg_item_stock V
WHERE B.super_main = S.schedule_plan_item
AND schedule_code = :schedule
AND B.sub = I.item_item_code
AND B.sub = V.stock_item_code
AND V.stock_dept_code = 'DP0008'
GROUP BY sub, item_item_desc, item_mfg_flag, stock_item_qty
HAVING SUM(qty * schedule_plan_qty) > 0 ORDER BY 3, 1;
DROP TABLE TEMP.BOM_VIEW;
END;[/code]----
END -
This used to work fine for last >4 years. See if you can find something fishy. I will try to give a runnable test case to reproduce the crash.
Thanks,
Vinod -
Stored Procedure error in Java
My Java application is invoking stored procedure(Oracle 10g). The stored procedure is opening a cursor for a SQL query that is created dynamically in side the procedure. Whenever there is an error while opening the cursor (i.e. executing the SQL query), I get the following exception message in Java application logs irrespective of what error has caused during SQL execution.
SQLException for SQL [{call PRC_TEST(?, ?, ?, ?, ?, ?, ?, ?)}]; SQL state [60000]; error code [604]; ORA-00604: error occurred at recursive SQL level 1
ORA-01003: no statement parsed
; nested exception is java.sql.SQLException: ORA-00604: error occurred at recursive SQL level 1
ORA-01003: no statement parsed
e.g. If the query is like select * from tableA and I dont have proper privlieges. I should get error message while opening the cursor :- insufficient privileges.
Is there any way where we can get more precise(or exact!) error message (in Java application logs) that stopped SQL execution while opening the cursor?I'm using a callable statement.
The strange thing is that, when i remove all IN and OUT paramters in the java code and the stored procedure, both the call to the stored procedure and teh execution of the stored procedure works.
The moment I add in just a IN parameter (in the stored procedure, and setting it in the java code) it stops working, and i receive this error.
java.sql.SQLException: ORA-06550: line 1, column 23:
PLS-00103: Encountered the symbol "" when expecting one of the following:
:= . ( @ % ;
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:114)
heres the java code and stored procedure
CREATE OR REPLACE PROCEDURE sampleProcedure(tax out number)
is
BEGIN
tax := 10 *.15;
/END;
CallableStatement statement =conn.prepareCall("{call sampleprocedure ?}");
statement.registerOutParameter(1,java.sql.Types.INTEGER);
statement.execute();
ResultSet rs = statement.getResultSet();
if((rs = statement.getResultSet()) != null){ -
Exit stored procedure after UPDATE
Hello,
I have written a LOOP that calls a second Stored Procedure.
In the second Stored Procedure I have 3 INSERTS each SELECT's values limited with a WHERE clause.
Example:
begin
dynsql:=INSERT INTO destinationtable (ID,DATE,NAME)
SELECT src.ID,src.DATE, dest.NAME FROM sourcetable src INNER JOIN destinationtable dest ON dest.ID=src.ID WHERE dest.date between '01.JAN.2012 and '03.JAN.2012' --if not condition not met, no insert
execute immediate dynsql;
dynsql:=UPDATE destinationtable SET DATE = dest.DATE FROM sourcetable src INNER JOIN destinationtable dest ON dest.ID=src.ID WHERE dest.date between '01.JAN.2012 and '03.JAN.2012'
execute immediate dynsql;
dynsql:=INSERT INTO destinationtable (ID,DATE,NAME)
SELECT src.ID,src.DATE, dest.NAME FROM sourcetable src INNER JOIN destinationtable dest ON dest.ID=src.ID WHERE dest.date between '01.APR.2012 and '01.MAY.2012' --if not condition not met, no insert
execute immediate dynsql
dynsql:=UPDATE destinationtable SET DATE = dest.DATE FROM sourcetable src INNER JOIN destinationtable dest ON dest.ID=src.ID WHERE dest.date between '01.APR.2012 and '01.MAY.2012'
execute immediate dynsql;
dynsql:=INSERT INTO destinationtable (ID,DATE,NAME)
SELECT src.ID,src.DATE, dest.NAME FROM sourcetable src INNER JOIN destinationtable dest ON dest.ID=src.ID WHERE dest.date between '01.JUN.2012 and '01.JUL.2012' --if not condition not met, no insert
execute immediate dynsql;
dynsql:=UPDATE destinationtable SET DATE = dest.DATE FROM sourcetable src INNER JOIN destinationtable dest ON dest.ID=src.ID WHERE dest.date between '01.JUN.2012 and '01.JUL.2012'
execute immediate dynsql;
end;
commit;What do I do?
I update the existing "old" row with a new date and then I am basically duplicating that row but adding it with a new DATE, the ID and NAME is "copied" as it is.
The big problem is that the rows result in recursive updates. if the first statement updates a date it might make the conditions for the second and first update become "true".
Which is not what I want. Initially, only one of the statements is true, ever. The problem with my code is that after the first update and date setting, another "might" become true.
This should stop. After one of the updates occured, I need to stop the stored procedure.
How do I stop it after upate?metalray wrote:
Hello BlueShadow, that makes sense. Thanks.
Can you tell me when sql&rowcount is reset, after an execute immediate, after a commit?It doesn't get 'reset' in the strict sense. When a PL/SQL program unit is initiated the implicit "SQL" cursor space is defined and exists in the scope of that program unit. At that point it is like any variable that is declared with it's value undefined (null). When you issue any DML statement (insert, update, delete, merge etc.), these will explicitly set the ROWCOUNT attribute within the SQL cursor space. Other SQL statements are also issued from PL/SQL through the SQL "space" (interface), and as such, they may (it's not defined anywhere) effect the values of attributes within it, including the ROWCOUNT, but we cannot say exactly in what way. Therefore, the only thing that can be definitely determined is that a) when it's first instantiated, the SQL%ROWCOUNT will be null, and also, )_immediately_ after any appropriate DML statement the SQL%ROWCOUNT will contain the number of rows effected. If the SQL%ROWCOUNT value is examined at any other point, the value is indeterminate so, for example, after a commit statement, we cannot be sure what value it has or what that value refers to.
I loop through each tax no. need to do either an update, update or delete, delete, each with different WHERE clauses. the danger is that
I update and then the where clause for the deletion becomes true, but my process should not do the deletion if an update happened. its a sequential check and ones true and update/deletion made, the loop stored procedure should terminate. right now I check for sql&rowcount to "not" get into a update or delete if one already happened but I fail to grasp the logic of when sql&rowcount gets which value . I have the feeling that the parent stored procedure that calls my second one with the update and deletes sets the sqlrowcount to 1 because it has an insert. (I use 11g)After your insert/update you should immediately get the value of SQL%ROWCOUNT into a variable, so that you have the value before it is effected by other statements.
You can then use that value in your variable to determine program logic e.g. whether the delete should process or not, regardless of whether you issued further code between the insert/update and the check to see if you should delete. Don't rely on things 'resetting' the ROWCOUNT attribute, only rely on things setting it. -
Finding Stored Procedure(s) Executed
Hi,
I need to find which stored procedure got executed when I run my application.
My application is in .NET and I am using Oracle 9.2.0.5
Thanks in advance.
Pravin PawarYou can use SQL trace and TKPROF for that.
1. Creation of PL/SQL and execution of procedures:
bas002>
bas002>
bas002> create or replace procedure p2
2 is
3 d date;
4 begin
5 select sysdate into d from dual;
6 end;
7 /
Procedure created.
bas002> show errors
No errors.
bas002>
bas002> create or replace procedure p1
2 is
3 n number;
4 begin
5 p2;
6 select count(*) into n from dual;
7 end;
8 /
Procedure created.
bas002> show errors
No errors.
bas002>
bas002> create or replace procedure p0
2 is
3 begin
4 null;
5 end;
6 /
Procedure created.
bas002> show errors
No errors.
bas002>
bas002>
bas002> alter session set sql_trace=true;
Session altered.
bas002>
bas002> exec p1;
PL/SQL procedure successfully completed.
bas002>
bas002> exec p0;
PL/SQL procedure successfully completed.
bas002>
bas002> alter session set sql_trace=false;
Session altered.2. use TKPROF to get formated trace file:
tkprof bas002_ora_892.trc output=test.trctest.trc contains:
TKPROF: Release 10.2.0.2.0 - Production on Wed Jan 30 15:03:54 2008
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Trace file: bas002_ora_892.trc
Sort options: default
count = number of times OCI procedure was executed
cpu = cpu time in seconds executing
elapsed = elapsed time in seconds executing
disk = number of physical reads of buffers from disk
query = number of buffers gotten for consistent read
current = number of buffers gotten in current mode (usually for update)
rows = number of rows processed by the fetch or execute call
alter session set sql_trace=true
call count cpu elapsed disk query current rows
Parse 0 0.00 0.00 0 0 0 0
Execute 1 0.00 0.00 0 0 0 0
Fetch 0 0.00 0.00 0 0 0 0
total 1 0.00 0.00 0 0 0 0
Misses in library cache during parse: 0
Optimizer mode: ALL_ROWS
Parsing user id: 55
BEGIN p1; END;
call count cpu elapsed disk query current rows
Parse 1 0.00 0.00 0 0 0 0
Execute 1 0.03 0.03 0 0 0 1
Fetch 0 0.00 0.00 0 0 0 0
total 2 0.03 0.03 0 0 0 1
Misses in library cache during parse: 1
Optimizer mode: ALL_ROWS
Parsing user id: 55
SELECT SYSDATE
FROM
DUAL
call count cpu elapsed disk query current rows
Parse 1 0.00 0.01 0 0 0 0
Execute 1 0.00 0.00 0 0 0 0
Fetch 1 0.00 0.00 0 0 0 1
total 3 0.00 0.02 0 0 0 1
Misses in library cache during parse: 1
Optimizer mode: ALL_ROWS
Parsing user id: 55 (recursive depth: 1)
SELECT COUNT(*)
FROM
DUAL
call count cpu elapsed disk query current rows
Parse 1 0.00 0.00 0 0 0 0
Execute 1 0.00 0.00 0 0 0 0
Fetch 1 0.00 0.00 0 0 0 1
total 3 0.00 0.00 0 0 0 1
Misses in library cache during parse: 1
Optimizer mode: ALL_ROWS
Parsing user id: 55 (recursive depth: 1)
BEGIN p0; END;
call count cpu elapsed disk query current rows
Parse 1 0.00 0.00 0 0 0 0
Execute 1 0.00 0.00 0 0 0 1
Fetch 0 0.00 0.00 0 0 0 0
total 2 0.00 0.00 0 0 0 1
Misses in library cache during parse: 0
Optimizer mode: ALL_ROWS
Parsing user id: 55
alter session set sql_trace=false
call count cpu elapsed disk query current rows
Parse 1 0.00 0.00 0 0 0 0
Execute 1 0.00 0.00 0 0 0 0
Fetch 0 0.00 0.00 0 0 0 0
total 2 0.00 0.00 0 0 0 0
Misses in library cache during parse: 0
Optimizer mode: ALL_ROWS
Parsing user id: 55
OVERALL TOTALS FOR ALL NON-RECURSIVE STATEMENTS
call count cpu elapsed disk query current rows
Parse 3 0.00 0.00 0 0 0 0
Execute 4 0.03 0.03 0 0 0 2
Fetch 0 0.00 0.00 0 0 0 0
total 7 0.03 0.03 0 0 0 2
Misses in library cache during parse: 1
OVERALL TOTALS FOR ALL RECURSIVE STATEMENTS
call count cpu elapsed disk query current rows
Parse 2 0.00 0.01 0 0 0 0
Execute 2 0.00 0.00 0 0 0 0
Fetch 2 0.00 0.00 0 0 0 2
total 6 0.00 0.02 0 0 0 2
Misses in library cache during parse: 2
6 user SQL statements in session.
0 internal SQL statements in session.
6 SQL statements in session.
Trace file: bas002_ora_892.trc
Trace file compatibility: 10.01.00
Sort options: default
1 session in tracefile.
6 user SQL statements in trace file.
0 internal SQL statements in trace file.
6 SQL statements in trace file.
6 unique SQL statements in trace file.
60 lines in trace file.
0 elapsed seconds in trace file.I don't know if it's possible to get with TKPROF all procedures called by top level procedures (in this example p2 call is missing).
I made this test with 10.2.0.2 but it should work the same for 9.2.0.5.
Message was edited by:
Pierre Forstmann -
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 -
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 deploying a Java Stored Procedure using JDeveloper
Hi,
I was going thru the Oracle By Example article: "Developing SQL and PL/SQL with JDeveloper". (http://www.oracle.com/technology/obe/obe9051jdev/ide1012/plsqlobe/obeplsql.htm)
One of the items in this article is - "Creating and Deploying a Java Stored Procedure"
I was able to create a java class, compile it. Created a deployment profile. created a pl/sql wrapper. While trying to deploy the java stored procedure, I am getting the following error:
Invoking loadjava on connection 'hr_conn' with arguments:
-order -resolve -thin
errors : class package1/mypackage/JavaStoredProc
ORA-29521: referenced name java/lang/StringBuilder could not be found
The following operations failed
class package1/mypackage/JavaStoredProc: resolution
oracle.aurora.server.tools.loadjava.ToolsException: Failures occurred during processing
at oracle.aurora.server.tools.loadjava.LoadJava.process(LoadJava.java:863)
at oracle.jdeveloper.deploy.tools.OracleLoadjava.deploy(OracleLoadjava.java:116)
at oracle.jdeveloper.deploy.tools.OracleLoadjava.deploy(OracleLoadjava.java:46)
at oracle.jdevimpl.deploy.OracleDeployer.deploy(OracleDeployer.java:97)
at oracle.jdevimpl.deploy.StoredProcHandler.doDeploy(StoredProcHandler.java:474)
at oracle.jdevimpl.deploy.StoredProcHandler.doDeploy(StoredProcHandler.java:361)
at oracle.jdevimpl.deploy.StoredProcHandler.doDeploy(StoredProcHandler.java:285)
at oracle.jdevimpl.deploy.StoredProcProfileDt$Action$1.run(StoredProcProfileDt.java:383)
#### Deployment incomplete. #### Oct 27, 2005 1:38:56 PM
Appreciate your help on this..I am using Jdeveloper 10.1.3 Early Access Version. JDK comes with it. I also have another JDK on my machine (JDK1.4.2_09)
-
Error while executing a stored procedure from forms6i
When I execute a STORED PROCEDURE from ORACLE DB 10g this procedure works perfectly fine.
But when I execute the same from the FORMs 6i I get the following error:
PDE-PLU022 Don't have access to the stored program unit
XMLPARSERCOVER in schema CARE.
where XMLPARSERCOVER is the class and
CARE is the schema.
Regards,
Jignesh SI have tried this with both the owner of the schema and the intended user, -from both forms and directly.
All rights was granted on the stored procedure. Since posting I have found that one of the tables that the procedure might insert into, was not explicitly granted to the intended user, and after rectifying that the error message went away.
-however, the procedure now silently "finishes" without any evidence that it ever ran, if invoked from the forms application. When invoked from SQL Plus (or JDev, or Toad) it runs as expected.
I have no public synonym for the procedure, -is that necessary?
The stored procedure in question is implemented in java, and published as a stored procedure. It does rather heavy lifting, when running, using a view against another server , updating local tables and quite a lot of data validation/cleansing, and logging. All recourses are within the same schema.
Any ideas? -
Error while calling a stored procedure using SQLJ
I am calling a stored procedure defined inside a package through a SQLJ script. The first parameter of that procedure is a IN OUT parameter which is used as a ROWID for creating a cursor. That ROWID value is the same for every record in the table, thereby enabling us to create a cursor.
When I give a hard-coded value as a parameter, I get an error stating that the assignment is not correct as the query is expecting a variable and not a literal. Hence I removed the hard-coded value and included a dymanic value in the SQLJ call.
String strVal = "A";
#sql{CALL ASSIGNMENTS_PKG.INSERT_ROW :{strVal},'SALARY_CODE_GROUP','BU',3,105,sysdate,1,sysdate,1,1)};
Here "ASSIGNMENTS_PKG" is a package name and INSERT_ROW is the procedure.
When the SQLJ program is run, I get an error stating:
"PLS-00201: identifier 'A' must be declared"
I read the error message, but I am not able to understand where I need to give the GRANT permission to.If you're using Oracle Provider for OLE DB (OraOLEDB) to execute this stored procedure, you need to set PLSQLRSet attribute. This attribute can be set in registry, connection string, or command object. Please refer to User Documentation for more information.
-
ORA-03111 - JCA Binding error while invoking a stored procedure in DB
Hi,
We are facing this problem for one interface alone.
Need expert advice to fix this problem..
This is scheduled to run once in a day and fails daily for past 2 weeks..
We receive below error as response..
Same interface worked fine for past 1 yr..
Also it works fine if we reprocess the batch in next day morning...
Exception occured when binding was invoked. Exception occured during invocation of JCA binding: "JCA Binding execute of Reference operation 'DB_Legacy_To_EBS_Invoice_Conversion' failed due to: Stored procedure invocation error. Error while trying to prepare and execute the IRSOA.AR_SOA_INVOICE.TRN_GET_CUST_INV_RAW_TO_STAGE API. An error occurred while preparing and executing the IRSOA.AR_SOA_INVOICE.TRN_GET_CUST_INV_RAW_TO_STAGE API. Cause: java.sql.SQLException: ORA-03111: break received on communication channel ". The invoked JCA adapter raised a resource exception. Please examine the above error message carefully to determine a resolution.
AND
Exception occured when binding was invoked. Exception occured during invocation of JCA binding: "JCA Binding execute of Reference operation 'DB_Legacy_To_EBS_Invoice_Conversion' failed due to: Stored procedure invocation error. Error while trying to prepare and execute the IRSOA.AR_SOA_INVOICE.TRN_GET_CUST_INV_RAW_TO_STAGE API. An error occurred while preparing and executing the IRSOA.AR_SOA_INVOICE.TRN_GET_CUST_INV_RAW_TO_STAGE API. Cause: java.sql.SQLException: ORA-01013: user requested cancel of current operation ORA-06512: at "IRSOA.XXIR_AR_SOA_CUSTOMER_INVOICE", line 213 ORA-06512: at line 1 ". The invoked JCA adapter raised a resource exception. Please examine the above error message carefully to determine a resolution
Thanks,
SundaramLooks like the SQL might be taking a longer time to execute and might be timing out.
Please refer the following:
Re: ORA-01013: user requested cancel of current operation
http://www.dba-oracle.com/t_ora_01013_user_requested_cancel_of_current_operation.htm
Additionally, ORA-06512 indicates that there is a mismatch of the with the data length that is being processed. Refer http://www.techonthenet.com/oracle/errors/ora06512.php
Hope this helps.
Thanks,
Patrick -
I am getting ORA-01403: no data found error while calling a stored procedur
Hi, I have a stored procedure. When I execute it from Toad it is successfull.
But when I call that from my java function it gives me ORA-01403: no data found error -
My code is like this -
SELECT COUNT(*) INTO L_N_CNT FROM TLSI_SI_MAST WHERE UPPER(CUST_CD) =UPPER(R_V_CUST_CD) AND
UPPER(ACCT_CD)=UPPER(R_V_ACCT_CD) AND UPPER(CNSGE_CD)=UPPER(R_V_CNSGE_CD) AND
UPPER(FINALDEST_CD)=UPPER(R_V_FINALDEST_CD) AND UPPER(TPT_TYPE)=UPPER(R_V_TPT_TYPE);
IF L_N_CNT >0 THEN
DBMS_OUTPUT.PUT_LINE('ERROR -DUPlicate SI-1');
SP_SEL_ERR_MSG(5,R_V_ERROR_MSG);
RETURN;
ELSE
DBMS_OUTPUT.PUT_LINE('BEFORE-INSERT');
INSERT INTO TLSI_SI_MAST
( CUST_CD, ACCT_CD, CNSGE_CD, FINALDEST_CD, TPT_TYPE,
ACCT_NM, CUST_NM,CNSGE_NM, CNSGE_ADDR1, CNSGE_ADDR2,CNSGE_ADDR3,
CNSGE_ADDR4, CNSGE_ATTN, EFFECTIVE_DT, MAINT_DT,
POD_CD, DELVY_PL_CD, TRANSSHIP,PARTSHIPMT, FREIGHT,
PREPAID_BY, COLLECT_BY, BL_REMARK1, BL_REMARK2,
MCC_IND, NOMINATION, NOTIFY_P1_NM,NOTIFY_P1_ATTN , NOTIFY_P1_ADDR1,
NOTIFY_P1_ADDR2, NOTIFY_P1_ADDR3, NOTIFY_P1_ADDR4,NOTIFY_P2_NM,NOTIFY_P2_ATTN ,
NOTIFY_P2_ADDR1,NOTIFY_P2_ADDR2, NOTIFY_P2_ADDR3, NOTIFY_P2_ADDR4,
NOTIFY_P3_NM,NOTIFY_P3_ATTN , NOTIFY_P3_ADDR1,NOTIFY_P3_ADDR2, NOTIFY_P3_ADDR3,
NOTIFY_P3_ADDR4,CREATION_DT, ACCT_ATTN, SCC_IND, CREAT_BY, MAINT_BY
VALUES( R_V_CUST_CD,R_V_ACCT_CD,R_V_CNSGE_CD,R_V_FINALDEST_CD,R_V_TPT_TYPE,
R_V_ACCT_NM,R_V_CUST_NM ,R_V_CNSGE_NM, R_V_CNSGE_ADDR1,R_V_CNSGE_ADDR2, R_V_CNSGE_ADDR3,
R_V_CNSGE_ADDR4,R_V_CNSGE_ATTN, R_V_EFFECTIVE_DT ,SYSDATE, R_V_POD_CD,R_V_DELVY_PL_CD,R_V_TRANSSHIP ,R_V_PARTSHIPMT , R_V_FREIGHT,
R_V_PREPAID_BY ,R_V_COLLECT_BY ,R_V_BL_REMARK1 ,R_V_BL_REMARK2,R_V_MCC_IND,
R_V_NOMINATION,R_V_NOTIFY_P1_NM, R_V_NOTIFY_P1_ATTN, R_V_NOTIFY_P1_ADD1, R_V_NOTIFY_P1_ADD2,
R_V_NOTIFY_P1_ADD3, R_V_NOTIFY_P1_ADD4, R_V_NOTIFY_P2_NM, R_V_NOTIFY_P2_ATTN, R_V_NOTIFY_P2_ADD1,
R_V_NOTIFY_P2_ADD2, R_V_NOTIFY_P2_ADD3, R_V_NOTIFY_P2_ADD4, R_V_NOTIFY_P3_NM, R_V_NOTIFY_P3_ATTN,
R_V_NOTIFY_P3_ADD1, R_V_NOTIFY_P3_ADD2, R_V_NOTIFY_P3_ADD3, R_V_NOTIFY_P3_ADD4,
SYSDATE,R_V_ACCT_ATTN,R_V_SCC_IND,R_V_USER_ID,R_V_USER_ID
DBMS_OUTPUT.PUT_LINE(' SI - REC -INSERTED');
END IF;Hi,
I think there is a part of the stored procedure you did not displayed in your post. I think your issue is probably due to a parsed value from java. For example when calling a procedure from java and the data type from java is different than expected by the procedure the ORA-01403 could be encountered. Can you please show the exact construction of the call of the procedure from within java and also how the procedure possible is provided with an input parameter.
Regards, Gerwin
Maybe you are looking for
-
Well at point of sale I was told my speed is approx 63 even tho the person I spoke to today said there noway I can go faster because I was quoted that speed. I received 74mb from day one but after some bad weather my electric went out around 3-4 time
-
How to make the translated fields active
Hello i needed to translate some fieds in me21n. i click on F1- technical information- then double clikc on the object name and then i go to translation menu from the top. The text is displayed as translated but when you open the me21n the field is i
-
Error while install DB instance using SAPinst
Hi, I have the following error while installing High Availability Database instance with option system copy-> restore from offline backup. We are at env. Window server 2003, MS SQL serevr 2005 SP 3. Can anybody help? thanks. ERROR 2009-02-11 14:45:4
-
I keep getting kernel panics, is it the airport?
Here's my log: Tue Nov 18 10:58:20 2008 panic(cpu 1 caller 0x001A8CEC): Kernel trap at 0x008ce953, type 0=divide error, registers: CR0: 0x8001003b, CR2: 0xb031c00c, CR3: 0x00fa0000, CR4: 0x00000660 EAX: 0x000000df, EBX: 0x00000010, ECX: 0x00000000, E
-
Redirection Issue on logon/logonServlet
Hi Experts, We've a WD Java application on which we've put an authentication. So, when we try to access the application we get http://hostname:Port/logon/logonServlet page. When we try to access the WD Java application Url, we get the above login pag