Call Store Procedure in SQL Server
How can I call an Oracle Store Procedure in a SQL Server procedure?
Make sure you're calling the stored procedure with the same parameters at the same database. If that's not the case then send the procedure body and how you are calling it from code and DB .
"If there's nothing wrong with me, maybe there's something wrong with the universe!"
Similar Messages
-
Exception while calling stored procedure in SQL server
Hi,
I run into a problem while calling a proc in SQL server. I am using a database control to do so. The proc returns a integer. This is the first time I use SQL server. Any thoughts? Thanks in advance.
My method call is:
int createAccount(SQLParameter[] param)
The sql is:
{call espsiCompany(?, ?, ?)}
The error is:
java.lang.NullPointerException
at com.bea.wlw.runtime.core.control.DatabaseControlImpl.getStatement_v2(DatabaseControlImpl.jcs:1885)
at com.bea.wlw.runtime.core.control.DatabaseControlImpl.invoke(DatabaseControlImpl.jcs:2691)
at com.bea.wlw.runtime.core.dispatcher.DispMethod.invoke(DispMethod.java:373)
at com.bea.wlw.runtime.core.container.Invocable.invoke(Invocable.java:423)
at com.bea.wlw.runtime.core.container.Invocable.invoke(Invocable.java:396)
at com.bea.wlw.runtime.jcs.container.JcsProxy.invoke(JcsProxy.java:388)
at services.OnyxDBControl.createAccount(OnyxDBControl.ctrl)
at services.OnyxDBControlTest.createAccount(OnyxDBControlTest.jws:18)Hi. That's not the signature of the procedure. What I'd like to see is
the SQL used to create the procedure, eg:
create procedure myProc @foo int, @bar varchar(30) ....
as
begin
end
Jun Li wrote:
Here you go. Thanks for your time.
DECLARE @RC int
DECLARE @iSiteId int
DECLARE @iCompanyId int
DECLARE @chLanguageCode char(4)
DECLARE @vchAssignedId varchar(255)
DECLARE @vchCompanyName varchar(255)
DECLARE @vchAddress1 varchar(255)
DECLARE @vchAddress2 varchar(255)
DECLARE @vchAddress3 varchar(255)
DECLARE @vchCity varchar(255)
DECLARE @chRegionCode char(4)
DECLARE @chCountryCode char(4)
DECLARE @vchPostCode varchar(40)
DECLARE @vchPhoneNumber varchar(40)
DECLARE @vchEmailAddress varchar(255)
DECLARE @vchURL varchar(255)
DECLARE @iCompanyTypeCode int
DECLARE @iCompanySubTypeCode int
DECLARE @iFamilyId int
DECLARE @iParentId int
DECLARE @iPrimaryContactId int
DECLARE @vchContactFirstName varchar(255)
DECLARE @vchContactLastName varchar(255)
DECLARE @iDivisionCode int
DECLARE @iSICCode int
DECLARE @iMarketSector int
DECLARE @vchTaxId varchar(255)
DECLARE @vchDunnsNumber varchar(255)
DECLARE @iPhoneTypeId int
DECLARE @iAddressTypeId int
DECLARE @iSourceId int
DECLARE @iStatusId int
DECLARE @bValidAddress tinyint
DECLARE @iAccessCode int
DECLARE @bPrivate tinyint
DECLARE @vchUser1 varchar(255)
DECLARE @vchUser2 varchar(255)
DECLARE @vchUser3 varchar(255)
DECLARE @vchUser4 varchar(255)
DECLARE @vchUser5 varchar(255)
DECLARE @vchUser6 varchar(255)
DECLARE @vchUser7 varchar(255)
DECLARE @vchUser8 varchar(255)
DECLARE @vchUser9 varchar(255)
DECLARE @vchUser10 varchar(255)
DECLARE @chInsertBy char(10)
DECLARE @dtInsertDate datetime
DECLARE @tiLockRecord tinyint
DECLARE @tiRecordStatus tinyint
DECLARE @tireturnType tinyint
-- Set parameter values
EXEC @RC = [ONYXPROD].[dbo].[espsiCompany] @iSiteId, @iCompanyId OUTPUT , @chLanguageCode, @vchAssignedId, @vchCompanyName, @vchAddress1, @vchAddress2, @vchAddress3, @vchCity, @chRegionCode, @chCountryCode, @vchPostCode, @vchPhoneNumber, @vchEmailAddress, @vchURL, @iCompanyTypeCode, @iCompanySubTypeCode, @iFamilyId, @iParentId, @iPrimaryContactId, @vchContactFirstName, @vchContactLastName, @iDivisionCode, @iSICCode, @iMarketSector, @vchTaxId, @vchDunnsNumber, @iPhoneTypeId, @iAddressTypeId, @iSourceId, @iStatusId, @bValidAddress, @iAccessCode, @bPrivate, @vchUser1, @vchUser2, @vchUser3, @vchUser4, @vchUser5, @vchUser6, @vchUser7, @vchUser8, @vchUser9, @vchUser10, @chInsertBy, @dtInsertDate, @tiLockRecord, @tiRecordStatus, @tireturnType -
How to write a store procedure under SQL Server 2008
Hi Folks,
Kindly help me step by step how to create a simple store procedure with help of sql server 2008 r2 for Crystal report.
I know how to work by using Universe but not SQL Server. Kindly help me how to hard code by using sql.
Thanks in adv.
ReddyFor the actual syntax for programming the stored proc, you'll need to work with someone (or a website) who knows T-SQL.
The cursor that gets returned from the stored proc must be an "in out" parameter for the stored proc. For SQL Server I usually define a record type that includes the fields that will be returned and then return a set of records of that type. Again, check with someone who is familiar with T-SQL for more information about how to do this.
-Dell -
Passing a table-field value in Crystal to a Store Procedure in SQL Server
I have been checking all over the interenet via searches and although some seem to come close to this, its still not what I want.
Essentially I need to pass value from Table-Field record (for each record read/selected) via a paramete to a Stored Procedure(SP) in SQL Server 2205/2008. I do NOT want to be prompted for a value for this parameter each time the report is run, simple pass the value in which will be used along with other select criteria to bring back one value for the report to use in a calcuation per record.
The value of the parameter is a date, but I understand it would be better to pass it in as a varchar(8) - 'YYYYMMDD' - and then reconvert it inside the SP, as follows:
In Crystal Reports 2008 SP3, I have a formula defined as,
trans_date = ToText ({F1ARS_STMT_WS_TRAN.TRANS_DATEI}, 'YYYYMMDD')
and essential just want to pass this to the SP below ... i.e. trans_date ---> @strTransDate
I then link the key fields [EXCH_RATE_TABLE_NAME] and [TRANS_CCY_CODE] to other tables in the Database Expert, and put [EXCH_RATE_AMT] on the report and use it to calculate what I want.
This works fine when the prompt comes up and I put in a proper date, but I don't what it to prompt, but simple pass the F1ARS_STMT_WS_TRAN.TRANS_DATEI in via the fornula/parameter and let teh SQL do the rest for each record selected..
CREATE PROCEDURE [dbo].sp_GET_EXCH_RATE_AMT (@strTransDate varchar(8)) --use format 'YYYYMMDD' to represent the date as a string.
-- Add the parameters for the stored procedure here
-- @TransDate datetime = now
AS
declare @TransDate datetime
set @TransDate = CONVERT(DATETIME, @strTransDate, 112)
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
SELECT [EXCH_RATE_TABLE_NAME], [TRANS_CCY_CODE], [EXCH_RATE_AMT]
FROM [F1CCY_EXCH_RATE]
WHERE [MAJOR_CCY_CODE] = 'BBD'
AND [START_DATEI] =
SELECT MAX([START_DATEI])
FROM [F1CCY_EXCH_RATE]
WHERE [MAJOR_CCY_CODE] = 'BBD'
AND [START_DATEI] <= @TransDate
END
GO
GRANT EXECUTE ON sp_GET_EXCH_RATE_AMT TO PUBLIC
GO
Thanks for any help. Can't tell the headache this has caused my both literally and figuratively.Hello,
I moved your post to the Report Design forum. Lots of SQL help in here...
I believe the problem is due to you using a Parameterized Stored Procedure. The first thing CR has to do is connect to your DB source which requires the date parameter before it can run the query to add the date filter, it's the SP that is prompting for the parameter. Therefore the report has not run so it can't get the field value from the report until you fill in the info for the SP. Catch 22 problem.... Which came first, the Chicken or the Parameter....
The report will work as you have noted but I don't know of anyway to refresh unless parameter is filled in again....
Jason has a lot of great solutions when it comes to these dilemmas, Possibly using a Command Object may help but I believe you will still run into the same issue....
Only way I can think of is to not use a parameter in the SP and let CR do the filtering client side. Of course this means all data is coming back to the client PC as you are likely trying to find a work around for.
Thank you
Don -
sql server services give error the remote procedure call failed [0x800706be] in sql server 2008.
To resolve this issue, I executed the following mofcomp command in command prompt to re-register the *.mof files:
mofcomp.exe "C:\Program Files (x86)\Microsoft SQL Server\100\Shared\sqlmgmproviderxpsp2up.mof".
but it does not work.
Plz give the exact soln to solve this error.sql server services give error the remote procedure call failed [0x800706be] in sql server 2008.
To resolve this issue, I executed the following mofcomp command in command prompt to re-register the *.mof files:
mofcomp.exe "C:\Program Files (x86)\Microsoft SQL Server\100\Shared\sqlmgmproviderxpsp2up.mof".
but it does not work.
Plz give the exact soln to solve this error.
So when you tried starting SQL server service it gave the error right ? or when you click on SQL server services in SQL server configuration manager(SSCM) you get this error. Can you be more clear. As far as I read your question it has something
to do with permission. Close SSCM window and this time right click on SQL server configuration manager and select run as administrator and check if you can see SQL server services
Please mark this reply as answer if it solved your issue or vote as helpful if it helped so that other forum members can benefit from it
My Technet Articles -
Executing Procedure in SQL SERVER and Storing the results in Oracle 10g
Hello,
I am trying execute SQL SERVER procedure from Oracle 10g and store the results in a oracle table. When I tried executing the procedure i am getting errors.
I am using Oracle Heteroeneous Services.
Steps I followed.
1. Created ODBC DSN on Oracle Server connecting to SQL SERVER database.
2. Created Listner entry and TNSNAMES entries.
3. Created Database link and able to select the data from the SQL SERVER tables.
Here is the code i tried to execute the procedure.
BEGIN
"META"."extract"@abc;
END;
"META"."extract"@abc;
ERROR at line 2:
ORA-06550: line 2, column 1:
PLS-00201: identifier 'META.extract@ABC' must be declared
ORA-06550: line 2, column 1:
PL/SQL: Statement ignored
Please help me.
Thank You,
Seshadri ThopeHi thopevs,
Can you please tell me the right syntax of calling procedures(on sql server) from oracle?
I am getting following error:
SQL> execute "GetdateSys"@oratosql;
begin "GetdateSys"@oratosql; end;
ORA-06550: line 2, column 7:
PLS-00201: identifier 'GetdateSys@ORATOSQL' must be declared
ORA-06550: line 2, column 7:
PL/SQL: Statement ignored
SQL>
Your help will be highly appreciated.
Thanks & Regards,
M.U.N.A -
How to find the list of unused stored procedures in SQL Server 2005?
Hi,
I need to find out the list of stored procedures which are not in use.
I found there is something called "sys.dm_exec_procedure_stats " for SQL server 2008.
Can you please suggest your ides here to do the same job for SQL server 2005.
Many Thanks.In SQL 2005 there is, sort of. This is query lists the last execution
time for all SQL modules in a database:
SELECT object_name(m.object_id), MAX(qs.last_execution_time)
FROM sys.sql_modules m
LEFT JOIN (sys.dm_exec_query_stats qs
CROSS APPLY sys.dm_exec_sql_text (qs.sql_handle) st)
ON m.object_id = st.objectid
AND st.dbid = db_id()
GROUP BY object_name(m.object_id)
But there are tons of caveats. The starting point of this query is
the dynamic management view dm_exec_query_stats, and the contents is
per *query plan*. If a stored procedure contains several queries,
there are more than one entry for the procedure in dm_exec_query_stats.
Best Regards,Uri Dimant SQL Server MVP,
http://sqlblog.com/blogs/uri_dimant/
MS SQL optimization: MS SQL Development and Optimization
MS SQL Consulting:
Large scale of database and data cleansing
Remote DBA Services:
Improves MS SQL Database Performance
SQL Server Integration Services:
Business Intelligence -
Does Oracle have Extended Stored Procedure like SQL Server and Sybase?
Hi, i am new to Oracle. I want to know if...
Does Oracle have Extended Stored Procedure like SQL Server and Sybase?
If it does not have, then how can i call outside program written in C or JAVA from the Database stored procedure or trigger?refer to this link on external procedures
http://download-west.oracle.com/docs/cd/A87860_01/doc/server.817/a76956/manproc.htm#11064 -
About JDBC CALL STORE PROCEDURE with out parameter is greater than 4000
Hi Guys,
I have a problem call store procedure with a large string.
as i know varchar2 can contain 32767 characters in pl/sql .
But when i used varchar2 as a out parameter in a store procedure, if the out parameter is greater than 4000 characters , it always give me error message as 'the buffer is too small'.
why it happened?
I read some article that says i need configure a property in data-source.xml , and jdbc 10g driver already solved this problem, but i used jdev 10.1.3.2 ,the driver should be fine.
How can i solve this problem?
Thanks in advance,
AppCatObject is Foundation, Execute Script
This is for a query, you can change to a stored procedure call. Pull the value back in the Java code then put into the process variable.
import javax.naming.InitialContext;
import javax.sql.DataSource;
import java.sql.*;
PreparedStatement stmt = null;
Connection conn = null;
ResultSet rs = null;
try {
InitialContext ctx = new InitialContext();
DataSource ds = (DataSource) ctx.lookup("java:IDP_DS");
conn = ds.getConnection();
stmt = conn.prepareStatement("select FUBAR from TB_PT_FUBAR where PROCESS_INSTANCE_ID=?");
stmt.setLong(1, patExecContext.getProcessDataLongValue("/process_data/@inputID"));
rs = stmt.executeQuery();
rs.next();
patExecContext.setProcessDataStringValue("/process_data/outData", rs.getString(1));
} finally {
try {
rs.close();
} catch (Exception rse) {}
try {
stmt.close();
} catch (Exception sse) {}
try {
conn.close();
} catch (Exception cse) {} -
ADF 11, USING EJB, CALL STORE PROCEDURE, A PROBLEAM?
ADF 11, USING EJB, CALL STORE PROCEDURE, A PROBLEAM?
I have a store procedure:
CREATE OR REPLACE PACKAGE BODY PK_HR1
IS
FUNCTION FUNC04
RETURN CUR_RESULT
IS
X_CUR CUR_RESULT;
BEGIN
OPEN X_CUR FOR
select mako, tenko, diachiko from kho;
RETURN X_CUR;
EXCEPTION
WHEN OTHERS THEN
RAISE;
END FUNC04;
END PK_HR1;
In the entities class, I have a NamedStoredProcedureQuery:
@Entity
@NamedStoredProcedureQuery(name="Kho.FUNC04",
resultClass=Kho.class,
procedureName="PK_HR1.FUNC04" )
public class Kho implements Serializable {
In session bean, i have a method
public class SessionEJBBean implements SessionEJB, SessionEJBLocal
public void test() throws Exception{
try {
//code here ...
List<Kho> listKho = em.createNamedQuery("Kho.FUNC04").getResultList();
System.out.println("aaaa");
} catch (Exception ex) {
ex.printStackTrace();
} finally {
I try running, but always show errror
this errors:
Internal Exception: java.sql.SQLException: ORA-06550: line 1, column 7:
PLS-00221: 'FUNC04' is not a procedure or is undefined
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
Error Code: 6550
Call: BEGIN PK_HR1.FUNC04(); END;
Query: ReadAllQuery(jp.co.mfr.sgs.bean.Kho)
help help me?You need to use a CallableStatement for this.
--olaf -
Hi,
I am looking for inputs in tuning stored procedure using sql server 2008. l am new to performance tuning in sql,plsql and oracle. currently facing issue in stored procedure - need to increase the performance by code optmization/filtering the records using where clause in larger table., the requirement is Stored procedure generate Audit Report which is accessed by approx. 10 Admin Users typically 2-3 times a day by each Admin users.
It has got CTE ( common table expression ) which is referred 2 time within SP. This CTE is very big and fetches records from several tables without where clause. This causes several records to be fetched from DB and then needed processing. This stored procedure is running in pre prod server which has 6gb of memory and built on virtual server and the same proc ran good in prod server which has 64gb of ram with physical server (40sec). and the execution time in pre prod is 1min 9seconds which needs to be reduced upto 10secs or so will be the solution. and also the exec time differs from time to time. sometimes it is 50sec and sometimes 1min 9seconds..
Pl provide what is the best option/practise to use where clause to filter the records and tool to be used to tune the procedure like execution plan, sql profiler?? I am using toad for sqlserver 5.7. Here I see execution plan tab available while running the SP. but when i run it throws an error. Pl help and provide inputs.
Thanks,
VijiYou've asked a SQL Server question in an Oracle forum. I'm expecting that this will get locked momentarily when a moderator drops by.
Microsoft has its own forums for SQL Server, you'll have more luck over there. When you do go there, however, you'll almost certainly get more help if you can pare down the problem (or at least better explain what your code is doing). Very few people want to read hundreds of lines of code, guess what's it's supposed to do, guess what is slow, and then guess at how to improve things. Posting query plans, the results of profiling, cutting out any code that is unnecessary to the performance problem, etc. will get you much better answers.
Justin -
Creation of System Stored Procedure in SQL Server 2012 & SQL Server 2012 R2.
Hi all,
I am stuck at a point I am looking for a system stored procedure named 'sp_dboption' in SQL Server 2012 & R2 but could not find.
Searched for it on the net and found that, this stored procedure 'sp_dboption' is now obsolete. So I tried to copy the content of 'sp_dboption' stored procedure from SQL Server 2008 R2 and create new system stored procedure with this name 'sp_dboption' in
SQL Server 2012 but was unable to create the system stored procedure.
Can you guys please tell me how to create system stored procedure in SQL Server 2012 & SQL Server 2012 R2. The reason of why I want to achieve this is because I have used 'sp_dboption' system stored procedure in my application to create a database.
As 'sp_dbotion' stored procedure is present in SQL Server 2008 R2 I am able to create the database in SQL server 2008 R2 but not in SQL server 2012.
Can you please guide me how to create system stored procedure. I am out of luck.
Please assist me, thanks & looking for help at the earliest. Hope someone will come to the fore and help me.Hi Vishwajeet,
If you tried to create any object in the sys schema, you will get the error below.
The specified schema name "sys" either does not exist or you do not have permission to use it.
So I am afraid creating any object in sys schema is not supported by SQL Server. Here is a similar link for your reference.
How to create table in SYS schema in SQL Server?
Though sp_dboption is not in SQL Server 2012, does creating a user-defined one with the same content in 2008 make any difference in your business? You just need to specify the fully qualified name dbname.dbo.sp_dboption.
If you are still interested in creating a system sp_dboption, you can register it with the
sp_ms_marksystemobject.
See
Creating Your Own SQL Server System Stored Procedures.
Eric Zhang
TechNet Community Support -
Debugging stored procedure in SQL Server 2012
Hi,
Please I need your help.
I used to debug stored procedures in SQL server 2008, 2008 R2. I'm debugging the stored procedure using SQL Server management studio. I just create a break point then I click on the debug button
and start debugging without any problems.
I'm talking about my local machine which I have administrator privileges on the machine. My account in the administrators group and I'm assigned in the sysadmin role in SQL server but I couldn't
debug the stored procedure. When I create a break point and try to debug the stored procedure I'm getting a popup screen saying "To continue debugging, the firewall needs to be configured. Configuring the firewall requires privileges."
I tried to figure out the issue but unfortunately until now I'm not able to resolve it.
Thanks.The problem resolved with help of Microsoft support but it was really strange situation.
First, the following is my environment.
OS is Windows 8 Pro
SQL Server 2012
I did try everything firewall, Anti-Virus and other thing as well. I usually type (local) on the server name TextBox. I did close my Anti-Virus program, turn off windows firewall and run SQL server as administrator but I’m still
unable to debug.
I just do one thing and one thing only, changed the (local) on the server name TextBox to the actual server name and everything work fine. I did try that with everything close/open my Anti-Virus program, turn
off/one windows firewall and still work fine, and I was able to debug any T-SQL in SQL server 2012 but run it as administrator.
Anyway, I’m happy to back on the road again.
Thank you every single one of you who try his best to help.
Cheers. -
How to call store procedure in query generator
Hi All,
How to call store procedure in query generator.
Regards
Rajkumar Gupta
Edited by: Rajkumar Gupta on Dec 7, 2010 2:11 AMHi,
Please check the following threads.
How to use Stored Procedure in sap business one
How to add parameters to a stored procedure in B1 Query generator
How to execute the procedure in sap b1
Hope it helps,
Vasu Natari. -
I log in in the Enterprise manager with the user "Nadia" that I created . I Created an escheme TEST and all the tables .
I Created also the package with this user. It has a procedure that returns 1 cursor.
This user has:
atributte: CONNECT, DBA AND RESOUCE
System: EXECUTE ANY PROCEDURE AND UNLIMITED TABLESPACE
Is it correct?
My application is access the oracle 9i with this user too.
I have to call the procedure this way:
SID.PACKAGE.PROCEDURE
Im my vb code, I am call this way too.
Code VB 6:
With cmd
.ActiveConnection = CNP
.CommandText = "NADIA.EXT_DADOS.DADOS_VISITANTE" ????
.Prepared = False
.CommandType = adCmdStoredProc
.Parameters.Append .CreateParameter("@Documento", adInteger, adParamInput, 15, 8384474)
.Parameters.Append .CreateParameter("@nome", adChar, adParamInput, 1, lsTipo)
Set ObReg = .Execute(, , adAsyncFetchNonBlocking)
End With
When execute, message errors show:
The NADIA.EXT_DADOS.DADOS_VISITANTE needs to be declared.
Wha is wrong?
thank you
NádiaIt looks like you are getting appropriate feedback in one of the other threads on this topic that you've posted:
To call Store procedure
But I would have to say that I hope this is just a test system. I would never grant DBA, EXECUTE ANY PROCEDURE, and UNLIMITED TABLESPACE to a "normal" user in a production system.
Good luck,
Mark
Maybe you are looking for
-
Urgent Timezone change: Venezuela - Patch needed or info how to change it.
Greetings, The Venezuelan government decided to change the Timezone of Venezuela (America/Caracas) from GMT -4 to GMT -4:30 by September 24th 2007. We need to change the timezone of a Solaris 10 server, of course, we thought about just changing time,
-
[SOLVED] 'Dim screen while inactive' not working
I have a sony vaio with GNOME 3. I suppose when it's not on AC power the screen should dim (it's ON on the Power Manager), but I wait and the screen's brightness doesn't drop a bit... I have another laptop, acer with Fedora 20 MATE, after a short whi
-
TS2529 why can't i get my email verification to activate my apple id
i have been trying for hours to set up my new phone and cant get my verification email
-
Writing HD Video (AVCHD) to BluRay using PE 8
I am trying to write a 28 minute high definition video project to BluRay disks using Primere Elements 8. The hardware is a Dell Quad Core 3.4 GHz machine with 12 GB RAM running Win-64 Pro. I do have a Blu Ray drive and disks available. The project is
-
Release strategy for GR?
Hi, My company has requirement that GR should be subject to approval process before it can be posted. As far as I know there is no standard functionality in SAP for this (at least in ECC, as in SRM there is one). Has anyone encounter this before? And