Adding Records Using Stored Procedure (or Cursor?)
Also, I would like to have a second example of a stored procedure that will add random rows to a table (that is, create duplicates of information already in the table).
For example,
IF p_value1 = 'FIRST_VALUE' then
add this record (incl. seq_no for key);
ELSIF p_value2 = 'SECOND_VALUE' then
add that record (incl. seq_no for key);
and on and on.
This procedure should also be able to handle random insertion up to several thousand rows. So, I know that I need to loop, say:
while v_ctr < 1000
or
for 1...999
Much thanks to anyone who can help.
Many thanks to anyone who can help.
<BLOCKQUOTE><font size="1" face="Verdana, Arial, Helvetica">quote:</font><HR>Originally posted by Colin Berrouard ([email protected]):
You should look in a PL/SQl book,
There are a lot of examples that can help you
<HR></BLOCKQUOTE>
I have already, but when trying to self-learn without not any familiarity with certain concepts and being at most a visual learner, I'm not getting this concept at this point...hence the reason why I asked.
Thanks.
Similar Messages
-
Insert record using stored procedure
Dear all,
I want to insert record using stored procedure in form6i,
any help or suggestion will be appreciated.
regards
Kashif AliKashif,
Could you please explain what you are trying to accomplish? Inserting records into a table from Forms is as simple as executing an INSERT statement in a Forms trigger or as complicated as overriding the Forms default INSERT functionality by defining your own On-Insert trigger. Your requirements will dictate where and how you do your INSERT.
Craig... -
Help: Using stored procedure to add new record in DB
I am using stored procedures for a form. In DB, I have select and update procedures work without problems. However, for the insert procedure, it does not seem work right. Here is how things work for the insert procedure:
1. On the form, I have an add record button, when this button is pressed, it calls the trigger "KEY_CREREC" with "create_record."
2. A blank record is then shown on form. I then put in some test date. Apparently, this will cause "SYSTEM.STATUS" set to "CHANGED." when calling for commit, it only calls the DB update procedure.
My question is how to make it call the insert procedure.
Any suggestions are greatly appreciated.I just added to lines in key_commit to check the system.form_status:
set_alert_property('AL_STOP', alert_message_text,'System Status: '||:system.form_status);
al_button := show_alert('AL_STOP');
After do_key('create_record') and some changes in fields, the :system.form_status shows "CHANGED.'
Just wondering what will make the auto generated insert_procedure for the block to trigger. So far, no problems to do query and update with the DB stored procedure, but the insert does not seem working.
Any help is greatly appreciated.
P.S. The new post might be more clear:
http://forums.oracle.com/forums/thread.jspa?threadID=675578&tstart=0
Message was edited by:
WJH -
Why Dynamic Parameter is not working, when i create report using stored procedure ?
Post Author: Shashi Kant
CA Forum: General
Hi all
Why Dynamic Parameter is not working, when i create report XI using stored procedure ?
Only i shaw those parameters which i used in my stored procedure, the parameter which i create dynamic using stored procedure
is not shown to me when i referesh the report for viewing the results.
I have used the same procedure which i mention below but can not seen the last screen which is shown in this .
============================================================================================
1. Select View > Field Explorer2. Right-click on Parameter Fields and select New from the right-click menu.3. Enter u201CCustomer Nameu201D as the name for your parameter4. Under u201CList of Valuesu201D select u201CDynamicu201D5. Under the Value column, click where is says u201Cclick here to add itemu201D and select Customer Name from the drop-down list. The dialog shown now look like the one shown below in Figure 1. Click OK to return to your report design.
Dynamic Parameter Setup6. Next, select Report > Select Expert, select the Customer Name field and click OK.7. Using the drop-down list beside select u201CIs Equal Tou201D and using the drop-down list, select your parameter field (it should be the first field). 8. Click OK to return to your report design and see the parameter dialog.The parameter dialog will appear and show you a dynamic list of values that is updated each time your run your report. It couldnu2019t be easier! In our next tutorial, we will be looking at how to use this feature to create cascading parameter fields, where the values are filtered by the preceding selection.
Dynamic Parameters in Action
My question is that whether dynamic parameter is working with storedprocedure or not.
When i added one table and try to fetch records using dyanmic prameters. after that i am not be able to find the dynamic parameter option when i referesh my report.
One more thing when i try the static parameter for my report, the option i see when i referesh the screen.
Please reply soon , it's urgent
Regards
shashi kantHi Kishore,
I have tested the issue step by step by following you description, while the first issue works well in my local environment. Based on my research, this can be caused by the lookup expression or it indeed return Male value based on the logic. If you use the
expression below, it will indeed only return the Male record. So please try to double-check the record in the two datasets and the expression in your environment:
=lookup(first(Fields!ProgramID.Value,"DataSet1"),Fields!ProgramID.Value,Fields!Gender.Value,"DataSet2")
As to the second issue, please try to use the following expression:
=Count(Lookup(fields!ProgramID.value,fields!ProgramID.value,fields!Gender.value,"DataSet2"))
Besides, if this issue still exist, in order to trouble shoot this issue more efficiently, could you please post both the .rdl file with all the size properties to us by the following E-mail address? It is benefit for us to do further analysis.
E-mail: [email protected]
Thanks,
Katherine Xiong
Katherine Xiong
TechNet Community Support -
Error while refreshing bqy file on workspace using stored procedure
Hi,
I am using stored procedure which returns ref-cursor. The report is running fine locally but on Workspace, while refresh, it gives the following error.
An Interactive Reporting Service error has occurred.-SQL API: [SQLNumResultCols], SQL RETURN: [-1], SQL STATE: [HY010], SQL NATIVE ERROR: [0], SQL MESSAGE: [[Microsoft][ODBC Driver Manager] Function sequence error]
(0)
I have ODBC/ODBC connection set up at BI+ configurator.
Thanks,
ManishWe also met this issue. Some guy told me this is a Hyperion limitation, is it true? I really need this function in Hyperion:(
-
Unable to run SSIS Package using Stored Procedure
Hi Guys,
I have create one simple SSIS Package(Move the first table record to second table).It will execute fine in locally.
But, If i'm going call/execute .dtsx file using stored procedure. I'm getting Error. so please let me know the valuable solution.
My Package Path : D:\Temp\SSIS_TESTING\TESTSSIS\TESTSSIS\Package.dtsx
Stored Procedure
================
CREATE PROCEDURE SPEXECUTESSISPACKAGE
@FILEPATH VARCHAR(8000)
,@STATUS VARCHAR(500) = NULL OUTPUT
AS
BEGIN
DECLARE @SQLQUERY VARCHAR(8000)
DECLARE @STATUSCODE INT
SET @SQLQUERY = 'DTEXEC /FILE "'+ @FILEPATH +'"'
SELECT @SQLQUERY AS 'SSIS FULL PATH'
EXEC @STATUSCODE = master..xp_cmdshell @SQLQUERY
SELECT @STATUSCODE AS 'STATUSCODE'
IF @STATUSCODE <> 0
BEGIN
SET @STATUS = 'PACAKGE EXECUTE FAILED'
PRINT @STATUS
END
ELSE
BEGIN
SET @STATUS = 'PACAKGE EXECUTE SUCCESS'
PRINT @STATUS
END
END
GO
RUN
============================================================================
EXEC SPEXECUTESSISPACKAGE 'D:\Temp\SSIS_TESTING\TESTSSIS\TESTSSIS\Package.dtsx', NULL
Error
=============================================================================
Microsoft (R) SQL Server Execute Package Utility
Version 9.00.4035.00 for 32-bit
Copyright (C) Microsoft Corp 1984-2005. All rights reserved.
NULL
Started: 5:06:26 AM
Error: 2014-11-14 05:06:26.07
Code: 0xC0011007
Source: {1244CD18-F96A-4DAD-8FC2-35F794015CA1}
Description: Unable to load the package as XML because of package does not have a valid XML format. A specific XML parser error will be posted.
End Error
Error: 2014-11-14 05:06:26.07
Code: 0xC0011002
Source: {1244CD18-F96A-4DAD-8FC2-35F794015CA1}
Description: Failed to open package file "D:\Temp\SSIS_TESTING\TESTSSIS\TESTSSIS\Package.dtsx" due to error 0x80070003 "The system cannot find the path specified.". This happens when loading a package and the file cannot
be opened or loaded correctly
into the XML document. This can be the result of either providing an incorrect file name was specified when calling LoadPackage or the XML file was specified and has an incorrect format.
End Error
Could not load package "D:\Temp\SSIS_TESTING\TESTSSIS\TESTSSIS\Package.dtsx" because of error 0xC0011002.
Description: Failed to open package file "D:\Temp\SSIS_TESTING\TESTSSIS\TESTSSIS\Package.dtsx" due to error 0x80070003 "The system cannot find the path specified.". This happens when loading a package and the file cannot be opened
or loaded correctly int
o the XML document. This can be the result of either providing an incorrect file name was specified when calling LoadPackage or the XML file was specified and has an incorrect format.
Source: {1244CD18-F96A-4DAD-8FC2-35F794015CA1}
Started: 5:06:26 AM
Finished: 5:06:26 AM
Elapsed: 0.047 seconds
NULL
I'm getting Execte SSIS Package Status : 4
===================================
4Two things to check
1. The account executing the package has access to the path. If package is stored in different server you need to pass the UNC path (ie like \\machinename\...)
2. Make sure the version of SSIS service is the same in both the servers ie where package is created/stored and where its getting executed. A lower version SSIS service will not be able to load and execute higher version package and it will throw you similar
error messages as you posted above.
Please Mark This As Answer if it solved your issue
Please Mark This As Helpful if it helps to solve your issue
Visakh
My MSDN Page
My Personal Blog
My Facebook Page -
Hi Guys,
SSIS 2012 ETL is failing only at one server (No BIDS) but running successfully from BIDS on different sever . In this ETL, I have used Stored Procedure in OLEDB Source.
Note: I have couple of ETLs developed in 2005 using same logic and upgraded to 2012, working perfectly.
I am getting Error Message:
SSIS
Error Code
DTS_E_OLEDBERROR.
An OLE DB
error has occurred.
Error code: 0x80004005.
An
OLE DB
record is available.
Source: "Microsoft OLE DB Provider for SQL Server"
Hresult: 0x80004005
Description: "Error converting data type varchar to datetime.".
Unable
to retrieve
column information
from the data
source. Make
sure your target
table in
the database is
available.
"OLE DB Source"
failed validation
and returned
validation status
"VS_ISBROKEN".
I tried below word around and found It is working perfectly.
I loaded data into a table (dbo.TEMP) using Stored procedure and then I used this dbo.TEMP table in OLEDB source and then found no issue.
MY SP Details: (This SP I am calling in OLEDB source of ETL) and when I run it from one server IT is working fine and when I run from ETL dedicated Server getting error: Guys Help me out.
USE
[TEST_DB]
GO
SET
ANSI_NULLS ON
GO
SET
QUOTED_IDENTIFIER ON
GO
ALTER
PROCEDURE [DBO].[SP_TEST]
--EXEC [DBO].[SP_TEST] '2014-09-30','2014-10-01'
@FROMDATETIME
DATETIME,
@TODATETIME
DATETIME
AS
SET
NOCOUNT ON
BEGIN
DECLARE
@FROMDATEKEY INT,
@TODATEKEY INT,
SET
@FROMDATEKEY=
CONVERT(VARCHAR(10),@FROMDATETIME,112)
SET
@TODATEKEY=
CONVERT(VARCHAR(10),@TODATETIME,112)
IF 1 = 1
BEGIN
SELECT
CAST(NULL
AS DATETIME)
AS TXN_DATE
, CAST(NULL
AS DATETIME
) AS PROCESS_DATE
, CAST(NULL
AS money)
AS S1_AMT
, CAST(NULL
AS money)
AS S2_AMOUNT
, CAST(NULL
AS money)
AS S2_INVALID_AMOUNT
, CAST(NULL
AS money)
AS INVALID_MOVED_IN_VALID_S2_AMOUNT
, CAST(NULL
AS VARCHAR(20))
AS SYSTEM_ID
, CAST(NULL
AS money)
AS S3_AMT
END
SELECT
TXN_DATE
,PROCESS_DATE
,S1_AMT
,S2_AMOUNT
,S2_INVALID_AMOUNT
,INVALID_MOVED_IN_VALID_S2_AMOUNT
,SYSTEM_ID
S3_AMT
FROM
DBO.TABLE_1
WHERE TNX_DATE_KEY
BETWEEN @FROMDATEKEY
and @TODATEKEY
UNION
ALL
SELECT
TXN_DATE
,PROCESS_DATE
,S1_AMT
,S2_AMOUNT
,S2_INVALID_AMOUNT
,INVALID_MOVED_IN_VALID_S2_AMOUNT
,SYSTEM_ID
S3_AMT
FROM
DBO.TABLE_2
WHERE TNX_DATE_KEY
BETWEEN @FROMDATEKEY
and @TODATEKEY
UNION
ALL
SELECT
TXN_DATE
,PROCESS_DATE
,S1_AMT
,S2_AMOUNT
,S2_INVALID_AMOUNT
,INVALID_MOVED_IN_VALID_S2_AMOUNT
,SYSTEM_ID
S3_AMT
FROM
DBO.TABLE_3
WHERE TNX_DATE_KEY
BETWEEN @FROMDATEKEY
and @TODATEKEY
END
Data Source Mode: SQL Command for Variable
"EXEC [DBO].[SP_TEST] '"+ (DT_WSTR, 24) @[User::V_EXTRACT_FROM_DT] +"','"+ (DT_WSTR, 24) @[User::V_EXTRACT_TO_DT] +"'"
Where variable @[User::V_EXTRACT_FROM_DT] and @[User::V_EXTRACT_TO_DT] is defined as DATETIME
Thanks Shiven:) If Answer is Helpful, Please VoteHi,
Yes you are right. At one sever where I was getting error, DateTime was in USA format and Where It was running successfully was in AUS format.
I changed from USA to AUS and I did another changes:
Data Source Mode: SQL
Command
EXEC [DBO].[SP_TEST]
@FROMDATETIME = ?,
@TODATETIME = ?
and It is working fine.
Thanks Shiven:) If Answer is Helpful, Please Vote -
Using Stored Procedures with TopLink / JPA : Success explanation
For those who have to use Stored Procedures in TopLink this is my success history :
To call an Stored Procedure from the persistence, we have to use the direct JDBC connection because my TopLink version ( Essentials 10g ) ? to date ( 10g ) does not have support for Stored Procedures.
Here is my code :
<address>{color:#0000ff} EntityManagerFactory JPAemfactory = null;{color}</address>
<address>{color:#0000ff} JPAemfactory = Persistence.createEntityManagerFactory ("MyPersistenceUnit"); // this is the name of the persistence unit wrote in the persistence.xml file{color}</address>
<address>{color:#0000ff} EntityManagerr MyEntityManager = JPAemfactory.createEntityManager ();{color}</address>
bq. <address>{color:#0000ff}// creation of the stored procedure calling string .... one question mark for every param, output included \\ String sql = "{call SP_GETLISTATARIFAS(?,?,?,?,?)}"; \\ // We get the JDBC connection \\ oracle.toplink.essentials.internal.ejb.cmp3.EntityManagerImpl entityManager = (oracle.toplink.essentials.internal.ejb.cmp3.EntityManagerImpl) MyEntityManager; \\ UnitOfWorkImpl uow = (UnitOfWorkImpl)entityManager.getUnitOfWork(); \\ // we create a request to the unitofwork because if dont the connection will not exist \\ uow.beginEarlyTransaction(); \\ Connection conexion = ((UnitOfWorkImpl)uow).getAccessor().getConnection(); \\ {color}{color:#0000ff} \\ try { \\ // Creation of the call and we will identify the params as they are in the stored procedure definitiondefinidos \\ CallableStatement call = conexion.prepareCall(sql); \\ {color}</address>
bq. <address>{color:#0000ff} \\ // params INPUT with their values \\ call.setString("pIDMCUPO", "125"); \\ call.setString("pCODIGOHOT", "8023"); \\ call.setString("pCODCANAL", "WEB"); \\ call.setString("pCODSUBCANAL", "HOTEL"); \\ {color}</address><address>{color:#0000ff} \\ // params OUTPUT \\ call.registerOutParameter("rRESULTADO", java.sql.Types.VARCHAR); \\ {color}</address><address>{color:#0000ff} \\ // execution \\ call.execute(); \\ {color}</address><address>{color:#0000ff} \\ // getting the response \\ mcontratos_out = call.getString("rRESULTADO"); \\ {color}</address><address>{color:#0000ff} \\ // closing the proc \\ call.close(); \\ {color}</address><address>{color:#0000ff} \\ } catch (SQLException ex) { {color}</address><address>{color:#0000ff} // something you do if there is an error \\ {color}</address><address>{color:#0000ff} \\ } {color}</address>
Hope this helps all the people that have searched a lot like me.......I have my entity manager setup in a singleton.
I'm finding it's costly to generate the emf, but if I don't close the em (enitity manager) and emf (entity manager factory) my open cursor count climbs until I exceed the max number of open cursors on the database (11g RAC)
I'm committing the connection, and uow, and closing the em at the end of each call.
But until I close the emf, the open cursors aren't released.
TransactionhistoryPkg tranPkg = new TransactionhistoryPkg(conn); //Class created over database package via JPublisher
tranPkg.transactionhistoryInsSp(insertTrans.getCardId()); // executes db package
tranPkg.closeConnection();
conn.commit();
uow.commit();
uow.getAccessor().decrementCallCount();
em.close();
Am I missing something really obvious here??
btw - I found this link helpful in troubleshooting the max cursors issue: https://support.bea.com/application_content/product_portlets/support_patterns/wls/InvestigatingORA-1000MaximumOpenCursorsExceededPattern.html -
Is BC4J a viabl option for database with stored procedure (ref cursor) API?
I'm about to begin a Web application development project. As foundation, we have a (Oracle) database of certain complexity that have a data access API developed with PL/SQL packages.
This API is designed to get data through stored procedures/functions that return REF CURSOR.
Personally I have been investigating about Oracle ADF/JSF, and a number of others J2EE technologies, and at this moment I am doubting if ADF BC are a viable option to my development team.
I think this because I have noticed that one of the great drawback in ADF BC is the lack of simplicity to get data through stored procedures/functions that returns REF CURSORS.
I have been looking for documentation and the only thing that I have found are two examples:
1.- One that really do not work (fails in get data from ref cursor): ADF BC StoredProcedure Sample application.
2.- And other published by Steve Muench in
http://radio.weblogs.com/0118231/stories/2003/03/03/gettingAViewObjectsResultRowsFromARefCursor.html. This sample works fine.
But, the problem with the approach of this last article is the amount (and complexity) of the code necessary to make so basic and recurrent operation as is "obtain data through a stored procedure (ref cursor)".
Below it is the code that I have constructed to call a function that returns a ref cursor (based on steve's article).
If this is the only way to make this (historically so basic and simple) task, then it is obvious that BC is not a viable technology to my (or I am in a mistake?), since we have about 50 stored procedures/functions to access the underlying data; that stored procedures/functions are key to development of the new application (and, still more, currently are used to anothers apps ).
By all this, I would like consult to Oracle's people:
1.- I really must reject BC as technology to implement this project ?
2.- It is possible to access stored procedures in a simpler way using BC?
3.- If the answer to 2 is NOT: in near future, the BC team has plans to give more support to the simple access to stored procedures?
4.- If the answer to 3 is NOT: what another technology you recommend to construct my data access/business tier and still be able to using the others characteristics of ADF?
Thank you very much for your guidelines.
Regards, RL.
** And the code!!!
** ### I am forced to do this for each call to a procedure???? ###
package myrefcursor.model;
import java.math.BigDecimal;
import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Types;
import oracle.jbo.JboException;
import oracle.jbo.domain.NullValue;
import oracle.jbo.domain.Number;
import oracle.jbo.server.DBTransaction;
import oracle.jbo.server.ViewObjectImpl;
import oracle.jbo.server.ViewRowImpl;
import oracle.jbo.server.ViewRowSetImpl;
import oracle.jdbc.driver.OracleCallableStatement;
import oracle.jdbc.driver.OracleTypes;
public class TraePolizasViewImpl extends ViewObjectImpl {
private static final String SQL = "begin ? := PKG_PRUEBA.trae_polizas(?);end;";
private static final String COUNTSQL = "begin ? := PKG_PRUEBA.count_trae_polizas(?);end;";
public TraePolizasViewImpl() {
protected void executeQueryForCollection(Object qc,Object[] params,int numUserParams) {
BigDecimal rut_contratante = null;
Object[] theUserParam = null;
System.out.println(params);
System.out.println(params[0]);
if (params != null)
theUserParam = (Object[]) params[0];
//if (theUserParam != null && theUserParam.length > 0 )
if (! (theUserParam[1] instanceof NullValue) )
rut_contratante = (BigDecimal)theUserParam[1];
storeNewResultSet(qc ,retrieveRefCursor(qc, rut_contratante));
super.executeQueryForCollection(qc, params, numUserParams);
protected void create() {
getViewDef().setQuery(null);
getViewDef().setSelectClause(null);
setQuery(null);
protected ViewRowImpl createRowFromResultSet(Object qc, ResultSet rs) {
rs = getResultSet(qc);
ViewRowImpl r = createNewRowForCollection(qc);
try {
populateAttributeForRow(r,0, nullOrNewNumber(rs.getBigDecimal(1)));
populateAttributeForRow(r,1, rs.getString(2));
catch (SQLException s) {
throw new JboException(s);
return r;
protected boolean hasNextForCollection(Object qc) {
ResultSet rs = getResultSet(qc);
boolean nextOne = false;
try {
nextOne = rs.next();
if (!nextOne) {
setFetchCompleteForCollection(qc, true);
rs.close();
catch (SQLException s) {
throw new JboException(s);
return nextOne;
protected void releaseUserDataForCollection(Object qc, Object rs) {
ResultSet userDataRS = getResultSet(qc);
if (userDataRS != null) {
try { userDataRS.close(); }
catch (SQLException s) { ; }
super.releaseUserDataForCollection(qc, rs);
public long getQueryHitCount(ViewRowSetImpl viewRowSet) {
return viewRowSet.getRowCount();
private ResultSet retrieveRefCursor(Object qc, BigDecimal rut_contratante) {
CallableStatement st = null;
try {
st = getDBTransaction().createCallableStatement(SQL, DBTransaction.DEFAULT);
st.registerOutParameter(1,OracleTypes.CURSOR);
if (rut_contratante == null)
st.setNull(2, Types.NUMERIC);
else
st.setBigDecimal(2, rut_contratante);
st.execute();
ResultSet rs = ((OracleCallableStatement)st).getCursor(1);
rs.setFetchSize(getFetchSize());
return rs ;
catch (SQLException s) {
throw new JboException(s);
finally {try {st.close();} catch (SQLException s) {;}}
private void storeNewResultSet(Object qc, ResultSet rs) {
ResultSet existingRs = getResultSet(qc);
if (existingRs != null) {
try {existingRs.close();} catch (SQLException s) {;}
setUserDataForCollection(qc,rs);
hasNextForCollection(qc); // Prime the pump with the first row.
private ResultSet getResultSet(Object qc) {
return (ResultSet)getUserDataForCollection(qc);
private static Number nullOrNewNumber(BigDecimal b) {
try {
return b != null ? new Number(b) : null;
catch (SQLException s) { ; }
return null;
public BigDecimal getprutcontratante() {
return (BigDecimal)getNamedWhereClauseParam("prutcontratante");
public void setprutcontratante(BigDecimal value) {
setNamedWhereClauseParam("prutcontratante", value);
}no?
-
IN Operator Parameter using stored procedure
Hi Guys,
I'm running a reporting services report using stored procedure and I'm facing a dilemma with the IN Operator in the stored procedure.
Can someone please help me out debugging the statement below? (run it on AdventureWorks Database)
Can I have the @Title Parameter based on another select statement something like this
Set @Title = SELECT Title FROM TableTitle
DECLARE @Title varchar(1000)
set @Title = 'Design Engineer', 'Tool Designer', 'Marketing Assistant'
SELECT FirstName, LastName, e.Title
FROM HumanResources.Employee AS e
JOIN Person.Contact AS c
ON e.ContactID = c.ContactID
WHERE e.Title IN (@Title)
Appreciate all the help on this.
Thank you
JohnHi John,
For your problem, we can use dynamical statement to solve the issue.
Here are 2 options to be clarified:
1. A multi-value parameter will return an array value.
2. It is not able to pass an array in a stored procedure.
To solve the issue, we can use the following steps:
1. Cconvert the array into string that delimited by “,” using the function “Join” in SQL Server Reporting Services.
2. Pass the string in the stored procedure.
3. Combine the parameter and the statement into one simply string.
4. Execute the simply string.
Here are the detailed steps for your reference:
1. In Report Designer, create a new dataset as “SELECT Title FROM TableTitle”.
2. Create a new multi-value parameter, set the available value from the dataset above.
3. Set the query of the main dataset as :
="spSelect_Title "&Join(Parameters!para.Value, ",")
4. Change the stored procedure as:
ALTER PROCEDURE [dbo].[spSelect_Title]
-- Add the parameters for the stored procedure here
--@Query NVarchar(Max),
@Title NVarchar(MAX)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
DECLARE @Query Varchar(Max)
SET @Query = 'SELECT FirstName, LastName, e.Title
FROM HumanResources.Employee AS e
JOIN Person.Contact AS c
ON e.ContactID = c.ContactID
WHERE e.Title IN (' + @Title+ ')'
-- PRINT ' QUERY = '+ ISNULL(@Query,'NULL')
Execute sp_executesql @Query
END
If you have any more questions, please feel free to ask.
Thanks,
Jin
Jin Chen - MSFT -
Best approach for performing DMLs using stored procedures
Hi,
I have a really general question and would like to hear your say about this.
I want my application to manipulate or read data using stored procedures (or packages in that manner) and not directly using queries against the DB.
Let's say I have a table with many columns:
create table test (pkid number(10),col1 varchar2(30), col2 number(10), col3 date,...);For such a DML procedure, is it best to do something like
procedure do_update(i_pkid IN number,i_col1 IN varchar2, i_col2 IN number, i_col3 IN date,...) as
begin
update test
set col1=i_col1,
col2=i_col2,
col3=i_col3...
where pkid=i_pkid;
commit;
end;Or do a selective update, meaning update only a certain column every time, given only 1 column actually changes? (and how to do that - separate procedures for each column? [columns can be nulls])
Also, is it better to work with test.col1%type instead of specifying the data type in the procedure?
And one last question - If I have a table with 100 columns and I don't want to create a procedure with 100 parameters - the best approach would be to use a record?
I just need to be set on the way I start implementing things in order to do it well from the start.
Many thanks.
Edited by: Pyrocks on Nov 17, 2010 1:58 PMPyrocks wrote:
One last clarification (although it may be more related to c/c++ developers - maybe one of you will know):
We are working with C++ and VB against a SQLServer and my part is to translate all the existing procedures to Oracle in order to migrate the application to work with Oracle DB.
The existing procedures use an IN parameter for each column in the table and I would really like to use rowtype like you mentioned.
Since I'm not a c/c++/vb developer - is there an easy way of working with such types, or even User-Defined Types, from c/c++/vb (as in passing a rowtype record from c++ to a SP ?)
I'm not looking for the actual way - just want to know how hard it would be and how much code needs to be changed in order to be able to convince the developers that this is the RIGHT way to work.
PS. none of our developers have experience with ORACLE so they wouldn't know the answer...Not actually an Oracle server-side (SQL language or PL/SQL language) question - but a client one. And it has been a long time since I wrote a fat client using C/C++ or Delphi.
The OCI (<i>Oracle Call Interface</i>) supports advance (user defined) SQL data types. Has since Oracle 8i. So in that respect, yes the client can support custom SQL data types.
How well it does depends entirely on that client language's features wrt OCI integration. For example, Delphi 4 was release around Oracle 8i and supported custom SQL types. I would expect that most languages today (like Java and C#) will provide support for it.
As for usiong +%ROWTYPE+ - this is a PL/SQL clause as far as I know. Unsure whether it is supported by the OCI. What could support it is a pre-compiler like Pro*C. These enable you to mix pseudo SQL source code with client language source code. The pre-compilation step then replaces the pseudo SQL code with native client language calls to the OCI. The code is then compiled by that client language's compiler. Pre-compilers can pull all kinds of interesting "tricks" with their pseudo SQL code support.
The best would be to consult the applicable client language's manuals that describe the interface it supports (via OCI) to Oracle. -
Using stored procedures for insert, update and delete
Hello all;
We have a question from our customer (who is the DBA), who has not in the past used TopLink, about whether it makes sense to tie TopLink into existing stored procedures to save and retrieve informations.
Is it possible?
Is there any circumstance under which it is a good idea?
ThanksIn TopLink any operation for which TopLink generates SQL, can be replaced by custom SQL, or a stored procedure call.
Custom SQL or stored procedures can be used for each of the descriptor's CRUD operations, but also for mapping queries and named queries. The Mapping Workbench only supports defining custom SQL for the descriptor CRUD operations and named queries, so many of the stored procedures call from the descriptor and mappings will need to be done through amendment methods.
Whether it makes sense or not depends on the application and the company and their requirements. It will add significant overhead to the development process to have to define and maintain all of the stored procedures, and the stored procedure calls in the descriptors. You may wish develop your application using TopLink generated SQL, and once you have the model and queries stabilized then switch to using stored procedures.
Whether it is a good idea depends on the application and the company and their requirements. Stored procedures may give the DBA more freedom to change the data-model once in production, and may allow for adding database-level security checks. In general using stored procedures will not improve performance if the procedures contain the same SQL that would have be executed anyway, but they may allow for the DBA to tune the SQL better. -
Need to update multiple records using store procedure
Hi i am trying to update multiple records using store procedure but failed to achieve pls help me with this
for example my source is
emp_name sal
abhi 2000
arti 1500
priya 1700
i want to increase salary of emp whose salary is less than 2000 it means rest two salary should get update..using stored procedure only
i have tried following code
create or replace procedure upt_sal(p_sal out emp.sal%type, p_cursor out sys_refcursor)
is
begin
open p_cursor for
select sal into p_sal from emp;
if sal<2000 then
update emp set sal= sal+200;
end i;f
end;
and i have called the procedure using following codes
set serveroutput on
declare
p_sal emp.sal%type;
v_cursor sys_refcursor;
begin
upt_sal(p_sal,v_cursor);
fetch v_cursor into p_sal;
dbms_output.put_line(p_sal);
end;
the program is executing but i should get o/p like this after updating
1700
1900
but i am getting first row only
2000
and record is not upsating...please help me with this
thanksHi Alberto,
thanx for your valuable suggestion. but still i have doubt. the code which i have mentioned above might be simple but what if i have big requirement where i need update the data by using loops and conditional statement.
and i have similar kind of requirement where i need to deal with procedure which returns more than one row
my source is
empno ename salary
111,abhi,300
112,arti,200
111,naveen,600
here i need to write a store procedure which accepts the empno (111) as input para and display ename and salary
here i have written store procedure like this
create or replace procedure show_emp_det(p_empno in emp.empno%type, p_ename out emp.ename%type,p_salary out emp.salary%type, p_cursor out sys_refcursor)
is
begin
open p_cursor for
select ename,salary into p_ename,p_salary from emp where empno=p_empno;
end;
and i have called this by using
declare
p_salary emp.salary%type;
p_ename emp.ename%type
v_cursor sys_refcursor;
begin
show_emp_det(111,p_ename,p_salary,v_cursor);
fetch v_cursor into p_ename,p_salary;
dbms_output.put_line(p_ename);
dbms_output.put_line(p_salary);
end;
here i should get
abhi,300
naveen,600
but i am getting first row only
abhi,300
but i want to fetch both rows...pls help me to find the solution -
Using stored procedures with dabasae controls
Hi. We have two questions.
Answer 1:
We are working with Sybase and we are trying to use stored procedures (SP) with databse controls but we don't know how to obtain SP's return. We can to use SP normally if that SP don't have any return. Next example works fine but "stored_procedure_name" actually returns an number (error code) and we need to obtain it:
* @jc:sql statement="{call stored_procedure_name (?)}"
Answer 2:
Do you know how to call SP dinamically? This mean to call an sql statemente where stored_procedure_name and its parameters could be pased as paremeters. That looks as:
* @jc:sql statement="{call {sql: spName} {sql: listOfParameters}}"
Thak you very much for your comments.
Regards.I have my entity manager setup in a singleton.
I'm finding it's costly to generate the emf, but if I don't close the em (enitity manager) and emf (entity manager factory) my open cursor count climbs until I exceed the max number of open cursors on the database (11g RAC)
I'm committing the connection, and uow, and closing the em at the end of each call.
But until I close the emf, the open cursors aren't released.
TransactionhistoryPkg tranPkg = new TransactionhistoryPkg(conn); //Class created over database package via JPublisher
tranPkg.transactionhistoryInsSp(insertTrans.getCardId()); // executes db package
tranPkg.closeConnection();
conn.commit();
uow.commit();
uow.getAccessor().decrementCallCount();
em.close();
Am I missing something really obvious here??
btw - I found this link helpful in troubleshooting the max cursors issue: https://support.bea.com/application_content/product_portlets/support_patterns/wls/InvestigatingORA-1000MaximumOpenCursorsExceededPattern.html -
Bulk insert using stored procedure or trigger
Hi ,
I have to insert around 40,000 rows in a table querying other database using database link.
Please advice whether I do using stored procedure or trigger.
Thanks.Here is a basic benchmark that illustrates the difference between maximising SQL, or doing it in PL/SQL instead.
Care needs to be taken with such a benchmark in order for physical I/O not to negatively impact a test, and then have no impact in the second test as that data read from disk now sits in the cache.
So I ran it a couple of times in order to "warm up" the cache. I also put the maximise-SQL test first in order to show that it is still faster, despite any physical I/O it may do (which will likely be faster logical I/O with the second test).
Run on Oracle XE 10.2.0.1.
SQL> drop table my_objects_copy purge;
Table dropped.
SQL> create table my_objects_copy as select * from all_objects;
Table created.
SQL>
SQL> set timing on
SQL> begin
2 delete from my_objects_copy;
3
4 insert into my_objects_copy
5 select * from all_objects;
6
7 commit;
8 end;
9 /
PL/SQL procedure successfully completed.
Elapsed: 00:00:01.11
SQL> set timing off
SQL>
SQL> drop table my_objects_copy purge;
Table dropped.
SQL> create table my_objects_copy as select * from all_objects;
Table created.
SQL>
SQL> set timing on
SQL> declare
2 cursor c is select * from all_objects;
3 objRow ALL_OBJECTS%ROWTYPE;
4 begin
5 delete from my_objects_copy;
6
7 open c;
8 loop
9 fetch c into objRow;
10 exit when c%NOTFOUND;
11
12 insert into my_objects_copy
13 values objRow;
14
15 end loop;
16 commit;
17 end;
18 /
PL/SQL procedure successfully completed.
Elapsed: 00:00:03.21
SQL>
The cursor-fetch-loop is almost 3 times slower. The more rows there are to process, the slower the cursor-fetch-loop will become, as it will create more and more context switching and copying data between the SQL and PL engines and back.
Maybe you are looking for
-
I have a problem in making a pdf-file interactive which I suspect will have to be solved by Javascript, but I don't know the exact solution. What I want to do is to be able to create a button on a page. Clicking this button will cause the pdf reader
-
Problems with restarting, connecting wirelessly Mac OS 10.4.8
Hello everyone, This is in addition to my previous post http://discussions.apple.com/thread.jspa?threadID=817360 I have restored the system that came with my iMac, which is 10.4.7 My iMac now restarts, based on what I arrive at the conclusion that th
-
Hi Experts, BAPI to get all user lists for input specific object, authorizations, profiles and values? Any useful answer will be rewarded with suitable points. Thanks, Rohan
-
Hi Guys, I need your help. I always used facetime on my iphone 4 without problems but when i used facetime for the first time on my macbook and came out what you read below. What does it mean and why i should change my ID password? Thanks a lot. "You
-
cant download and install CS 5 reactivation . I have the serial number