Procedure/Function Help
How do I test a Procedure/Function in SQL Plus? I tried using the execute statement but it gave me errors.
Can you post the particular errors you're getting?
Justin
Distributed Database Consulting, Inc.
http://www.ddbcinc.com/askDDBC
Similar Messages
-
Help!How can I find the name of a calling procedure from within a procedure/function?
Is there anyway to find out the name of calling procedure(database) from within a database stored procedure/function? This is required for creating an auditing module.
Thanks,
Abraham
===========
email:[email protected]You can use this query to get the procedure names that are calling your procedure.
SELECT name FROM all_Dependencies
WHERE upper(referenced_name) = 'YOUR_PROC_NAME'
In your procedure, you can get these values into a cursor and then use them one by one.
Hope this would help.
Faheem -
Help with Oracle packaged procedures/functions in JDBC
Up to this point I've pretty much used vanilla SQL calls for Oracle (with the JDBC thin driver).
However, I just received a PL/SQL script (that I didn't write) which I need to execute in a Java application (and get a result set). So I started looking at the Callable object. However, I'm having problems:
I'm trying to execute the following, piece by piece:
exec pay_balance_pkg.set_context('TAX_UNIT_ID','143') ;
select /*+ ORDERED */
ppf.employee_number,
ppf.full_name,
pdb.balance_name,
ppa.effective_date,
pay_balance_pkg.get_value(pdb.defined_balance_id, paa.assignment_action_id) amount
from
lots more SQL
Using a Callable statement, I can run the pay_balance_pkg.set_context('TAX_UNIT_ID','143') as "{call pay_balance_pkg.set_context(?,?)}" and set up the input parameters. It runs.
But the pay_balance_pkg.get_value(pdb.defined_balance_id, paa.assignment_action_id) attempt generates errors because of the implicit parameters (pdb.defined_balance_id, paa.assignment_action_id). I was assuming the previous call set up the "context" for these parameters. But it doesn't seem to in JDBC.
What's the solution for this?
Is there a way to just "run" the .sql file via JDBC or JDeveloper? Or do I literally have to parse out the PL/SQL and SQL from the file?Thanks for the reply.
It turned out that within that "large chunk of SQL", there was a package call that wasn't returning the expected results... which mucked up the rest of the SQL call.
Apparently it was a permissions issue in that the package didn't like to be called from JDBC; but would work fine out of SQL*Plus. Have you heard of this?
I ended up just throwing the first package call into an an anonymous PL/SQL block, and then doing the SQL call... both in SQLJ. Only because the app is throw-away. Otherwise I agree: it would have been better in a stored procedure/function. -
Parameter index move while executing PL/SQL stored procedure/function
Hello, community.
Have a question for you. It looked like very easy to write some small JDBC-wrapper to handle stored procedure/functions call for Oracle.
Here is the code snippet of it:
import java.io.Serializable;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Iterator;
import javax.sql.DataSource;
import oracle.jdbc.driver.OracleTypes;
import org.apache.log4j.Logger;
public class SmallHelper {
public static final int CALL_TYPE__PROCEDURE = 1;
public static final int CALL_TYPE__FUNCTION = 2;
public static final int PARAMETER__IN = 1;
public static final int PARAMETER__OUT = 2;
private static final Logger log = Logger.getLogger(SmallHelper.class);
private Connection con = null;
private CallableStatement statement = null;
private String name;
private int type;
private int resultType;
private HashMap arguments = new HashMap();
* Creates connection using data source as parameter.
* @param ds - data source
* @throws EhlApplicationException
public SmallHelper(DataSource ds) throws Exception {
try {
con = ds.getConnection();
catch (SQLException e) {
ExceptionHelper.process(e);
public void registerProcedure(String name) {
this.name = name;
this.type = CALL_TYPE__PROCEDURE;
public void registerFunction(String name, int resultType) {
this.name = name;
this.resultType = resultType;
this.type = CALL_TYPE__FUNCTION;
* NB! When You're dealing with stored function index should start with number 2!
public void registerArgument(int index, Object value, int type, int inOutType) {
arguments.put(new Long(index), new CallableStatementArgument(value, type, inOutType));
private String getSQL() {
StringBuffer str = new StringBuffer("{ call ");
if ( type == CALL_TYPE__FUNCTION )
str.append(" ? := ");
str.append(name).append("( ");
for ( Iterator i = arguments.values().iterator(); i.hasNext(); ) {
i.next();
str.append("?");
if ( i.hasNext() )
str.append(", ");
str.append(") }");
return str.toString();
public void execute() throws SQLException{
String query = getSQL();
statement = con.prepareCall(query);
if ( type == CALL_TYPE__FUNCTION )
statement.registerOutParameter(1, resultType);
for ( Iterator i = arguments.keySet().iterator(); i.hasNext(); ) {
Long index = (Long) i.next();
CallableStatementArgument argument = (CallableStatementArgument) arguments.get(index);
int type = argument.getType();
if ( argument.getInOutType() == PARAMETER__OUT )
statement.registerOutParameter(index.intValue(), type);
else if ( type != OracleTypes.CURSOR )
statement.setObject(index.intValue(), argument.getValue(), type);
log.info("Executing SQL: "+query);
statement.execute();
public CallableStatement getStatement() {
return statement;
public void close() throws EhlApplicationException {
try {
if (statement != null)
statement.close();
if (con != null)
con.close();
catch (SQLException e) {
EhlSqlExceptionHelper.process(e);
private class CallableStatementArgument implements Serializable{
private Object value;
private int type;
private int inOutType;
public CallableStatementArgument(Object value, int type, int inOutType) {
this.value = value;
this.type = type;
this.inOutType = inOutType;
public int getType() {
return type;
public Object getValue() {
return value;
public int getInOutType() {
return inOutType;
}It was really done in 10-15 mins, so don't be very angry at code quality :)
Here is the problem.:
helper.registerProcedure("pkg_diagnosis.search_diagnosis");
helper.registerArgument(1, null, OracleTypes.CURSOR, EhlJdbcCallableStatementHelper.PARAMETER__OUT);
helper.registerArgument(2, pattern, OracleTypes.VARCHAR, EhlJdbcCallableStatementHelper.PARAMETER__IN);
helper.registerArgument(3, lang, OracleTypes.VARCHAR, EhlJdbcCallableStatementHelper.PARAMETER__IN);
helper.registerArgument(4, EhlSqlUtil.convertSetToString(langs, ","), OracleTypes.VARCHAR, EhlJdbcCallableStatementHelper.PARAMETER__IN);
helper.registerArgument(5, EhlSqlUtil.convertSetToString(diagnosisClass, ","), OracleTypes.VARCHAR, EhlJdbcCallableStatementHelper.PARAMETER__IN);
helper.registerArgument(6, parentId, OracleTypes.NUMBER, EhlJdbcCallableStatementHelper.PARAMETER__IN);
helper.execute();
ResultSet rs = ((OracleCallableStatement) helper.getStatement()).getCursor(1);
procedure definition:
procedure search_diagnosis (l_res OUT dyna_cur,
in_search_string IN VARCHAR2,
in_search_lang IN VARCHAR2,
in_lang_list IN VARCHAR2,
in_diag_class_list IN VARCHAR2,
in_parent_id IN NUMBER) Procedure call has inner check that fail because of som strange reason:
in_search_string has 2 as index, that is correct. but procedure recieves is as number 3 in parameter list (what is in_search_lang). Other parameters are moved to. It seems like a cursor takes 2 places in definition. It's clear that if I put in_search_string as 1 parameter and cursor as 0 I'll get invalid parametr bindong(s) exception. So... any ideas why 2nd parameter is actually 3rd?
Thanks beforehand.hmm...moreover:
if we change procedure to function and call it in a simple way:
CallableStatement stmnt = helper.getConnection().prepareCall("begin ? := pkg_diagnosis.search_diagnosis(?,?,?,?,?); end;");
stmnt.registerOutParameter(1, OracleTypes.CURSOR);
stmnt.setString(2, pattern);
stmnt.setString(3, lang);
stmnt.setString(4, langs);
stmnt.setString(5, diagnosisClass);
stmnt.setObject(6, parentId, OracleTypes.NUMBER);
stmnt.execute();
ResultSet rs = (ResultSet) stmnt.getObject(1);the exception is:
[BEA][Oracle JDBC Driver][Oracle]ORA-06550: line 1, column 14:
PLS-00382: expression is of wrong type
ORA-06550: line 1, column 7:
PL/SQL: Statement ignoredif we return some string or number - it works. but when we want cursor back - it fails.
cursor is defined like ordinary dynamic cursor:
TYPE dyna_cur IS REF CURSOR; -
Hi All
I am trying to create a stored procedure that will return a line from a table.
The basic brief I have is that we have a bunch of tables that set up the user security and they link back to a our_systems table which holds info about all internal systems.
I need a stored procedure which can be called with a username and a system id. If the user has rights to the system then the line from the our_system table will be returned along with a rights level.
The hard part is I want to stop the users from seeing all the tables in this section. The original idea is to denie access to the tables but allow access to a stored procedure. Would this work?
The second point is how can I get this working? I am used to MS SQL Server and this would easily be done by creating the procedure and then doing
SELECT * FROM spCheckRights('dave',1)
But Oracle (9i is the version I am using) says that a function / procedure can't be placed there.
I have 2 version of my procedure
FUNCTION spCheckRights (login_name In varchar2, drxsystem_id In number)
return sys_refcursor
AS
l_cursor sys_refcursor;
BEGIN
open l_cursor for SELECT ds.NAME FROM drx_systems ds WHERE ds.system_id = 1;
return l_cursor;
END;
OR
FUNCTION spCheckRights (login_name In varchar2, drxsystem_id In number)
return drx_systems%ROWTYPE
AS
drxsys drx_systems%ROWTYPE;
BEGIN
SELECT * INTO drxsys FROM drx_systems ds WHERE ds.system_id = 1;
return drxsys;
END;
As you can see neither do all the check rights stuff yet, I wanted to test the basics first. Any views on which method is better for returning a row?
Any help would be appreciated
Thanks in advance
Dave RAs long as the owner of the function has rights to the tables, the users calling the function do not need to have any rights on the table, only execute on the function.
The choice of using a procedure or a function (in Oracle they differ) and whether to return a cursor, a collection type or a record type really depends on your front-end requirements, and the number of values you want to return.
A function can only return a single value. That value can be a cursor or a collection of some kind (think array), or it can be a scalar variable. A procedure can return, through out parameters, multiple values. This set of types that can be returned is the same as for a function.
So, for a function returning a cursor, you would do something analagous to:
curvar ResultSet;
curvar = f(p1, p2);in the language appropriate way. For testing in sqlplus, that would be something like:
VAR curvar SYS_REFCURSOR;
exec :curvar := f(p1, p2);
print curvar;Note, the colon in front of curvar in the exec is required. As long as your calling code can define a variable of drx_systems%ROWTYPE to recieve it, then the second version should work similarly.
If you will only be returning values from a single row, and if the number of coumns is relatively small, you could also consider a procedure something like:
PROCEDURE spcheckrights (p_login_name IN VARCHAR2,
p_drxsystem_id IN NUMBER,
p_name OUT VARCHAR2,
p_allowed OUT VARCHAR2) AS
BEGIN
SELECT ds.name, ds.allowed
INTO p_name, p_allowed
FROM drx_systems
WHERE system_id = 1;
END;Then call it passing in variable to get the results. Again, in sqlplus that would look something like:
VAR name VARCHAR2(30);
VAR allowed VARCHAR2(1);
exec p(p1, p2, :name, :allowed);
print name, allowed;Again, in sqlplus, the colons before name and allowed in the exec call are required.
HTH
John -
Enhanced Approval Procedure Functions- authorization issue
Dear Expert,
I have activated the enhances approval procedure function as per below screen shot:
Granted authorization as mention in New ChaRM Feature with SP 10: Enhanced Approval Procedure Functions by Michael. With SM_APP_AP with 02, 22 and 75.
But the Request for change procedure selection and approval steps was disabled
The requestor able to change the approval procedure and approval steps only if i granted the user with 70 (administer).
Please help as i want the requestor to be able to select the approval procedure and approval steps but not approving the CR. Im following the chart below but seem like is not working.
Role
SAP standard roles
Activity for
Change Manager
SAP_CM_SMAN_CHANGE_MANAGER
37 (approve) approval step, 75 (delete approval step), 22 (add approval step), 02 (change approval procedure assignment)
Potential Approvers
SAP_CM_SMAN_DEVELOPER
SAP_CM_SMAN_OPERATOR
SAP_CM_SMAN_TESTER
37 (delivered inactive)
Power User, Administrator
SAP_CM_SMAN_ADMINISTRATOR
70 (administer), 37 (approve) approval step, 75 (delete approval step), 22 (add approval step), 02 (change approval procedure assignment)
Thanks
Regards,
JunnieHi Jansi,
I have added activity 22 (add approval step) and 02 (change approval procedure assignment) but the approval procesure and approval step are disabled and not allow the requestor to select /add/ male changes.
So im not sure which part is going wrong.
Thanks
Regards,
Junnie -
Have been using SQL Server since 1998, and been wondering why MS cant better the GUI , in terms of ease of use, as its done in Visual Studio and other such tools, though there are some enhancements like multiple window etc, would expect few more for easy
working for developers.
1) A search text box, in the SSMS interface, for searching stored procedures, functions, tables etc would be very useful, instead of expanding the entire tree and going through a long list to find your procedure or table, especially when you have a large
list of them.
2) Also a code search tool, like to find a keyword in the entire stored procedures, triggers and functions would be useful, currently we had to generate whole script and then find the keyword, and this is cumbersome, as you have to move back and forth to
find which stored procedure or function has that keyword etc.
Thanks.1. You already have feature in SQL management studio to search for objects using full names or patterns through object explorer
See
http://visakhm.blogspot.in/2013/02/object-filtering-using-ssms-object.html
2. For this you can use the catalog view sys.sql_modules and fire a query on it
see
http://visakhm.blogspot.in/2012/03/advantages-of-using-syssqlmodules-view.html
http://visakhm.blogspot.in/2013/01/systemsqlmodules-and-allsql-modules.html
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs -
Calling a stored workspace procedure/function in page template
I have an unusual puzzle. I am trying to find a way to call a stored procedure or function in a page template; ie, through HTML/javascript.
I maintain a website with several dozen applications and I currently have the page templates in all of these applications subscribed to one master template, so that changes can be made in one place and implemented across all the applications. So far, the only content I can display on every page in every application through page template subscription is static content; dynamic content (ie content generated based on data in the database) is implemented page-by-page (or application-by-application).
I'm wondering if there is a way to call stored procedures/functions from the page template to create dynamic content (based on the :APP_USER identity, for example). htmldb_Get() doesn't seem to be helpful, because as far as I can tell it only calls on-demand application processes, not workspace procedures/functions.
Is there any way at all that a workspace procedure/function can be called directly from the page template (eg with a javascript function of some kind)? Again, I am trying to avoid having to use any application/page-level apex entities (items, processes, etc) so that I can just put the javascript or whatever in the page template and refresh all the applications in my workspace.
Thanks in advance!
Jonathan Cole
PS - I am currently using v3.1Just to add the owner in output :
SCOTT@demo102> ed
Wrote file afiedt.buf
1 select owner, table_name, ltrim(max(sys_connect_by_path(column_name,','))
2 keep (dense_rank last order by position),',') as PKcolumns
3 from
4 (select a.owner, a.table_name, b.column_name, b.position
5 from all_tables a, all_cons_columns b, all_constraints c
6 where a.owner=b.owner
7 and a.table_name=b.table_name
8 and b.owner=c.owner
9 and b.constraint_name=c.constraint_name
10 and c.constraint_type='P'
11 and a.table_name in ('SDO_COORD_AXES','EMP'))
12 group by owner, table_name
13 connect by prior owner = owner and prior table_name = table_name and prior position = position - 1
14* start with position = 1
SCOTT@demo102> /
OWNER TABLE_NAME PKCOLUMNS
MDSYS SDO_COORD_AXES COORD_SYS_ID,ORDER
SCOTT EMP EMPNO
SCOTT@demo102> Nicolas. -
Searching strings in procedures, function and packages (OWB)
Hi all,
I'm working on an OMB script to look for a string in procedures, function and packages in OWB. So far, I found how to do it for functions and procedures:
string match -nocase \*text_to_find* [OMBRETRIEVE FUNCTION 'my_function' GET PROPERTIES(IMPLEMENTATION)]
string match -nocase \*text_to_find* [OMBRETRIEVE PROCEDURE 'my_procedure' GET PROPERTIES(IMPLEMENTATION)]
I have tried something similar for packages but it didn't work. Does someone know how to do this search in packages? Any help will be appreciated.
Regards,
MauricioOf course, if you are looking for a match in any source - including procedures and packages not imported into OWB, then OMB+ isn't going to be a ton of help as it won't be aware of those other packages.
In that case, you can always find those dependencies by doing a standard select owner, name, type, text from all_source where text like '%YOUR_SEARCH_CRITERIA%' query.
and you can embed that in your OMB+ using the Java/SQL library: How to run SQL from OMB+
Cheers,
Mike -
Read access to procedures,function,packages and triggers
Hi,
I created a user with CREATE SESSION,SELECT ANY TABLE privilege. My objective is to create a user with read only access to other schemas. But the newly created user is not able to read procedures,function,packages and triggers. The new user need read access to procedures,function,packages and triggers. What is the priviege required for this access? Please help me to resolve this issue.
Regards,
Mat.Hi,
Grant select all will give select privileges to all schema level objects except procedures,function,packages and triggers. But I need to grant read privileges on these objects to newly created user.
Regards,
Mat. -
Procedure Function to dequeue a message and return cursor
Hi Guys,
We are looking for ways to dequeue a message from an oracle queue and pass it to the java code.
Namely we would like to create a procedure/function to dequeue a message which can be called by the java code for further processing.
So far we have the following working example, but it uses DBMS_OUTPUT.PUT_LINE to display values. But the target is to pass it to java...
Our DB - 11gR2
CODE:
create or replace
PROCEDURE PRC_DEQUEUE_EVENT_1
AS
dequeue_options DBMS_AQ.dequeue_options_t;
message_properties DBMS_AQ.message_properties_t;
message_handle RAW(16);
message our_message_type;
BEGIN
dequeue_options.navigation := DBMS_AQ.FIRST_MESSAGE;
DBMS_AQ.DEQUEUE(
queue_name => 'ORDERS_Q',
dequeue_options => dequeue_options,
message_properties => message_properties,
payload => message,
msgid => message_handle);
DBMS_OUTPUT.PUT_LINE('STATUS: '|| MESSAGE.CORDYS_STATUS);
DBMS_OUTPUT.PUT_LINE('CUSTOMERNUMBER: '|| MESSAGE.CUSTOMERNUMBER);
DBMS_OUTPUT.PUT_LINE('EINDDATUM: '|| MESSAGE.EINDDATUM);
DBMS_OUTPUT.PUT_LINE('ERRORCODE: '|| MESSAGE.ERRORCODE);
DBMS_OUTPUT.PUT_LINE('EXTRA1: '|| MESSAGE.EXTRA1);
DBMS_OUTPUT.PUT_LINE('EXTRA2: '|| MESSAGE.EXTRA2);
DBMS_OUTPUT.PUT_LINE('EXTRA3: '|| MESSAGE.EXTRA3);
DBMS_OUTPUT.PUT_LINE('EXTRA4: '|| MESSAGE.EXTRA4);
DBMS_OUTPUT.PUT_LINE('EXTRA5: '|| MESSAGE.EXTRA5);
END;
In a result we get the following on the screen:
STATUS: ORDER_COMPLETE
CUSTOMERNUMBER:
EINDDATUM: 20-DEC-11 12:00:00
ERRORCODE:
EXTRA1:
EXTRA2:
EXTRA3:
EXTRA4:
EXTRA5:
Question is how to sent result into a variable/cursor... whatever which might be read by the java code.
Any help would be much appreciated.
Thanks!
eMarcel
Edited by: eMarcel on Jan 16, 2012 3:56 PMThanks:)
-
How to find Unused variables in procedure,function or package
Hi all,
I want find out unused variables in procedure, function and package.
I have written below script for doing this ,but i am not getting the expected result.
Kindly help me to improve the below code ,so that it works as expected.
{code}
version details
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
PL/SQL Release 11.2.0.3.0 - Production
"CORE 11.2.0.3.0 Production"
TNS for Linux: Version 11.2.0.3.0 - Production
NLSRTL Version 11.2.0.3.0 - Production
{code}
{code}
What i Have tried is This.
DECLARE
V_OBJECT_NAME VARCHAR2(30) :='PR_PRINT';
V_OBJECT_TYPE VARCHAR2(30) :='PROCEDURE';
CURSOR C1(CP_OBJECT_NAME VARCHAR2,CP_OBJECT_TYPE VARCHAR2)
IS
SELECT US.NAME,
US.TYPE,
US.LINE,
REGEXP_SUBSTR(US.TEXT,'.* ') AS var_name
FROM user_source US
WHERE name=CP_OBJECT_NAME
AND type =CP_OBJECT_TYPE
AND REGEXP_LIKE (TEXT,'(v_|g_|c_)','i')
AND REGEXP_LIKE (TEXT,'^[^ ]')
AND REGEXP_LIKE (TEXT,'^[^--]') ;
v_count NUMBER ;
BEGIN
FOR i IN C1(V_OBJECT_NAME,V_OBJECT_TYPE)
LOOP
SELECT COUNT( *)
INTO V_COUNT
FROM USER_SOURCE US
WHERE US.NAME=I.NAME
AND REGEXP_LIKE(US.TEXT,i.var_name,'i' )
AND US.LINE<>I.LINE;
IF V_COUNT =0 THEN
DBMS_OUTPUT.PUT_LINE('variable '||I.VAR_NAME||'Is declared at line#'||I.LINE||' But no where used');
END IF ;
END LOOP;
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('p_err_code := '||SQLCODE||dbms_utility.format_Error_backtrace());
DBMS_OUTPUT.PUT_LINE('p_err_msg := '||sqlerrm);
END ;
{code}
Thanks,
P PrakashHello,
as suggested by padders you can use PL/Scope, an example:
ALTER SESSION SET PLSCOPE_SETTINGS='IDENTIFIERS:ALL';
CREATE OR REPLACE PACKAGE ui_test1 AS
global_number NUMBER := 9;
FUNCTION get_number
RETURN NUMBER;
END ui_test1;
CREATE OR REPLACE PACKAGE BODY ui_test1 AS
PROCEDURE setNull
p_varchar IN OUT VARCHAR2
IS
BEGIN
p_varchar := NVL(p_varchar,'NULL');
END setNull;
FUNCTION get_number
RETURN NUMBER
IS
FUNCTION setZero
p_number IN NUMBER
RETURN NUMBER
IS
BEGIN
RETURN NVL(p_number,0);
END setZero;
BEGIN
RETURN global_number;
END get_number;
END ui_test1;
SELECT DISTINCT
object_name
,object_type
,name
,type
,line
,col
FROM all_identifiers obj
WHERE obj.owner = USER
AND obj.usage = 'DECLARATION'
AND obj.object_name = 'UI_TEST1'
AND NOT EXISTS (
SELECT 1
FROM all_identifiers with_rh
WHERE obj.signature = with_rh.signature
AND with_rh.usage IN ('REFERENCE','CALL','ASSIGNMENT')
ORDER BY TYPE
,object_name
,object_type
,name;
OBJECT_NAME OBJECT_TYPE NAME TYPE LINE COL
UI_TEST1 PACKAGE GET_NUMBER FUNCTION 11 10
UI_TEST1 PACKAGE BODY SETZERO FUNCTION 35 14
UI_TEST1 PACKAGE UI_TEST1 PACKAGE 1 9
UI_TEST1 PACKAGE BODY SETNULL PROCEDURE 12 11
Regards
Marcus -
How to hide Procedures,Functions,Packages source code?
Hi,
I tried to find a way to hide all our application oracle
database's all Procedures, Functions, Packages PL/SQL Source
code. But I haven't find the way. Could Oracle do this? ( MS SQL
Server can)
Thanks in advance,
Cheng
nullcheng (guest) wrote:
: Hi,
: I tried to find a way to hide all our application oracle
: database's all Procedures, Functions, Packages PL/SQL Source
: code. But I haven't find the way. Could Oracle do this? ( MS
SQL
: Server can)
: Thanks in advance,
: Cheng
Hi Cheng,
You may be interested in what Quintessence Systems (Berkshire,
United Kingdom - http://www.quintessence.demon.co.uk) have
developed.
Addressed at precisely this kind of problem area, we've
developed a technology called F2J (Formula to Java). F2J
automatically converts stored PL/SQL (Procedures, Functions and
Packages) to Java classes which can be loaded and run as Stored
Procedures in an Oracle8i database.
If you think this may be able to assist you then check out the
website for further info or email me directly.
How this is helpful.
Elton Barendse
null -
ORA-04044: procedure, function, package, or type is not allowed here
Hi,
I am trying to build an object hierarchy.The object hirarcy is for a multi division, multi department, multi cost center and multi operation Organisation.Multiple department can store into multiple divisions, multiple cost center can store into multiple departments, multiple operations can store into multiple cost centers.
The structure I try to built like this:
create type div_obj_new as object
(id number,
divdesc varchar2(100)
create type div_obj_tab as
table of div_obj_new
create type dept_obj_new as object
(id number,
deptdesc varchar2(100),
dept_div number
create type dept_obj_tab as
table of dept_obj_new
create type cctr_obj_new as object
(id number,
cctrdesc varchar2(100),
cctr_dept number
create type cctr_obj_tab as
table of cctr_obj_new
create type oper_obj_new as object
(id number,
operdesc varchar2(100),
oper_cctr number
create type oper_obj_tab as
table of oper_obj_new
==========================
create type div_obj_type as object
(divid div_obj_tab)
NOT FINAL
create type dept_obj_type under div_obj_type
(deptid dept_obj_tab)
NOT FINAL
create type cctr_obj_type under dept_obj_type
(cctrid cctr_obj_tab)
NOT FINAL
create type oper_obj_type under cctr_obj_type
(operid oper_obj_tab)
NOT FINAL
=======This Table creation is not working=================
create table organisation
(div div_obj_type,
dept dept_obj_type,
cctr cctr_obj_type,
oper oper_obj_type)
nested table div store as division_table
nested table dept store as department_table
nested table cctr store as costcntr_table
nested table oper store as operation_table
nested table oper store as operation_table
ERROR at line 9:
ORA-22912: specified column or attribute is not a nested table type
=========================================================
Then I try to insert record into the div_obj_type instead of organisation table as it was not working.
The insert script is as follows:
===================================
insert into div_obj_type values
div_obj_tab
(div_obj_new(01,'Division 01'),
div_obj_new(02,'Division 02'),
div_obj_new(03,'Division 03'),
div_obj_new(04,'Division 04')
dept_obj_tab
dept_obj_new(10,'Department 10',1),
dept_obj_new(11,'Department 11',1),
dept_obj_new(12,'Department 12',2),
dept_obj_new(13,'Department 13',3),
dept_obj_new(14,'Department 14',4),
dept_obj_new(15,'Department 15',5),
dept_obj_new(16,'Department 16',6),
dept_obj_new(17,'Department 17',7)
cctr_obj_tab
cctr_obj_new(100,'Cost Center 100',10),
cctr_obj_new(101,'Cost Center 101',11),
cctr_obj_new(100,'Cost Center 102',12),
cctr_obj_new(100,'Cost Center 103',13),
cctr_obj_new(100,'Cost Center 104',14),
cctr_obj_new(100,'Cost Center 105',15),
cctr_obj_new(100,'Cost Center 106',16),
cctr_obj_new(100,'Cost Center 107',17),
cctr_obj_new(100,'Cost Center 108',10),
cctr_obj_new(100,'Cost Center 109',11),
cctr_obj_new(100,'Cost Center 110',12)
oper_obj_tab
oper_obj_new(1000,'Operation 1000',100),
oper_obj_new(1000,'Operation 1001',101),
oper_obj_new(1000,'Operation 1002',102),
oper_obj_new(1000,'Operation 1003',103),
oper_obj_new(1000,'Operation 1004',104),
oper_obj_new(1000,'Operation 1005',105),
oper_obj_new(1000,'Operation 1006',106),
oper_obj_new(1000,'Operation 1007',107),
oper_obj_new(1000,'Operation 1008',108),
oper_obj_new(1000,'Operation 1009',109),
oper_obj_new(1000,'Operation 1010',110),
oper_obj_new(1000,'Operation 1011',101),
oper_obj_new(1000,'Operation 1012',102),
oper_obj_new(1000,'Operation 1013',103),
oper_obj_new(1000,'Operation 1014',104),
oper_obj_new(1000,'Operation 1015',105),
oper_obj_new(1000,'Operation 1016',106),
oper_obj_new(1000,'Operation 1017',107),
oper_obj_new(1000,'Operation 1018',108)
insert into div_obj_type values
ERROR at line 1:
ORA-04044: procedure, function, package, or type is not allowed here
Actually I want to create an object view or object table with all the details of division, department , cost center and operation and it will store depending upon the respective upper level hirarcy 's id.For eg. department details can be fetched through division id etc..
So I can't figure out what to do for this kind of structure and how to do that.
I am running Oracle Release 2 (9.2.0.1.0) for Windows 2000.
Any help , advice or suggestions will be appreciated.
Thanks & Regards
NiharHi Cameron,
Thanks for your great suggestion.Actually what you have suggested is correct and it was tested by me correctly.But actually I want to store records in the multiple objects hirarcy depending upon the respective upper level hirarcy 's id.For say how can I retrive all records related to divisionID which is in the top level hirarchy? So by selecting divisionID=01, how can I easily select all depts,cost centers and Operation details?
Again I have another problem , when try to retrive record using PL/SQL I got some problem.
Structure as created above.Again I am giving here.
create type div_obj_new as object
(id number,
divdesc varchar2(100)
create type div_obj_tab as
table of div_obj_new
create type dept_obj_new as object
(id number,
deptdesc varchar2(100),
dept_div number
create type dept_obj_tab as
table of dept_obj_new
create type cctr_obj_new as object
(id number,
cctrdesc varchar2(100),
cctr_dept number
create type cctr_obj_tab as
table of cctr_obj_new
create type oper_obj_new as object
(id number,
operdesc varchar2(100),
oper_cctr number
create type oper_obj_tab as
table of oper_obj_new
create table organisation
(div div_obj_tab,
dept dept_obj_tab,
cctr cctr_obj_tab,
oper oper_obj_tab)
nested table div store as division_table
nested table dept store as department_table
nested table cctr store as costcntr_table
nested table oper store as operation_table
insert into organisation values
div_obj_tab
(div_obj_new(01,'Division 01'),
div_obj_new(02,'Division 02'),
div_obj_new(03,'Division 03'),
div_obj_new(04,'Division 04')
dept_obj_tab
dept_obj_new(10,'Department 10',1),
dept_obj_new(11,'Department 11',1),
dept_obj_new(12,'Department 12',2),
dept_obj_new(13,'Department 13',3),
dept_obj_new(14,'Department 14',4),
dept_obj_new(15,'Department 15',5),
dept_obj_new(16,'Department 16',6),
dept_obj_new(17,'Department 17',7)
cctr_obj_tab
cctr_obj_new(100,'Cost Center 100',10),
cctr_obj_new(101,'Cost Center 101',11),
cctr_obj_new(100,'Cost Center 102',12),
cctr_obj_new(100,'Cost Center 103',13),
cctr_obj_new(100,'Cost Center 104',14),
cctr_obj_new(100,'Cost Center 105',15),
cctr_obj_new(100,'Cost Center 106',16),
cctr_obj_new(100,'Cost Center 107',17),
cctr_obj_new(100,'Cost Center 108',10),
cctr_obj_new(100,'Cost Center 109',11),
cctr_obj_new(100,'Cost Center 110',12)
oper_obj_tab
oper_obj_new(1000,'Operation 1000',100),
oper_obj_new(1000,'Operation 1001',101),
oper_obj_new(1000,'Operation 1002',102),
oper_obj_new(1000,'Operation 1003',103),
oper_obj_new(1000,'Operation 1004',104),
oper_obj_new(1000,'Operation 1005',105),
oper_obj_new(1000,'Operation 1006',106),
oper_obj_new(1000,'Operation 1007',107),
oper_obj_new(1000,'Operation 1008',108),
oper_obj_new(1000,'Operation 1009',109),
oper_obj_new(1000,'Operation 1010',110),
oper_obj_new(1000,'Operation 1011',101),
oper_obj_new(1000,'Operation 1012',102),
oper_obj_new(1000,'Operation 1013',103),
oper_obj_new(1000,'Operation 1014',104),
oper_obj_new(1000,'Operation 1015',105),
oper_obj_new(1000,'Operation 1016',106),
oper_obj_new(1000,'Operation 1017',107),
oper_obj_new(1000,'Operation 1018',108)
===============
declare
div number;
divdesc varchar2(100);
divdetails varchar2(100);
dept number;
deptdesc varchar2(100);
deptdetails varchar2(100);
cctr number;
cctrdesc varchar2(100);
cctrdetails varchar2(100);
oper number;
operdesc varchar2(100);
operdetails varchar2(100);
cursor c_div is
select d.id , d.divdesc from table(select div from organisation) d
where d.id=1;
--union
cursor c_dept is
select dp.id , dp.deptdesc "Dept Details" from table(select dept from organisation) dp
where dp.dept_div=1;
--union
cursor c_cctr is
select cc.id , cc.cctrdesc "Cctr Details" from table(select cctr from organisation ) cc
where cc.cctr_dept=10;
--union
cursor c_oper is
select op.id , op.operdesc "Oper Details" from table(select oper from organisation) op
where op.oper_cctr=100;
TYPE oper_type IS RECORD
(oper_no NUMBER,
oper_desc VARCHAR(50));
TYPE cctr_type IS RECORD
(cctr_no NUMBER,
cctr_desc VARCHAR(50),
oper_detl oper_type);
TYPE dept_type IS RECORD
(dept_no NUMBER,
dept_desc VARCHAR(50),
cctr_detl cctr_type);
TYPE div_type IS RECORD
(div_no NUMBER,
div_desc VARCHAR2(50),
dept_detl dept_type);
division_rec div_type;
begin
for i_div in c_div%rowcount
loop
exit when c_div%notfound;
division_rec.div_no:=i_div.id;
division_rec.div_desc:=i_div.divdesc;
dbms_output.put_line('Division details = ' || division_rec.div_no || division_rec.div_desc);
--end loop;
for i_dept in c_dept%rowcount
loop
exit when c_dept%notfound;
select dp.id , dp.deptdesc ,
into
division_rec.dept_detl.dept_no, division_rec.dept_detl.dept_desc
from
table(select dept from organisation) dp
where dp.dept_div=division_rec.div_no;
-- division_rec.dept_detl.dept_no:=c_dept.id;
-- division_rec.dept_detl.dept_desc:=c_dept.deptdesc;
dbms_output.put_line('Department details = ' || division_rec.dept_detl.dept_no ||
division_rec.dept_detl.dept_desc);
--end loop;
for i_cctr in c_cctr
loop
exit when c_cctr%notfound;
select cc.id , cc.cctrdesc
into
division_rec.dept_detl.cctr_detl.cctr_no ,
division_rec.dept==_detl.cctr_detl.cctr_desc
from
table(select cctr from organisation ) cc
where cc.cctr_dept=division_rec.dept_detl.dept_no;
-- division_rec.dept_detl.cctr_detl.cctr_no:=c_cctr.id;
-- division_rec.dept_detl.cctr_detl.cctr_desc:=c_cctr.cctrdesc;
dbms_output.put_line('Cost Center details = ' || division_rec.dept_detl.cctr_detl.cctr_no ||
division_rec.dept_detl.cctr_detl.cctr_desc);
--end loop;
for i_oper in c_oper%rowcount
loop
exit when c_oper%notfound;
select op.id , op.operdesc
into
division_rec.dept_detl.cctr_detl.oper_detl.oper_no,
division_rec.dept_detl.cctr_detl.oper_detal.oper_desc
from
table(select oper from organisation) op
where op.oper_cctr=division_rec.dept_detl.cctr_detl.cctr_no;
-- division_rec.dept_detl.cctr_detl.oper_detl.oper_no:=c_oper.id;
-- division_rec.dept_detl.cctr_detl.oper_detal.oper_desc:=c_oper.operdesc;
dbms_output.put_line('Operation details = ' ||
division_rec.dept_detl.cctr_detl.oper_detl.oper_no ||
division_rec.dept_detl.cctr_detl.oper_detal.oper_desc);
end loop;
end loop;
end loop;
end loop;
end;
for i_div in c_div%rowcount
ERROR at line 46:
ORA-06550: line 46, column 14:
PLS-00999: implementation restriction (may be temporary)
ORA-06550: line 46, column 1:
PL/SQL: Statement ignored
New version of PL/SQL bloc
==============================
declare
div number;
divdesc varchar2(100);
divdetails varchar2(100);
dept number;
deptdesc varchar2(100);
deptdetails varchar2(100);
cctr number;
cctrdesc varchar2(100);
cctrdetails varchar2(100);
oper number;
operdesc varchar2(100);
operdetails varchar2(100);
cnt_div number;
cnt_dept number;
cnt_cctr number;
cnt_oper number;
cursor c_div is
select d.id , d.divdesc from table(select div from organisation) d
where d.id=1;
--union
cursor c_dept is
select dp.id , dp.deptdesc from table(select dept from organisation) dp
where dp.dept_div=1;
--union
cursor c_cctr is
select cc.id , cc.cctrdesc from table(select cctr from organisation ) cc
where cc.cctr_dept=10;
--union
cursor c_oper is
select op.id , op.operdesc from table(select oper from organisation) op
where op.oper_cctr=100;
TYPE oper_type IS RECORD
(oper_no NUMBER,
oper_desc VARCHAR(50));
TYPE cctr_type IS RECORD
(cctr_no NUMBER,
cctr_desc VARCHAR(50),
oper_detl oper_type);
TYPE dept_type IS RECORD
(dept_no NUMBER,
dept_desc VARCHAR(50),
cctr_detl cctr_type);
TYPE div_type IS RECORD
(div_no NUMBER,
div_desc VARCHAR2(50),
dept_detl dept_type);
division_rec div_type;
begin
/*select count(*) into cnt_div from table(select div from organisation) d
where d.id=1;*/
for i_div in c_div
loop
exit when c_div%notfound;
division_rec.div_no:=i_div.id;
division_rec.div_desc:=i_div.divdesc;
dbms_output.put_line('Division details = ' || division_rec.div_no || division_rec.div_desc);
--end loop;
/*select count(*) into cnt_dept from table(select dept from organisation) dp
where dp.dept_div=i_div.id;*/
for i_dept in c_dept
loop
exit when c_dept%notfound;
select dp.id , dp.deptdesc
into
division_rec.dept_detl.dept_no, division_rec.dept_detl.dept_desc
from
table(select dept from organisation) dp
where dp.dept_div=division_rec.div_no;
-- division_rec.dept_detl.dept_no:=c_dept.id;
-- division_rec.dept_detl.dept_desc:=c_dept.deptdesc;
dbms_output.put_line('Department details = ' || division_rec.dept_detl.dept_no || division_rec.dept_detl.dept_desc);
--end loop;
/*select count(*) into cnt_cctr from table(select cctr from organisation ) cc
where cc.cctr_dept=division_rec.dept_detl.dept_no;*/
for i_cctr in c_cctr
loop
exit when c_cctr%notfound;
select cc.id , cc.cctrdesc
into
division_rec.dept_detl.cctr_detl.cctr_no , division_rec.dept_detl.cctr_detl.cctr_desc
from
table(select cctr from organisation ) cc
where cc.cctr_dept=division_rec.dept_detl.dept_no;
-- division_rec.dept_detl.cctr_detl.cctr_no:=c_cctr.id;
-- division_rec.dept_detl.cctr_detl.cctr_desc:=c_cctr.cctrdesc;
dbms_output.put_line('Cost Center details = ' || division_rec.dept_detl.cctr_detl.cctr_no || division_rec.dept_detl.cctr_detl.cctr_desc);
--end loop;
/*select count(*) into c_oper from table(select oper from organisation) op
where op.oper_cctr=division_rec.dept_detl.cctr_detl.cctr_no;*/
for i_oper in c_oper
loop
exit when c_oper%notfound;
select op.id , op.operdesc
into
division_rec.dept_detl.cctr_detl.oper_detl.oper_no, division_rec.dept_detl.cctr_detl.oper_detl.oper_desc
from
table(select oper from organisation) op
where op.oper_cctr=division_rec.dept_detl.cctr_detl.cctr_no;
-- division_rec.dept_detl.cctr_detl.oper_detl.oper_no:=c_oper.id;
-- division_rec.dept_detl.cctr_detl.oper_detl.oper_desc:=c_oper.operdesc;
dbms_output.put_line('Operation details = ' || division_rec.dept_detl.cctr_detl.oper_detl.oper_no || division_rec.dept_detl.cctr_detl.oper_detl.oper_desc);
end loop;
end loop;
end loop;
end loop;
end;
declare
ERROR at line 1:
ORA-01422: exact fetch returns more than requested number of rows
ORA-06512: at line 64
I hope you might have the solutions.
Thanks & Regards
Nihar -
Exp/imp procedures, functions and packages question
Hi
I've a 9i R2 version Oracle database. I would like to export procedures, functions and packages from a schema. How do I do that?
Is there any script or command lines can provide?
ThanksHello user12259190.
You can do an export of the user itself, excluding table data as inH:\>exp
Export: Release 10.2.0.1.0 - Production on Tue Dec 22 11:22:52 2009
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Username: db_user@db_sid
Password:
Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
With the Partitioning, Data Mining and Real Application Testing options
Enter array fetch buffer size: 4096 >
Export file: EXPDAT.DMP >
(2)U(sers), or (3)T(ables): (2)U > 2
Export grants (yes/no): yes > no
Export table data (yes/no): yes > no
Compress extents (yes/no): yes > no
Export done in WE8MSWIN1252 character set and AL16UTF16 NCHAR character set
server uses UTF8 character set (possible charset conversion)
Note: table data (rows) will not be exported
Note: grants on tables/views/sequences/roles will not be exported
. exporting pre-schema procedural objects and actions
. exporting foreign function library names for user DB_USER
. exporting PUBLIC type synonyms
. exporting private type synonyms
. exporting object type definitions for user DB_USER
About to export DB_USER's objects ...
. exporting database links
. exporting sequence numbers
. exporting cluster definitions
. about to export DB_USER's tables via Conventional Path ...
. . exporting table TABLE_NAMEs
EXP-00091: Exporting questionable statistics.
. exporting synonyms
. exporting views
. exporting stored procedures
. exporting operators
. exporting referential integrity constraints
. exporting triggers
. exporting indextypes
. exporting bitmap, functional and extensible indexes
. exporting posttables actions
. exporting materialized views
. exporting snapshot logs
. exporting job queues
. exporting refresh groups and children
. exporting dimensions
. exporting post-schema procedural objects and actions
. exporting statistics
Export terminated successfully with warnings.Unfortunately, you can't export just the objects you want to unless they are tables.
Using import (imp) you can list the content of your packages, procedures, functions, views, etc. and perhaps that will give you what you need.
Another choice would be to useSELECT * FROM user_source ORDER BY 2, 1, 3;to list the code.
Hope this helps,
Luke
Maybe you are looking for
-
How to Submit a Concurrent program from OAF page Button?
Hi, I have tried this but its not submitting the request String shipId = pageContext.getParameter("shipId"); OADBTransaction tr = am.getOADBTransaction(); Connection conn = tr.getJdbcConnection(); OracleCallableStatement ocs = null; String stmt = new
-
HT5100 How do I create an iTunes U account for my institution?
This is admittedly a rather dumb question, but I am in academic administration for a postgraduate institution and I am interested in utilizing iTunes U to house some of our content. I'd like to create an account, not simply as a course manager (done
-
Premier Elements 10 not offered for dowload
When I try to download trial version of PE 10, I get Download Assistant but it only offfers PCE 5. I have tried several times but it never cannot get PE 10
-
How to create or use app_AppMenuMultiOpenBottom for button in apex page
Hi all can anybody help to use app_AppMenuMultiOpenBottom2 function used in the apex on edit page on create or utilities buttons i want to implement same pull down menu like it . thanxs
-
My Computers hinges are breaking!!​! Please Help.
So I purchased my Hp Envy m6 approximately 2 years ago, and have taken great care of it. In spite of this, both of my hinges are beginning to break, causing the left and right bottom corners to bend, warp, and slowly start breaking also. I am aware t