Using array with a stored procedure
Hello,
In order to transmit an array from java to a PL/SQL procedure with oracle8i, we have been trying to instanciate an javaArrayDescriptor using the name of an oracle user Datatype (a table of Varchar(20)).
This works perfectly well while connected to the database as the owner of the datatype (user 1),
but doesn't when connected with another user (user 2) even if a public synonym is created.
As it seemed that synonym for objects do not work properly, we tried to put the datatype as part of a public package.
This works when the procedure is called from SQL worksheet (connected with user 2) but doesn't when it is called from our java application (still connected with user 2).
We also created the same datatype for user 2. However the procedure (created by user 1) did not accept the new datatype (error: wrong type or number of arguments) as it requires the user 1 datatype.
Is there a way to allow any user to use a datatype?
Or to access a datatype defined in a package fom java in order to make an ArrayDescriptor?
You should create the TYPE AddrType in Oracle (say thru Sql*Plus) using CREATE TYPE.. command. Currently, looks like you have the TYPE declared within a package.
Similar Messages
-
Passing array to oracle stored procedure in VC++ 2005
Hi,
I am try to send an array of integers to a stored procedure via ODBC 10.2.0.3 on VC++2005 enviornment. I get the below error
ORA-06550: line 1, column 7:
PLS-00306: wrong number or types of arguments in call to 'MYPROC1'
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored ... Error Code = 6550
[]E R R O R
The same code works if I use an INSERT statement.
SQLUSMALLINT* rowsProcessed = new SQLUSMALLINT;
RETCODE nRetCode;
const int arraySize = 200;
long ptrVal[arraySize];
long ptrInd[arraySize];
long ptrStatus[arraySize];
for (int i = 0; i < arraySize; i++)
ptrVal = i;
ptrInd = 0;
nRetCode = SQLSetStmtAttr(m_hstmt, SQL_ATTR_PARAM_BIND_TYPE, SQL_PARAM_BIND_BY_COLUMN, 0);
// assign the number of sets of parameters that are to be inserted
nRetCode = SQLSetStmtAttr(m_hstmt, SQL_ATTR_PARAMSET_SIZE, (SQLPOINTER)iSizeOfArray, 0);
// assign an array to retrieve status info for each row of parameter values
nRetCode =SQLSetStmtAttr(m_hstmt, SQL_ATTR_PARAM_STATUS_PTR, (SQLPOINTER)ptrStatus, 0);
// assign a buffer to store the number of sets of parameters that have been processed
nRetCode = SQLSetStmtAttr(m_hstmt, SQL_ATTR_PARAMS_PROCESSED_PTR, (SQLPOINTER)rowsProcessed, 0);
nRetCode = SQLBindParameter(m_hstmt, nParamIndex, nDirection, SQL_C_LONG, SQL_INTEGER, 0, 0, ptrVal, 0, ptrInd);
//suceeds
SQLPrepare(m_hstmt, (SQLCHAR*)"INSERT INTO my_table VALUES (?)", SQL_NTS);
//fails
SQLPrepare(m_hstmt, (SQLCHAR*)"{CALL mypackage.myproc1(?)}", SQL_NTS);
SQLExecute(m_hstmt);
package is
create or replace package mypackage
as
type mytable is table of binary_integer;
procedure myproc1( l_tab in mytable);
end;
show errors
create or replace package body mypackage
as
procedure myproc1( l_tab in mytable)
as
begin
insert into my_table values (100);
commit;
FORALL i IN l_tab.first .. l_tab.last
INSERT into my_table values( l_tab(i) );
end;
end;
any ideas?I believe when you're doing it with an insert, you're saying "execute this insert statement a bunch of times, here's all the values in advance", which is different than passing an array to a stored procedure where you want it to execute once.
Oracle's ODBC driver doesnt support Associative Arrays (aka index-by tables).
Hope it helps,
Greg -
Passing arrays to Oracle Stored procedure.
Have any body passed arrays to Oracle stored procedures while the app is running in Weblogic app server. I am able to pass the arrays with regular JDBC connection. If I run the same piece of code using a connection recieved from the datasource of weblogic server, its not working. I am getting serialization errors with the ArrayDescriptor class. Looks like the ArrayDescriptor is not serializable.
Does anybody know solution/workaround to pass arrays ?
Thanks in advanceyou could write a wrapper class that extends ArrayDescriptor and implements serializable...
for example your class would look something like this.
public class MyArrayDescriptor extends ArrayDescriptor
implements Serializable
in your regular code use the wrapper class in place of the ArrayDescriptor (it will contain all the same methods as the real ArrayDescriptor) and you should be able to toss your wrapper class anywhere you please. -
Performance problem with java stored procedure
hi,
i developped a java class, then I stored it in Oracle 8.1.7.
This class contains several import of other classes stored in the database.
It works, but the execution perfomances are disappointing. It's very long. I guess, that's because of the great number of classes to load that are necessary for my class execution.
I tried to increase the size of the java pool (I parameter 70 Mo in the java_pool_size parameter of the init.ora), but the performance is not much better.
Has anyone an idea to increase the performance of this execution of my class ?
In particular, is there a way to keep permanently in memory the java objects used by my class ?
Thanks in advance
bye
[email protected]
nullbefore running Java, the database session needs to be Java enabled; this might be the reason why it is taking so long. If this is the case, you should see an improvement in subsequent calls, once a database session is Java enabled, other users can benefit from it.
Kuassi
I have some performance issue with java stored procedure. Hope some one will be able to help me out. I'm using java stored procedures in my application and basically these procedures are used to do some validation and form the XML message of the database tables. I have noticed that when I call the PL/SQL wrapper function, it is taking time to load the java class and once the class is loaded the execution is faster. Most of the time is spent for loading the class rather than executing the function. if I reduce the class load time, I can improve the performance drastically. Do any one of you know how to reduce the class load time. The following are the platform and oracle version.
O/S: IBM AIX
Oracle: 8.1.7 -
Conversion of java Array to oracle SQL Array while calling Stored Procedure
How java Array can be converted to oracle SQL array while calling Stored procedure with callable statement.
i.e java Array ---> Sql Array in Oracle while setting the datatypes to callable statement arguments.Look at:
http://forum.java.sun.com/thread.jsp?forum=48&thread=376735&tstart=0&trange=15
Paul -
Using VIEW inside a stored procedure
Hi,
So I have a View designed in one file that validates someone who is authorized.
Then I have a stored procedure to display authorized stationeries created before a given date. Its takes a parameter @CreatedOn.
How can I use VIEW in my stored procedure so I can display all the authorized which are set 1 before a given date?
My VIEW:
ALTER VIEW vw_AuthorizedStationeries AS
SELECT Authorized
FROM dbo.Stationeries
WHERE Authorized = 1
And my stored procedure:
CREATE PROCEDURE usp_stationeries (@CreatedOn datetime)ASBEGINSELECTFROMENDGO
Thanks!Try something like below, You need to replace CreatedDate column with appropriate date column in your table.
1. Alter the view to get the required date:
ALTER VIEW vw_AuthorizedStationeries AS
SELECT Authorized, CreatedDate
FROM dbo.Stationeries
WHERE Authorized = 1
2. Alter SP:
CREATE PROCEDURE usp_stationeries (@CreatedOn datetime)
AS
BEGIN
SELECT Authorized
FROM vw_AuthorizedStationeries
WHERE CreatedDate <= @CreatedOn
END
GO
OR
You can pull required information directly from your table:
CREATE PROCEDURE usp_stationeries (@CreatedOn datetime)
AS
BEGIN
SELECT Authorized
FROM dbo.Stationeries
WHERE CreatedDate <= @CreatedOn and Authorized = 1
END
GO
If this post answers your query, please click "Mark As Answer" or "Vote as Helpful". -
How to verify the user information pass by the form with a stored procedure?
Hi,
I would like to know how to verify user information pass by the form with a stored procedure.
I want make a portal which accepts to new user registration, but I want verify the new user's informations (like the name don't contain a number etc).
Thanks for your help
regards
jlaHi Samson,
You can use the UI API to do this. You can catch the form_ADD event and then validate the input from the users. You can even block the event from completing (and stop the document from being added) if your code finds some incorrect data using the bubbleEvent functionality.
I don't have one specific example to show you, but if you look at some of the SDK samples (for example C:\Program Files\SAP\SAP Business One SDK\Samples\COM UI\VB.NET\02.CatchingEvents) to see how to work with events, you can then create your own validation to ensure the users data is valid.
Regards,
Niall -
How do I merge data from table1 on server 1 to final table on server 2 with a stored procedure to execute every so many hours.
Hello,
If you had configure server2 as
linked server on the server1, you can run the following statement inside stored proceduce to copy table data. And then create a job to the run stored proceduce every 4 hours.
Insert Into Server2.Database2.dbo.Table2
(Cols)
Select Cols From Server1.Database1.dbo.Table1
Or you can use the SQL Server Import and Export Wizard to export the data from server1 to server2, save the SSIS package created by the wizard on the SQL Server, create a job to run the SSIS package.
Reference:http://technet.microsoft.com/en-us/library/ms141209.aspx
Regards,
Fanny Liu
Fanny Liu
TechNet Community Support -
Use database inside a stored procedure
Hi guys, a stupid question: I'm working with several database and sometimes I'm afraid to run an alter or a create something in the wrong database, bear in mind that several database have the same tables. Sometime happens to run a query oin the db A
instead in the db B. So, the question: If I create a procedure like this,
create procedure creatingPillar as
use USA
begin
IF EXISTS (SELECT * FROM sys.objects WHERE object_id =
OBJECT_ID(N'pillarretail') AND type in (N'U'))
DROP TABLE PillarRetail
create table PillarRetail (anid int , ancore varchar(20), period dec(18,6), settlem datetime2,
settlementper int, asf dec(18,6),astlf dec (18,6), tot dec (18,6) )
insert into PillarRetail select anid, ancore, Period, settlem, settlementper,
asf, astlf, tot from createsemipillar2011
insert into PillarRetail select select anid, ancore, Period, settlem, settlementper,
asf, astlf, tot createsemipillar
end
but I'm wondering if is useless to put the use USA in the stored procedure by the moment that I'm creating the procedure in USA. I mean, having the SP in the USA db even if I run the procedure from another db it should run in USA. Just a stupid question
I know but I got this doubt...
ThanksYou may try as below:
create proc as below: (This will create the proc in USA database.
use USA
Go
create procedure dbo.creatingPillar as
begin
IF EXISTS (SELECT * FROM sys.objects WHERE object_id =
OBJECT_ID(N'pillarretail') AND type in (N'U'))
DROP TABLE PillarRetail
create table PillarRetail (anid int , ancore varchar(20), period dec(18,6), settlem datetime2,
settlementper int, asf dec(18,6),astlf dec (18,6), tot dec (18,6) )
insert into PillarRetail select anid, ancore, Period, settlem, settlementper,
asf, astlf, tot from createsemipillar2011
insert into PillarRetail select select anid, ancore, Period, settlem, settlementper,
asf, astlf, tot createsemipillar
end
Then you can call as below:
Exec USA.dbo.creatingPillar -
How to pass an array to a stored procedure
create or replace package demo_pkg
as
type cityArray is table of city%rowtype index by binary_integer;
procedure city_report( p_inputs in cityArray );
end;
CREATE OR REPLACE PACKAGE BODY demo_pkg
AS
PROCEDURE city_report (p_inputs IN cityarray)
IS
BEGIN
FOR i IN 1 .. p_inputs.COUNT
LOOP
DBMS_OUTPUT.put_line ( 'citycode = '
|| p_inputs (i).city_code
|| ' CITYDESCRIPTION = '
|| p_inputs (i).city_description
INSERT INTO testing
(city_code, city_description
VALUES (p_inputs (i).city_code, p_inputs (i).city_description
commit;
END LOOP;
END;
END;
to call that procedure ia m using this
declare
my_data demo_pkg.cityArray;
begin
my_data(1).city_code := 1234;
my_data(1).CITY_DESCRIPTION := 10;
my_data(2).city_code := 4567;
my_data(2).CITY_DESCRIPTION := 20;
my_data(3).city_code := 4321;
my_data(3).CITY_DESCRIPTION := 30;
demo_pkg.city_report( my_data );
end;
but actually the procedure (demo_pkg.city_report)is called from front end(.net).how they will call this procedure in .net invironmentHi,
Your exact question has been asked before, see: http://asktom.oracle.com/pls/ask/search?p_string=How+to+pass+an+array+to+a+stored+procedure
or do a search on this forum.
And please use this tag => (yes, just the 4 characters forming the word 'code' between curly brackets)
*before* and *after* your example to maintain formatting and indentation, it's hard to read now.... -
What is the problem with this Stored Procedure
Hi ,
What is the problem with this Stored Procedure ?Why is it giving errors ??
CREATE or replace PROCEDURE getEmpName
*(EMP_FIRST OUT VARCHAR2(255))*
BEGIN
SELECT ename INTO EMP_FIRST
FROM Emp
WHERE EMPNO = 7369;
END ;
*/*You don't specify precision in procedure arguments.
(EMP_FIRST OUT VARCHAR2(255))should be
(EMP_FIRST OUT VARCHAR2)Since you asked what's wrong with it, I could add that it needs formatting and the inconsistent use of upper and lower case is not helping readability. -
Using Copy statement in Stored procedure
The following statement works in sqlplus session:
copy from comment/password@servername append amcomment_temp using
select * from amcomment
where commentid in(1,2,3,4)
I want to use this in a stored procedure. There is a long datatype in this table. The
procedure will not compile. Have tried execute immediate and compiler rejects this statement also.'COPY' is a SQL*Plus command, not PL/SQL. This is why the PL/SQL compiler throws it out.
-
Need Help With a Stored Procedure
Help With a Stored Procedure
Hi everyone.
I am quite new relative to creating stored procedures, so I anticipate that whatever help I could get here would be very much helpful.
Anyway, here is my case:
I have a table where I need to update some fields with values coming from other tables. The other tables, let us just name as tblRef1, tblRef2 and tblRef3. For clarity, let us name tblToUpdate as my table to update. tblToUpdate has the following fields.
PlanID
EmployeeIndicator
UpdatedBy
CreatedBy
tblRef1, tblRef2 and tblRef3 has the following fields:
UserName
EmpIndicator
UserID
In my stored procedure, I need to perform the following:
1. Check each row in the tblToUpdate table. Get the CreatedBy value and compare the same to the UserName and UserID field of tblRef1. If no value exists in tblRef1, I then proceed to check if the value exists in the same fields in tblRef2 and tblRef3.
2. If the value is found, then I would update the EmployeeIndicator field in tblToUpdate with the value found on either tblRef1, tblRef2 or tblRef3.
I am having some trouble writing the stored procedure to accomplish this. So far, I have written is the following:
CREATE OR REPLACE PROCEDURE Proc_Upd IS v_rec NUMBER;
v_plan_no tblToUpdate.PLANID%TYPE;
v_ref_ind tblToUpdate.EMPLOYEEINDICATOR%TYPE;
v_update_user tblToUpdate.UPDATEDBY%TYPE;
v_created_by tblToUpdate.CREATEDBY%TYPE;
v_correct_ref_ind tblToUpdate.EMPLOYEEIDICATOR%TYPE;
CURSOR cur_plan IS SELECT PlanID, EmployeeIndicator, UPPER(UpdatedBy), UPPER(CreatedBy) FROM tblToUpdate;
BEGIN
Open cur_plan;
LOOP
FETCH cur_plan INTO v_plan_no, v_ref_ind, v_update_user, v_created_by;
EXIT WHEN cur_plan%NOTFOUND;
BEGIN
-- Check if v_created_by has value.
IF v_created_by IS NOT NULL THEN
-- Get the EmpIndicator from the tblRef1, tblRef2 or tblRef3 based on CreatedBy
SELECT UPPER(EmpIndicator)
INTO v_correct_ref_ind
FROM tblRef1
WHERE UPPER(USERNAME) = v_created_by
OR UPPER(USERID) = v_created_by;
IF v_correct_ref_ind IS NOT NULL THEN
-- Update the Reference Indicator Field in the table TRP_BUSPLAN_HDR_T.
UPDATE TRP_BUSPLAN_HDR_T SET ref_ind = v_correct_ref_ind WHERE plan_no = v_plan_no;
ELSIF
-- Check the Other tables here????
END IF;
ELSIF v_created_by IS NULL THEN
-- Get the EmpIndicator based on the UpdatedBy
SELECT UPPER(EmpIndicator)
INTO v_correct_ref_ind
FROM tblRef1
WHERE UPPER(USERNAME) = v_update_user
OR UPPER(USERID) = v_created_by;
IF v_correct_ref_ind IS NOT NULL THEN
-- Update the Reference Indicator Field in the table TRP_BUSPLAN_HDR_T.
UPDATE TRP_BUSPLAN_HDR_T SET ref_ind = v_correct_ref_ind WHERE plan_no = v_plan_no;
ELSIF
-- Check the Other tables here????
END IF;
END IF;
END;
END LOOP;
CLOSE cur_plan;
COMMIT;
END
Please take note that the values in the column tblToUpdate.UpdatedBy or tblToUpdate.CreatedBy could match either the UserName or the UserID of the table tblRef1, tblRef2, or tblRef3.
Kindly provide more insight. When I try to execute the procedure above, I get a DATA NOT FOUND ERROR.
Thanks.Ah, ok; I got the updates the wrong way round then.
BluShadow's single update sounds like what you need then.
I also suggest you read this AskTom link to help you see why you should choose to write DML statements before choosing to write cursor + loops.
In general, when you're being asked to update / insert / delete rows into a table or several tables, your first reaction should be: "Can I do this in SQL?" If you can, then putting it into a stored procedure is usually just a case of putting the sql statement inside the procedure header/footers - can't really get much more simple than that! *{;-) -
How to use order by in stored procedure base block?
How to use order by in stored procedure base block? I need to change order by dynamically
Use SET_BLOCK_PROPERTY('BLOCK_NAME',ORDER_BY,'COLUMN_NAME1, COLUMN_NAME2');
-
Using temporary tables in stored procedures
Suppose that I have created a temporary table in a stored procedure using an "EXECUTE IMMEDIATE" statement. When I compile the procedure, that table is not created yet, so the compiler says that the table does not exist.
What is the way of using temporary tables in stored procedures?It's a good practice to avoid using DDL statements being executed from stored procedures. "Truncate Table" via dynamic SQL from stored procedure is a different story and is useful in DSS environments.
But if you insist on "creating" tables using Dynamic SQL from Stored Procedures then you must also embed your DML statements in Dynamic SQL to avoid compilation errors.
Example:
Create or Replace Procedure Proc_TestDynamicSQL is
Begin
Execute Immediate 'Create table myTable as select * from user_tables' ;
Execute Immediate 'Update myTable set table_name = ''Test'' ' ; --two single quotes before and after the string "Test"
End;
In this case, Oracle wouldn't care about the table references during compilation.
Maybe you are looking for
-
How can I permit all traffic from inside-dmz-outside on asa5505
Scenario : Servers are in DMZ, Internal LAN Users should access ports Specified (5000 & 2048). Router 2801 is facing Leased line; from there it’s connected to firewall. Router LAN IP: 83.111.X.X - 255.255.255.X ASA Version 7.2(4) hostname ciscoasa do
-
When the Apple techs at their store setup my new MacBook Pro, my first Apple product they evidently acted as The Administrator. They did not tell me about this process or give me a password. So now when I need the password I have no idea what it is
-
Tables not showing in a new Database created using CREATE DATABASE command
Hi there! I've created a database using "Script Database As" in SSMS. Here's the code generated: USE [master] GO /****** Object: Database [PLMAINDB] Script Date: 08/22/2014 11:25:44 ******/ CREATE DATABASE [PLTESTDB] ON PRIMARY ( NAME = N'CLIEN
-
Needing to add keep pool to SGA, sizing and checking for room?
Hi all, I'm needing to experiment with pinning a table and index (recommended by COTS product vendor) to see if it helps performance. I'm trying to set up a keep pool...and put the objects in it I've gone into the database, and found that I will need
-
Novell login not available with remote desktop on windows 7
Installed Novell Client 2 SP3 for Windows Server 2012 on my terminal server. When I log in from Windows XP to that terminal server I am getting an option to login with Novell Client. On Windows 7 however I only can logon to the server. What am I miss