Triggering and Stopping a Stored Procedure
I'm setting up a mass mailing system for approx 250,000
users.
I need to find a way to trigger a stored procedure to run
every 5 miuntes untill the task is complete. The idea being that
once triggered it'll work its merry way through the database firing
off a couple of thousand emails each cycle untill it's reached the
end.
Any ideas how to implement this?
Thanks
Generally, the term "stored procedure" is used to mean a
piece of SQL code that is stored and run in the database server. It
sounds like what you mean is a ColdFusion Scheduled Task - a piece
of CF code that is run automatically. You can set these up using
either the CF administrator or the <cfschedule> tag. Breaking
up your mailings is a good idea since CF will probably time out if
you try to execute 250,000 mailings at once. You could do something
like this:
1) If unsent records, do:
2) Select X number of unsent records
3) Send mail
4) Update X records as having been sent
You would just have to make sure that you time it correctly,
otherwise you could wind up with 1 process starting before the
other finishes and some people will get duplicate emails.
Similar Messages
-
Java and Sybase nested stored procedures.
Hi!
I have nested Sybase stored procedures, the main procedure calls a helper stored proc.
The main procedure returns 2 result sets before calling the helper store proc and helper store proc returns 1 resultset. After the helper store proc is called, the main store proc returns 2 more resultset. When I run it using SQL client tool the main procedure(and it's helper) execute well and returns rows.
I need to call this store proc in a java code and display all the resultset in screen. I am using Statement:execute(<exec sp>) to execute the store proc and then statement.getResultSet() to get each resultset. The loop is controlled by statement.getMoreResults() .
It displays the first 2 resultsets from main Store Proc. Then the control goes to helper store proc. It executes the helper store proc and displays the resultset from helper. But then it stops there and doesnot
come back to main store proc to execute the remaining resultset.
What I suspect is that, the statement object is getting overlaid when the call goes to helper proc.
Any idea as to how to code to handle multiple nested resultset ?
~ RNS.
My Sybase stored procedure code looks like -
=======================================================================
create procedure main_proc
@param1 int
as
select getdate()
select @@servername
declare @return_val int
exec proc2 @param1, @return_val out
select myCol1,
myCol2,
myCol3=@return_val
from mytable
select db_name()
===========================================================================
Sybase Code for proc2
create procedure proc2
@param1 int,
@param2 int out
as
begin
if something exists(select * from table where whereClause)
select @param2="TRUE"
else
select @param2="FALSE"
select getdate()
end
go
GRANT EXECUTE...
EXEC sp_procxmode 'dbo.proc2,'unchained'
go
====================================================================
Code snippet :-
do {
int iit=0;
rs=stmt.getResultSet();
if ( rs != null ) {
ResultSetMetaData rsd = rs.getMetaData();
int nocols = rsd.getColumnCount();
for (int i=1; i<=nocols; i++)
System.out.println(rsd.getColumnName(i)));
while (rs.next())
for (int i=1; i<=nocols; i++)
System.out.println(rs.getString(rsd.getColumnName(i));
} while (stmt.getMoreResults());I'm not 100% sure about this, but my guess is that this is caused by the TDS protocol (used by Sybase). TDS makes no difference between the stored procedure you are calling and the "inner" stored procedure, so the driver just returns update counts and result sets as they are generated, regardless of who generated them.
Another guess (as I don't know what driver you are using) is that execute() returns the first result (update count or ResultSet), as opposed to executeQuery(), which returns the first ResultSet (probably discarding the update count). You can make sure of this by calling getMoreResults(); you should get your ResultSet at some point.
Alin. -
Triggers accepting parametes from stored procedures
Can triggers accept parameters from stored procedures like some filename or column name of a table and pass them to external c procedures.If so I would greatly appreciate if any one could provide me with an example.
P.S The trigger is on a view and the view which in turn should be created in the stored procedure.
Thanks
HariniHello,
Yes you can invoke Web Services from the database, it is often called "Database Web Service call out" and it is documented in the Web Services Developer Guide
Regards
Tugdual Grall -
Using XI - RFC table and an Oracle stored procedure that returns a cursor.
I need to create an interface using XI between an RFC table and an Oracle stored procedure that returns a cursor. We are on oarcle 9.2 and SP12.
My stored procedure looks something like this:
CREATE OR REPLACE
PROCEDURE testproc_xi2 (p_recordset1 OUT SYS_REFCURSOR,
in_quoteid IN varchar2 )
AS
BEGIN
OPEN p_recordset1 FOR
SELECT q.quote_id,
q.modified_by,
q.quote_status,
q.total_cost
FROM quote q
WHERE q.quote_id = in_quoteid
AND q.total_cost > 0 ;
END testproc_xi2 ;
My RFC has table and one import parameter .
I wanted to know how to create the data type for the ref cursor? and also for the table type in the RFC?
CAN XI handle multi rows coming from a Stored procedure? Are there any other alternative methods if this is not supported?Any pointers to this would be helpful.
I have called a Oracle SP from an RFC before, but that interface had one input parameter going to the stored procedure from the RFC and about 6 o/p parameters coming from the Stored procedure. This works fine.
Thanks for the help.
MalaMala,
i dont think there is anything called an rfc table...RFC stands for remote function call. That in essence would imply you need a rfc to jdbc connection.
yes XI can handle multiple rows cooming from the the stored procedure if you have them mapped appropriately.
Now as to how to create the data type within xi , you need to know what fields are going to be returned and whether they are nested and then just create them as you would for an xml
for ex
<Details>
<FirstName>
<LastName>
</Details>
that in xi would be smthing like
Details type of data occurence
FirstName type of data occurence
LastName type of data occurence.
Hope that helps.
If it does dont forget the points..:-) -
How to use stored procedures in DIAdem and Can the stored procedures be used to return values?
Can anyone please tell me how to use stored procedures in diadem and to return values from it. Its really important, can you please answer it at the earliest.
Thanks In advance
spiyaHi Spria,
I'm very sorry for the mix-up, I thought Allen was going to answer you back with the particulars that we found out. Check out the attached Word document and the below tidbits:
The built-in DIAdem ODBC functions {SQL_...()} can only call stored functions, which return a scaler result {found then in SQL_Result(1,1)}. The syntax for this with an ORACLE db is
"select function(parameters) from package"
...where package defaults to "dual" if you don't use your own package.
There might be exceptions to that though, and the syntax will be different for other databases. Note that stored ORACLE procedures can NOT be called from the ODBC functions, instead you must use either ADO function calls in the DIA
dem VBScript or the OO4O COM wrapper that ORACLE provides (this is described in further detail in the below Word document).
Hope this helps,
Brad Turpin
DIAdem Product Support Engineer
National Instruments
Attachments:
Calling_ORACLE_Stored_Procedures_from_DIAdem.doc 28 KB -
Returning rowcount and resultset from stored procedure
Hello,
In SQL Server you can return multiple resultsets from stored procedure by simple SELECT statement. But in Oracle, you have to use SYS_REFCURSOR.
Sample code:
CREATE OR REPLACE PROCEDURE sp_resultset_test IS
t_recordset OUT SYS_REFCURSOR
BEGIN
OPEN t_recordset FOR
SELECT * FROM EMPLOYEE;
END sp_resultset_test;
Is there any other way in Oracle 10 or 11 ?
Thank You.What is the requirement? Oracle is far more flexible than SQL-Server... with numerous features that do not exist in SQL-Server. (Fact)
One of the biggest mistakes you can make is to treat Oracle like SQL-Server... trying to match feature A1 in SQL-Server to feature B3 in Oracle.
Does not work that way.. rather then stick to SQL-Server as SQL-Server does SQL-Server specific features far better than Oracle.
So instead of trying to map what a T-SQL stored proc to do to an Oracle ref cursor (even to the extent of using that very silly sp_ prefix to name the proc), tell us the problem and requirements... That way we can tell you what Oracle features and options are best used to solve that problem - instead of competing in some unknown feature comparison event with SQL-Server. -
Loading jar files and calling java stored procedure
I am trying to load jai_core.jar, jai_codec.jar, mlibwrapper.jar and another class I created into my project schema. I am having problems with resolving all of the class using the "loadjava -resolve" command as well as using the "alter java class" command. The single class I authored is not in a valid state as well as the PL/SQL wrapper for the function I am calling.
My questions are:
1) Does the single class need to be in a valid state before the PL/SQL wrapper will compile and be in a valid state itself?
2) Are there any special tricks to this becuase the code I am using below doesn't seem to be working correctly?
3. Should I worry about "resolving/validating" all of the class from the jar file? I have read conflicting views on this topic.
SQL> CREATE OR REPLACE FUNCTION get_image (p_fileName in varchar2, p_offset in number )
2 RETURN blob AS LANGUAGE Java
3 NAME 'gov.irs.rtr.image.ImageUtilityFunction.getImage (java.lang.String, int) RETURN oracle.sql.BLOB';
4 /
Warning: Function created with compilation errors.
SQL> show err
Errors for FUNCTION GET_IMAGE:
LINE/COL ERROR
0/0 PL/SQL: Compilation unit analysis terminated
3/1 PLS-00311: the declaration of
"gov.irs.rtr.image.ImageUtilityFunction.getImage
(java.lang.String, int) RETURN oracle.sql.BLOB" is incomplete or
malformed
Any help would be greatly appreciated.
Regards,
JoeyWe are using Oracle 9.2.0.8 and I have written the single class in 1.3.1.
The first loadjava commands I tried were:
loadjava -user username/password -resolve -resolver '((* RTRPROD)(* PUBLIC))' jai_core.jar jai_codec.jar mlibwrapper_jai.jar
loadjava loadjava -user username/password -resolve -resolver '((* RTRPROD)(* PUBLIC) (* -))' ImageUtility.class
Then I tried:
loadjava -user username/password -resolve -resolver '((* RTRPROD)(* PUBLIC) (* -))' jai_core.jar jai_codec.jar mlibwrapper_jai.jar
errors : class javax/media/jai/operator/EncodeDescriptor
ORA-29534: referenced object RTRPROD.com/sun/media/jai/codec/ImageCodec could not be resolved
errors : class javax/media/jai/operator/FileStoreDescriptor
ORA-29534: referenced object RTRPROD.com/sun/media/jai/codec/ImageCodec could not be resolved
errors : class com/sun/media/jai/opimage/BMPRIF
ORA-29534: referenced object RTRPROD.com/sun/media/jai/opimage/CodecRIFUtil could not be resolved
errors : class com/sun/media/jai/opimage/CodecRIFUtil
ORA-29534: referenced object RTRPROD.com/sun/media/jai/codec/ImageCodec could not be resolved
errors : class com/sun/media/jai/opimage/EncodeRIF
ORA-29534: referenced object RTRPROD.com/sun/media/jai/codec/ImageCodec could not be resolved
errors : class com/sun/media/jai/opimage/FPXRIF
ORA-29534: referenced object RTRPROD.com/sun/media/jai/opimage/CodecRIFUtil could not be resolved
errors : class com/sun/media/jai/opimage/GIFRIF
ORA-29534: referenced object RTRPROD.com/sun/media/jai/opimage/CodecRIFUtil could not be resolved
errors : class com/sun/media/jai/opimage/IIPCRIF
ORA-29534: referenced object RTRPROD.com/sun/media/jai/codec/ImageCodec could not be resolved
This error messages goes on and on for 44 files.
I have found out that JAI is part of the Oracle 9 Release 2 but is part of the InterMedia package that is not installed. I would imagine that the JAI libraries mentioned above would be included in InterMedai. However, there are several dependencies on packages distributed in the Sun JDK but not the Oracle Runtime.
Regards,
Joey -
Start, restart, stop and status stored procedure - howto?
First:
- this and other otn forums are awesome!
- apex is neat
Second:
- I have O'Reilly books: "Oracle pl/sql programming" and "Mastering Oracle SQL"
- Also tried to search / google best practices around stopping 'hanging stored procedures' and creating logics for such happening
Challenge:
I would like to implement simple solution for starting, stopping, restarting and maybe even getting status of stored procedures. Sounds like unix runlevels but in "userspace" without the sys rights.
Finally I would like to have this functionality in apex-application where predefines stored procedures could be started, restarted, stopped and maybe even status could be retrieved.
start - this is simple, start - but maybe check if such stored procedure is already started ( so this start will fail)
stop - send signal to certain procedure(s) that now it/they should exit immediately
restart - actually stop+start
status - maybe via status table indicating e.g. records_processed/records_to_be_processed
Mostly I need this stop so what would be the best way to write "exit" for stored procedure? I would like to avoid the following approach:
SELECT sid, serial# , username, schemaname, osuser FROM gv$session;
ALTER SYSTEM KILL SESSION '<sid>,<serial#>' IMMEDIATE;
/paavo
Edited by: paavo on Jul 13, 2009 11:35 AM - added status to subject :)paavo wrote:
Thank you, very good references, but still I think my challenge persist on stop still because I try to do this without the rights to v$session etc. tables.
So what would be the best way to deliver stop-message to executing stored procedure. E.g.
- via table which is regularly checked by stored procedure (e.g. in loop it selects from the table)
/paavoI think for stopping such a procedure you have only two sensible possibilities.
First option is to kill the session. For this you or the logic that does the kill needs the appropriate rights to do it.
Second option would be to programm this behaviour. The procedure can listen to a kind of signal and if it gets that signal it is stopped. This signal can be a value in a parameter table, but it can also be a message in some pipe/advanced queue. However this means the procedure will stop only at certain defined points (whenever it checks for the stop signal).
Btw: You didn't mention what is the business case behind that technical request. Maybe you can elaborate a little on that too. -
I select the shared datasource from the data source propeties dialog, test the connection and everything is good.
I add a dataset by selecting "use a dataset embedded in my report" option within the Dataset properties dialog.
I select the newly added data source, click the "Stored procedure" query type and drop down the list box and select my intended stored procedure.
the timeout for the dataset is "0" seconds.
I click the "OK" button and I'm presented with the parameters to the stored procedure.
I enter valid data for the parameters and click the "OK" button.
I then get the following error message after 30 seconds:
The problem is, all of the timeouts, that I'm aware of, have values of zero (no timeout) or high enough values that 30 seconds isn't even close to the timeout.
I think the smallest timeout we have is 120 seconds.
I have searched this site and many others and the solutions all involve altering the stored procedure to get the fields into report builder and then revert the stored procedure back to its original form.
To me, this is NOT a solution.
I have too many stored procedures that need to be brought into Report Builder.
I need a real solution.
Thank you for you time, Tim Caldwell.
Timothy E CaldwellI don't mean to be rude, but really, check to see if the stored procedure can return data rows???
Maybe I'm not being clear enough.
The stored procedure runs perfectly fine.
it runs perfectly fine in the production environment and the test environment.
I can access the stored procedure in several ways and have it return correct data.
I can even trick report builder into creating a dataset with parameters and run the stored procedure that way.
What I cannot do, is to get report builder to not timeout after 30 seconds on the initial creation of a dataset with a Query type of stored procedure.
I have seen this issues posted again and again and again on may different sites and the "solution" is to simplifiy the stored procedure by creating a stored procedure that has a create table and a select in the stored procedure and that's it. After
report builder creates the dataset the developer then has to replace the simplified stored procedure with the actual stored procedure and everything works fine after that.
HOWEVER, having to go through this process for 70 or more stored procedures is ridiculous.
It would appear that there is something within report builder itself that is causing this issue.
The SQL Script included is an example of a stored procedure that will not create fields create a dataset with fields and parameters in Report Builder 3.0:
USE [CRUM_IT]
GO
/****** Object: StoredProcedure [dbo].[COGNOS_Level5ScriptSP] Script Date: 11/17/2014 08:02:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER procedure [dbo].[COGNOS_Level5ScriptSP]
@CompanyCode varchar(8) = null,
@GetSiblings varchar(1) = 'N'
as
Begin
-- get emergency contact info
select *
into #tmp_Contacts
from
(select
ConEEID,
con.connamelast as [Emer Contact Last Name],
con.connamefirst as [Emer Contact First Name],
con.connamemiddle as [Emer Contact Middle Initial/Name]--,
,ROW_NUMBER() over (Partition by ConEEID order by ConNameLast)as rn
,ISNULL(
case when con.conphonepreferred = 'H'
then '(' + substring(con.conphonehomenumber, 1, 3) + ')' + substring(con.conphonehomenumber, 4, 3) + '-' + substring(con.conphonehomenumber, 7, 4)
else '(' + substring(con.conphoneothernumber , 1, 3) + ')' + substring(con.conphoneothernumber , 4, 3) + '-' + substring(con.conphoneothernumber , 7, 4)
end,
) as [Emergency Phone]
from [ultiprosqlprod1].[ultipro_crum].dbo.Contacts con
where con.ConIsEmergencyContact='y'
and con.ConIsActive='y'
) A
where A.rn = 1
CREATE TABLE #tmp_CompanyCodes (CompanyCode varchar(8))
If @GetSiblings = 'Y'
Begin
INSERT INTO #tmp_CompanyCodes (CompanyCode)
EXEC [z_GetClientNumbers_For_ParentOrg_By_ClientNumber] @CompanyCode
End
INSERT INTO #tmp_CompanyCodes
values (@CompanyCode)
select *
into #tmp_Company
from [ultiprosqlprod1].[ultipro_crum].dbo.Company
where cmpcompanycode in (select CompanyCode from #tmp_CompanyCodes)
select distinct
cmpcompanycode as [Client ID],
CmpCompanyDBAName as [Client Name],
eec.eecEmplStatus AS [Employment Status],
eec.eecEmpNo AS [Employee Num],
rtrim(eep.eepNameLast) AS [Last Name],
rtrim(eep.eepNameFirst) AS [First Name],
isnull(rtrim(ltrim(eep.eepNameMiddle)), '') AS [Middle Initial/Name],
rtrim(eep.eepAddressLine1) AS [Address Line 1],
isnull(rtrim(eep.eepAddressLine2), '') AS [Address Line 2],
eep.eepAddressCity AS [City],
eep.eepAddressState AS [State],
CASE
WHEN len(eep.eepAddressZipCode) > 5 and charindex(eep.eepAddressZipCode, '-', 1) = 0
THEN substring(eep.eepAddressZipCode, 1, 5)
ELSE rtrim(eep.eepAddressZipCode)
END AS [Zip code],
CASE
WHEN len(eep.eepAddressZipCode) > 5 and charindex(eep.eepAddressZipCode, '-', 1) = 0
THEN substring(eep.eepAddressZipCode, 6, 4)
WHEN len(eep.eepAddressZipCode) > 5 and charindex(eep.eepAddressZipCode, '-', 1) > 0
THEN substring(eep.eepAddressZipCode, charindex(eep.eepAddressZipCode, '-', 1) + 1, 4)
WHEN len(eep.eepAddressZipCode) <= 5
THEN ''
END AS [ZIP + 4],
substring(eep.eepSSN, 1, 3) + '-' + substring(eep.eepSSN, 4, 2) + '-' + substring(eep.eepSSN, 6, 4) AS [SSN],
isnull(convert(VARCHAR(10), eep.eepDateOfBirth, 101), '') AS [Date Of Birth],
eetFED.TAXCODE AS [FED Tax Code],
eetFED.FILINGSTATUS AS [Fed Filing Status],
eetFED.EXEMPTIONS AS [Fed Exemption Allowance],
eetFED.ADDITIONAL AS [Additional Fed Withholding],
eetSIT.TAXCODE AS [SIT Tax Code],
eetSIT.FILINGSTATUS AS [State Filing Status],
eetSIT.EXEMPTIONS AS [State Exemption Allowance],
eetSIT.ADDITIONAL AS [Additional State Withholding],
isnull('(' + substring(eep.eepPhoneHomeNumber, 1, 3) + ')' + substring(eep.eepPhoneHomeNumber, 4, 3) + '-' + substring(eep.eepPhoneHomeNumber, 7, 4), '') AS [Home Phone],
isnull((SELECT cod.codDesc
FROM [ultiprosqlprod1].[ultipro_crum].dbo.Codes cod WITH (NOLOCK)
WHERE cod.codCode = eep.eepEthnicID
AND cod.codDosTable = 'ETHNICCODE'), '') AS [Race-Origin], --eep.eepEthnicID AS [Race-Origin],
eep.eepGender AS [Gender],
isnull(convert(VARCHAR(10), eec.eecDateOfOriginalHire, 101), '') AS [Original Hire Date],
isnull(convert(VARCHAR(10), eec.eecDateOfSeniority, 101), '') AS [Seniority Date],
isnull(convert(VARCHAR(10), eec.eecDateOfTermination, 101), '') AS [Termination Date],
isnull(eecTermType,'') as [Termination Type],
isnull(TchDesc, '') as [Termination Reason],
rtrim(eec.eecJobCode) AS [WC Code],
isnull(eec.eecJobTitle, '') AS [Job Title],
pgr.pgrPayFrequency AS [Pay Frequency],
eec.eecFullTimeOrPartTime AS [Full/Part Time],
eec.eecSalaryOrHourly AS [Pay Type],
isnull(convert(MONEY, eec.eecHourlyPayRate), 0.00) AS [Hourly Rate],
isnull(eec.eecAnnSalary, 0.00) AS [Annual Salary],
[YTD Hours],
isnull(eep.eepNameFormer, '') AS [Maiden Name],
eec.eecLocation AS [Location ID],
rtrim(eec.eecOrgLvl1) AS [Department ID],
eec.eecorglvl2 AS [Cost Item],
eec.eecorglvl3 as [Client Project],
eec.eecPayGroup as [Pay Group],
isnull(eepAddressEMail,' ') as [Email Address],
isNull(BankName1,' ') as PrimaryBank,
isNull(BankRoute1,' ') as PrimaryRouteNum,
isNull(Account1,' ') as PrimaryAccount,
isNull(AcctType1,' ') as PrimaryAcctType,
isNull(DepositRule1,' ') as PrimaryDepositRule,
isNull(BankName2,' ') as SecondaryBank,
isNull(BankRoute2,' ') as SecondaryRouteNum,
isNull(Account2,' ') as SecondaryAccount,
isNull(AcctType2,' ') as SecondaryAcctType,
isNull(DepositRule2,' ') as SecondaryDepositRule,
isNull(
CASE
WHEN DepositRule2 = 'D'
THEN '$' + convert(varchar, cast(EddAmtOrPct2 AS decimal(10,2)))
WHEN DepositRule2 = 'P'
THEN convert(varchar, cast((EddAmtOrPct2*100) AS decimal(10,0))) + '%'
ELSE null
END,' ') as SecondaryDepositAmount,
isNull(BankName3,' ') as ThirdBank,
isNull(BankRoute3,' ') as ThirdRouteNum,
isNull(Account3,' ') as ThirdAccount,
isNull(AcctType3,' ') as ThirdAcctType,
isNull(DepositRule3,' ') as ThirdDepositRule,
isNull(
CASE
WHEN DepositRule3 = 'D'
THEN '$' + convert(varchar, cast(EddAmtOrPct3 AS decimal(10,2)))
WHEN DepositRule3 = 'P'
THEN convert(varchar, cast((EddAmtOrPct3*100) AS decimal(10,0))) + '%'
ELSE null
END,' ') as ThirdDepositAmount,
Supervisor,
eec.eecEEID AS [Employee EEID],
eec.EecJobCode As [Job Code],
isnull(eec.EecTimeclockID,' ') As [Time Clock ID],
con.[Emer Contact Last Name],
con.[Emer Contact First Name],
con.[Emer Contact Middle Initial/Name],
con.[Emergency Phone]
from [ultiprosqlprod1].[ultipro_crum].dbo.empPers eep WITH (NOLOCK)
inner join [ultiprosqlprod1].[ultipro_crum].dbo.empComp eec WITH (NOLOCK)
ON eep.eepEEID = eec.eecEEID
inner join #tmp_Company cmp WITH (NOLOCK)
ON eec.eecCOID = cmp.cmpCOID
inner join [ultiprosqlprod1].[ultipro_crum].dbo.PayGroup pgr WITH (NOLOCK)
ON eec.eecPayGroup = pgr.pgrPayGroup
left outer join [ultiprosqlprod1].[ultipro_crum].dbo.TrmReasn
on tchCode = eecTermReason
left join (select CAST(sum(isnull(eee.eeeYTDHrs,0.00))AS DECIMAL(18,2)) as [YTD Hours],
eeeEEID,
eeeCOID
from [ultiprosqlprod1].[ultipro_crum].dbo.EmpEarn eee with (NOLOCK)
group by eeeCOID,eeeEEID)eee
on eec.eecEEID = eee.eeeEEID
and eec.eecCOID = eee.eeeCOID
left join (SELECT eetCOID AS COID,
eetEEID AS EEID,
eetTaxCode AS TAXCODE,
eetFilingStatus AS FILINGSTATUS,
eetExemptions AS EXEMPTIONS,
eetExtraTaxDollars AS ADDITIONAL
FROM [ultiprosqlprod1].[ultipro_crum].dbo.empTax WITH (NOLOCK)
WHERE eetTaxCode = 'USFIT'
)eetFED
ON eec.eecCOID = eetFED.COID
and eec.eecEEID = eetFED.EEID
left join (SELECT eetCOID AS COID,
eetEEID AS EEID,
eetTaxCode AS TAXCODE,
eetFilingStatus AS FILINGSTATUS,
eetExemptions AS EXEMPTIONS,
eetExtraTaxDollars AS ADDITIONAL
FROM [ultiprosqlprod1].[ultipro_crum].dbo.empTax WITH (NOLOCK)
WHERE eetTaxCode like '%SIT'
AND eetIsWorkInTaxCode = 'Y'
)eetSIT
ON eec.eecCOID = eetSIT.COID
and eec.eecEEID = eetSIT.EEID
left outer join (SELECT eddCOID,
eddEEID,
eddEEBankName BankName1,
eddEEBankRoute BankRoute1,
eddAcct Account1,
EddAcctType AcctType1,
EddDepositRule DepositRule1,
EddAmtOrPct EddAmtOrPct1
FROM [ultiprosqlprod1].[ultipro_crum].dbo.EmpDirDp WITH (NOLOCK)
WHERE eddSequence = '99')edd
ON eec.eecCOID = edd.eddCOID
and eec.eecEEID = edd.eddEEID
left outer join (SELECT eddCOID,
eddEEID,
eddEEBankName BankName2,
eddEEBankRoute BankRoute2,
eddAcct Account2,
EddAcctType AcctType2,
EddDepositRule DepositRule2,
EddAmtOrPct EddAmtOrPct2
FROM [ultiprosqlprod1].[ultipro_crum].dbo.EmpDirDp WITH (NOLOCK)
WHERE eddSequence = '01')edd2
ON eec.eecCOID = edd2.eddCOID
and eec.eecEEID = edd2.eddEEID
left outer join (SELECT eddCOID,
eddEEID,
eddEEBankName BankName3,
eddEEBankRoute BankRoute3,
eddAcct Account3,
EddAcctType AcctType3,
EddDepositRule DepositRule3,
EddAmtOrPct EddAmtOrPct3
FROM [ultiprosqlprod1].[ultipro_crum].dbo.EmpDirDp WITH (NOLOCK)
WHERE eddSequence = '02')edd3
ON eec.eecCOID = edd3.eddCOID
and eec.eecEEID = edd3.eddEEID
left outer join (SELECT eecCOID,
eecEEID,
rtrim(eepNameLast) + ', ' +
rtrim(eepNameFirst) + ' ' +
isnull(rtrim(ltrim(eepNameMiddle)), '') AS [Supervisor]
FROM [ultiprosqlprod1].[ultipro_crum].dbo.EmpComp WITH (NOLOCK)
join [ultiprosqlprod1].[ultipro_crum].dbo.EmpPers with (NoLock)
on eeceeid = eepeeid)eec2
ON eec.eecSupervisorID = eec2.eecEEID
left outer join #tmp_Contacts con
on eep.eepEEID = con.ConEEID
order by [Client ID],
[Last Name],
[First Name]
drop table #tmp_Contacts
END
Timothy E Caldwell -
How to create a stored procedure and use it in Crystal reports
Hi All,
Can anyone explain me how to create a stored procedure and use that stored procedure in Crystal reports. As I have few doubts in this process, It would be great if you can explain me with a small stored proc example.
Thanks in advance.If you are using MSSQL SERVER then try creating a stored procedure like this
create proc Name
select * from Table
by executing this in sql query analyzer will create a stored procedure that returns all the data from Table
here is the syntax to create SP
Syntax
CREATE PROC [ EDURE ] procedure_name [ ; number ]
[ { @parameter data_type }
[ VARYING ] [ = default ] [ OUTPUT ]
] [ ,...n ]
[ WITH
{ RECOMPILE | ENCRYPTION | RECOMPILE , ENCRYPTION } ]
[ FOR REPLICATION ]
AS sql_statement [ ...n ]
Now Create new report and create new connection to your database and select stored procedure and add it to the report that shows all the columns and you can place the required fields in the report and refresh the report.
Regards,
Raghavendra
Edited by: Raghavendra Gadhamsetty on Jun 11, 2009 1:45 AM -
How to create stored procedures and use those in Crystal reports
Hi All,
Can anyone explain me how to create a stored procedure and use that stored procedure in Crystal reports. As I have few doubts in this process, It would be great if you can explain me with a small stored proc example.
Thanks in advance.Hello,
There is a document explainining how to use Oracle stored proc with Crystal reports.
Check at:
https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/1084c536-711e-2b10-e48a-924a60745253
It is for older version but it should work and you can refer to it to get general idea how to start with it. It has a sample oracle stored proc and how to connect it from Crystal Reports. -
Hello,
I have a request to create a user login and restrict that user to only be able to execute a single stored procedure.
Is this possible using only TSQL commands?
Am i on the right track here?
USE MyDatabase
GO
CREATE LOGIN [mylogin] DEFAULT_DATABASE = [MyDatabase], CHECK_POLICY = OFF, CHECK_EXPIRATION = OFF
GO
CREATE ROLE exec_single_proc_role
GO
exec sp_addrolemember 'exec_single_proc_role', 'mylogin'
GO
CREATE SCHEMA [restricted] AUTHORIZATION mylogin
GO
GRANT EXECUTE ON SCHEMA::restricted TO exec_single_proc_role
GOThanks for the reply.
This particular user should need to be able to Alter, Execute, and View the stored procedure as well.
Here is what i ended up with: Any improvement are appreciated. Thanks
USE MyDatabase
GO
--DROP SCHEMA
IF EXISTS (SELECT * FROM sys.schemas WHERE name = N'restricted')
DROP SCHEMA [restricted]
GO
--DROP SERVER WIDE LOGIN
IF EXISTS (SELECT * FROM sys.server_principals WHERE name = N'MyUserLogin')
DROP LOGIN [MyUserLogin]
GO
--CREATE SERVER WIDE LOGIN
CREATE LOGIN [MyUserLogin] WITH PASSWORD = 0x0100F1CF6792E602EF40DFF55983FDE81A9 HASHED, SID = 0xC33B04EECE59DC4C95BE66ED9B15D13D, DEFAULT_DATABASE = [MyDatabase], CHECK_POLICY = OFF, CHECK_EXPIRATION = OFF
GO
--DROP ROLE
DECLARE @RoleName sysname
set @RoleName = N'exec_single_proc_role'
IF EXISTS (SELECT * FROM sys.database_principals WHERE name = @RoleName AND type = 'R')
Begin
DECLARE @RoleMemberName sysname
DECLARE Member_Cursor CURSOR FOR
select [name]
from sys.database_principals
where principal_id in (
select member_principal_id
from sys.database_role_members
where role_principal_id in (
select principal_id
FROM sys.database_principals where [name] = @RoleName AND type = 'R' ))
OPEN Member_Cursor;
FETCH NEXT FROM Member_Cursor
into @RoleMemberName
WHILE @@FETCH_STATUS = 0
BEGIN
exec sp_droprolemember @rolename=@RoleName, @membername= @RoleMemberName
FETCH NEXT FROM Member_Cursor
into @RoleMemberName
END;
CLOSE Member_Cursor;
DEALLOCATE Member_Cursor;
End
IF EXISTS (SELECT * FROM sys.database_principals WHERE name = N'exec_single_proc_role' AND type = 'R')
DROP ROLE [exec_single_proc_role]
GO
--DROP USER
IF EXISTS (SELECT * FROM sys.database_principals WHERE name = N'MyUserLogin')
DROP USER [MyUserLogin]
GO
--CREATE USER AND ASSIGN DEFAULT SCHEMA
CREATE USER [MyUserLogin] FOR LOGIN [MyUserLogin] WITH DEFAULT_SCHEMA=[restricted]
GO
--CREATE SCHEMA
CREATE SCHEMA [restricted] AUTHORIZATION [MyUserLogin]
GO
--CREATE ROLE
CREATE ROLE [exec_single_proc_role] AUTHORIZATION [MyUserLogin]
GO
--ADD ROLE
EXEC sp_addrolemember 'exec_single_proc_role', [MyUserLogin]
GO
GRANT EXECUTE ON SCHEMA::[restricted] TO [exec_single_proc_role]
GO
GRANT EXECUTE ON OBJECT::[dbo].[MyStoredProcedure] TO [MyUserLogin]
GO -
Creating and calling stored procedure using jdbc
When I try to create and call a stored procedure using JDBC a very confusing error message about non-existence of the procedure just created is thrown. Using Informix database (IDS 10). Any pointers to point out what am doing wrong would be great!
Thanks
import java.io.FileNotFoundException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Scanner;
public class CreateStoredProc {
public static void main(String args[]){
if (0 == args.length)
return;
try {
Class.forName("com.informix.jdbc.IfxDriver");
Connection conn = DriverManager.getConnection("jdbc:informix-sqli://10.76.244.120:30000/sampledb:INFORMIXSERVER=krisunda;user=root;password=cisco");
String q = " create procedure runproc() "+
" define i int; "+
" let i = 0; "+
" end procedure; "+
" execute procedure runproc(); ";
Statement stmt = conn.createStatement ();
stmt.execute (q);
} catch (Exception e) {
e.printStackTrace();
The stack trace:
java.sql.SQLException: Routine (runproc) can not be resolved.
at com.informix.jdbc.IfxSqli.a(IfxSqli.java:3204)
at com.informix.jdbc.IfxSqli.E(IfxSqli.java:3518)
at com.informix.jdbc.IfxSqli.dispatchMsg(IfxSqli.java:2353)
at com.informix.jdbc.IfxSqli.receiveMessage(IfxSqli.java:2269)
at com.informix.jdbc.IfxSqli.executeExecute(IfxSqli.java:2157)
at com.informix.jdbc.IfxSqli.executeExecute(IfxSqli.java:2132)
at com.informix.jdbc.IfxResultSet.b(IfxResultSet.java:378)
at com.informix.jdbc.IfxStatement.a(IfxStatement.java:1299)
at com.informix.jdbc.IfxStatement.executeImpl(IfxStatement.java:1269)
at com.informix.jdbc.IfxStatement.c(IfxStatement.java:989)
at com.informix.jdbc.IfxStatement.execute(IfxStatement.java:875)
at CreateStoredProc.main(CreateStoredProc.java:37)
Caused by: java.sql.SQLException
at com.informix.util.IfxErrMsg.getSQLException(IfxErrMsg.java:373)
at com.informix.jdbc.IfxSqli.E(IfxSqli.java:3523)
... 10 moreDriverManager.getConnection("jdbc:informix-sqli://10.76.244.120:30000/sampledb:INFORMIXSERVER=krisunda;user=root;password=cisco");check with ur sys admin wheather the particular user in the database has >execute privilage(rights) also.i mean execute the SP in the DB level.I guess that a root user will have the enough right.
String q = " create procedure runproc() "+
" define i int; "+<" let i = 0; "+
" end procedure; "+
" execute procedure runproc(); ";
Statement stmt = conn.createStatement ();
stmt.execute (q);Try to use the following code:
String q = " create procedure runproc() "+
" define i int; "+
" let i = 0; "+
" end procedure; "
Statement stmt = conn.createStatement ();
stmt.execute (q);
q=" execute procedure runproc(); ";
stmt.execute (q);
Because maybe the driver failed to precompile your sql once, so that nothing happen. -
Oracle 8i and stored procedures
Hi I was hoping someone could point me to the right direction here.
I have been using SQL server before and often use stored procedures. I understand that if you want to use stored procedures you will use the CallableStatement object and the prepareCall method of the Connection object like so:
let's say my stored proc has 2 number parameters:
CallableStatement cs = con.prepareCall( " { call <stored_proc_name> (?, ?) } );
cs.getString(1, 1);
cs.getString(2, 2);
ResultSet rs = cs.executeQuery( );
where con is my connection object that i used to connect to my database. So far am I right with the following code?
But my problem is I have to use Oracle 8i. So what is the equivalent of SQL server stored procs in Oracle? Is it functions? Procedures? Or Java Stored Procedures? I have been reading all these sites and the forums for ideas but still haev no clue what approach I should take
I have managed to connect to my db using the thin drivers and have successfully passed SQL statements. Although, I don't want to pass SQL statements, I want to use stored procedures. With SQL server I would create all my stored procedures and use my beans to call these stored procedures. So as a new user of Oracle 8i coming form SQL server, what approach do I use and how?
Thanks in advance for all the help!Alright well looks like I'm stuck now.
This seems more like a PL\SQL question though. If I want to return 2 or more values do I use function or a procedure? here's the code I made:
CREATE OR REPLACE FUNCTION sign_in(username VARCHAR(20), userpassword VARCHAR(20))
RETURN NUMBER IS id_num NUMBER, user_type VARCHAR(1);
BEGIN
SELECT * INTO id_num, user_type
FROM ID_MASTER idm, PERSON prs
WHERE USERNAME = username
AND USER_PASSWORD = userpassword
AND idm.ID_NUM = prs.ID_NUM;
RETURN id_num, user_type;
END;
now according to Oracle this is an invalid function. But the error message doesn't say much. Basically I want to pass 2 parameters to use for a query and return 2 variables from the result of the query. Am I suppose to use a procedure?
If I pass paramters do which string do I use to prepareCall: "{ ? = CALL sign_in (?, ?) }" or do I use the "{ CALL sign_in (?, ?) }"
But my problem right now is how to make the proper stored procedure. I'd be very much obliged to anyone who can give a sample. Thank you all for your time! -
So I have a chunk of data that only resides in Oracle. So I need to capture that information from Oracle. Now before you get over zealous, I did try with an OPENQUERY and it took FOREVER! And I don't know why the OPENQUERY took FOREVER but if I run the same
query directly against Oracle it runs very quickly...like 20 seconds.
So now I'm wondering...can I build a dataset in my SSRS Report that uses an Oracle Data source and an Oracle Stored Procedure in its Dataset that I'll create to aggregate this subset of data and then utilize its result set back in my main reporting
Dataset that will utilize SQL Server? And how can I do that? Can I make my main Dataset reference, say, a #TemporaryTable that is created from my Oracle Dataset in its
I'll continue to Google a few things as I await your review and hopefully a reply.
Thanks in advance for your help.Hi ITBobbyP,
According to your description you want to use data from a Oracle data source into a DataSet which retrieving data from SQL Server. Right?
In Reporting Services, we can have multiple data sources in one project pointing to different database. And we can use separated dataset to retrieve data from different data source. However, it's not supported to combine the two datasets together
directly. We can only use Lookup(), LookupSet() function to combine fields from different dataset into one tablix when there are common columns between two datasets. This is the only way to make tow result sets together in SSRS.
Reference:
Lookup Function (Report Builder and SSRS)
LookupSet Function (Report Builder and SSRS)
Best Regards,
Simon Hou
TechNet Community Support
Maybe you are looking for
-
Ipod nano 4th not recognized by itunes or windows
Okay so I have had my iPod Nano 4th generation since it like came out. Recently it has been odd turning off on its own and this morning i turned it on and then put it to sleep. It kept flashing in between asleep and awake. Then I bought new music on
-
How to remove duplicate photos with Elements and Revel?
While on vacation this year, I uploaded pictures from my camera to my iPad to Revel. When I got home, I copied all of the pictures from my camera to my harddrive on my laptop and imported them into Elements 12. On my laptop I store photos in subdir
-
As I said earlier I have a problem. I told it to Jampe - a moderator - but his solution didn't solve my issue. The Problem is that I have two new updates for my mobile ""NOKIA C7"" . The first one is Microsoft apps & the other one is social but I can
-
Problem saving "space" in ABAP TRANSFER statement
Hello all, I have an internal table that I loop through and write that data to a file using TRANSFER statement. Here is an exmaple of my code: data: l_xml_out type string. BEGIN OF itab_out OCCURS 0, record(some length) TYPE c,
-
Quality inspection without order confirmation
hi ther ........ I have created a process order & released it. Now I am able to do quality result recording in QEN51N & Usage dicision in QA11 without process order confirmation. how come this is possible without system throwing any kind of error ?