User define function for SQL Server
Hi all,
it's possible to write an UDF for SQL Server in Java?
I know that it is possible with DB2 and Oracle.
My main goal is to write an UDF that works well with all of these DB.
Thank's
Hi all,
it's possible to write an UDF for SQL Server in
Java?Okay, JDBC can talk to any database (given you have a driver implementation). Also, JDBC is like a conduit. So the real question is likely, will your database let you do this?
I know that it is possible with DB2 and Oracle.
My main goal is to write an UDF that works well with
all of these DB.I also don't know what a UDF is, but if you ARE talking about stored procedures, then no, it's not possible. All databases are different. On that note, I typically recommend NEVER using stored procedures unless absolutely necessary.
But it also sounds like you want to do this at runtime. I've seen systems that do this (bind stored procs at runtime dynamically) and it's a freakin nightmare! So be careful.
Similar Messages
-
How to create user defined metrics for SQL Server target?
The customer is not able to create a user defined metrics for SQL Server target.
This is very important for him to use this product.
He is asking how to create user defined metrics?
I sent him Note 304952.1 How to Create a User-Defined SQL Metric in EM 10g Grid Control
But it would work for an Oracle DB, but his target is SQL Server DB
Not able to find the "User-Defined Metrics" link from Database home page.
How to create user defined metrics for SQL Server target?http://download-uk.oracle.com/docs/cd/B14099_19/manage.1012/b16241/Monitoring.htm
-
How to Use Sequence Object Inside User-defined Function In SQL Server
I'm trying to call sequence object inside SQL Server user-defined function. I used
Next Value for dbo.mySequence to call the next value for my sequence created. But I'm getting an error like below.
"NEXT VALUE FOR function is not allowed in check constraints, default objects, computed columns, views, user-defined functions, user-defined aggregates, user-defined table types, sub-queries, common table expressions, or derived tables."
Is there any standard way to call sequence inside a function?
I would really appreciate your response.
Thanks!The NEXT
VALUE FOR function cannot be used for User Defined function. It's one of the limitation.
https://msdn.microsoft.com/en-us/library/ff878370.aspx
What are you trying to do? Can you give us an example and required output?
--Prashanth -
Creating user defined function in sql server 2000
I have created a udf an i want to call it in another udf. will u please help me out how to create.
thank youAnd you ask that in an ORACLE forum? Brilliant idea... ;)
-
Using User Defined Function is SQL
Hi
I did the following test to see how expensive it is to use user defined functions in SQL queries, and found that it is really expensive.
Calling SQRT in SQL costs less than calling a dummy function that just returns
the parameter value; this has to do with context switchings, but how can we have
a decent performance compared to Oracle provided functions?
Any comments are welcome, specially regarding the performance of UDF in sql
and for solutions.
create or replace function f(i in number) return number is
begin
return i;
end;
declare
l_start number;
l_elapsed number;
n number;
begin
select to_char(sysdate, 'sssssss')
into l_start
from dual;
for i in 1 .. 20 loop
select max(rownum)
into n
from t_tdz12_a0090;
end loop;
select to_char(sysdate, 'sssssss') - l_start
into l_elapsed
from dual;
dbms_output.put_line('first: '||l_elapsed);
select to_char(sysdate, 'sssssss')
into l_start
from dual;
for i in 1 .. 20 loop
select max(sqrt(rownum))
into n
from t_tdz12_a0090;
end loop;
select to_char(sysdate, 'sssssss') - l_start
into l_elapsed
from dual;
dbms_output.put_line('second: '||l_elapsed);
select to_char(sysdate, 'sssssss')
into l_start
from dual;
for i in 1 .. 20 loop
select max(f(rownum))
into n
from t_tdz12_a0090;
end loop;
select to_char(sysdate, 'sssssss') - l_start
into l_elapsed
from dual;
dbms_output.put_line('third: '||l_elapsed);
end;
Results:
first: 303
second: 1051
third: 1515
Kind regards
TaoufikI find that inline SQL is bad for performance but
good to simplify SQL. I keep thinking that it should
be possible somehow to use a function to improve
performance but have never seen that happen.inline SQL is only bad for performance if the database design (table structure, indexes etc.) is poor or the way the SQL is written is poor.
Context switching between SQL and PL/SQL for a User defined function is definitely a way to slow down performance.
Obviously built-in Oracle functions are going to be quicker than User-defined functions because they are written into the SQL and PL/SQL engines and are optimized for the internals of those engines.
There are a few things you can do to improve function
performance, shaving microseconds off execution time.
Consider using the NOCOPY hints for your parameters
to use pointers instead of copying values. NOCOPY
is a hint rather than a directive so it may or may
not work. Optimize any SQL in the called function.
Don't do anything in loops that does not have to be
done inside a loop.Well, yes, but it's even better to keep all processing in SQL where possible and only resort to PL/SQL when absolutely necessary.
The on-line documentation has suggested that using a
DETERMINISTIC function can improve performance but I
have not been able to demonstrate this and there are
notes in Metalink suggesting that this does not
happen. My experience is that DETERMINISTIC
functions always get executed. There's supposed to
be a feature in 11g that acually caches function
return values.Deterministic functions will work well if used in conjunction with a function based index. That can improve access times when querying data on the function results.
You can use DBMS_PROFILER to get run-time statistics
for each line of your function as it is executed to
help tune it.Or code it as SQL. ;) -
User defined function for getting last string in the line
Hi Experts,
I am not java expert, can anyone give me user defined function for getting last string in the line.
for example if the source field is "NEW ARBOUR SQUARE" i want to pass to target field only last string that is "SQUARE"
please help me out of this.
Kind Regards.
Praveen.You don't even need a UDF for this. In the graphical editor look for the standard functions and once you do a scroll over on 'text functions; you will find what you are looking for.
Just a piece of advice, try keeping UDF's to minimum unless really required or it is complicated without it.
regards -
SQL User Defined Functions for performing statistical calculations
Hi!
I hope you can help. I just wasn’t sure where to go with this question, so I’m hoping you can at least point me in the right direction.
I’m writing a SQL Server stored procedure that returns information for a facility-wide scorecard-type report. The row and columns are going to be displayed in a SQL Server Reporting Services report.
Each row of information contains “Current Month” and “Previous Month” numbers and a variance column. Some rows may compare percentages, others whole numbers, others ratios, depending on the metric they’re measuring. For each row/metric the company has specified whether they want to see a t-test or a chi-squared statistical test to determine whether or not there was a statistically significant difference between the current month and the previous month.
My question is this: Do you know where I can find a set of already-written user defined functions to perform statistical calculations beyond the basic ones provided in SQL Server 2005? I’m not using Analysis Services, so what I’m looking for are real SQL User Defined Functions where I can just pass my data to the function and have it return the result within a stored procedure.
I’m aware that there may be some third-party statistical packages out there we could purchase, but that’s not what I’m looking for. And I’m not able to do anything like call Excel’s analysis pack functions from within my stored procedure. I’ve asked. They won’t let me do that. I just need to perform the calculation within the stored procedure and return the result.
Any suggestions? Is there a site where people are posting their SQL Server UDF’s to perform statistical functions? Or are you perhaps aware of something like a free add-in for SQL that will add statistical functions to those available in SQL? I just don’t want to have to write my own t-test function or my own chi-squared function if someone has already done it.
Thanks for your help in advance! Oh, and please let me know if this should have been posted in the TSQL forum instead. I wasn't entirely sure.
Karen GrubeSTATS_T_TEST_
docs.oracle.com/cd/B19306_01/server.102/b14200/functions157.htm
STATS_T_TEST_ONE: A one-sample t-test
STATS_T_TEST_PAIRED: A two-sample, paired t-test (also known as a crossed t-test)
STATS_T_TEST_INDEP: A t-test of two independent groups with the same variance (pooled variances)
STATS_T_TEST_INDEPU: A t-test of two independent groups with unequal variance (unpooled variances) -
How to use evaluate function for sql server function
Hi Team,
We have imported a column(date dtat type) from SQL server cube . By default it imported as varchar,. We have three option in physical layer for this column(Varchar,Intiger,unknown)
So we want to convert this column into date.can we use evaluate or there is any option to do that.?Hi,
I am not sure your requirement. But how pass evaluate function obiee?
syntax:- EVAULATE('your db function(%1,%2)', parameter list)
here %1 and %2 are the no.of parameters (columns or may constant values) to be passed for the db-function
if you have 3 parameters then you need to use %3 also.. means the columns to be passed.
following exapmples are for ORACLE db,
ex1: EVALUATE('upper(%1)', 'satya ranki reddy') gives the result as -> SATYA RANKI REDDY
ex2: EVALUATE('upper(%1)', 'Markets.Region') here Markets.Region is column.
you also can call the user-defined functions through evaulate
EVALUATE('functioname(%1,%2), column1, column2)
the above function has 2 parameters to be inputted
Hope this help's
Thanks
Satya -
Error in User defined function for dynamic file naming
Hi,
While creating User Defined function with this following code for dynamic fieldname
DynamicConfiguration conf = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
DynamicConfigurationKey key = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File","FileName");
String ourSourceFileName = conf.get(key);
return ourSourceFileName;
which options should i select for cache Value, Context, Queue
for Augument , what name shd i mention.
Regards,
VarunHi Varun,
I guess I have answered a similar question just a few minutes before on very similar post from you. Just pasting the same here .................
Are you trying to access the ASMA values from the SOAP header of the XI message for the source file name?
First of all you need to Set the Sender File Adapter for Set ASMA and then file name. So it will work fine when you actually run the scenario end to end.
But in the mapping tool when you test the mapping - there is not message header updated with the actual source filename - and whenever you try to read the FileName attribute in the message header from the UDF - it cannot find the object and returns a NullPointerException.
I would suuggest for your mapping tool testing to be successful, have a check in the java code for null values,
DynamicConfiguration conf = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
DynamicConfigurationKey key = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File","FileName");
String ourSourceFileName = conf.get(key);
If (ourSourceFileName != null)
Return ourSourceFileName;
Return "NoFileName.txt";
Let us know if this works.
Regards,
Suddha -
Making a User Defined Function for Mapping in XI
Hi folks..
I knw how to make User defined Function in XI,
i was wondering about can we have any room for making a function for Initializing Purpose, which intializes few fields in source Message to some Global variables, and later we can use these Global Variables to set the the Target field
My Doubt is this...
i have Source & target Structure like this Structure like this....
SOURCE TEST DATA IS...
Parentsrc
child1src a
child2src b
child3src c
child4src hi
child4src hello
child4src hey
(On the basis of instances of child4src the istance of the Parentdst will be generated)
TARGET DATA SHUD BE LIKE THIS....
Parentdst
child1dst a
child2dst b
child3dst c
child4dst hi
Parentdst
child1dst a
child2dst b
child3dst c
child4dst hello
Parentdst
child1dst a
child2dst b
child3dst c
child4dst heyHi
You have to modify your target structure:
<b>Source</b>
Parentsrc
child1src a
child2src b
child3src c
child4src hi
child4src hello
child4src hey
<b>Target</b>
<b>root</b>
Parentdst
child1dst a
child2dst b
child3dst c
child4dst hi
Parentdst
child1dst a
child2dst b
child3dst c
child4dst hello
Parentdst
child1dst a
child2dst b
child3dst c
child4dst hey
<b></root></b>
Now map like this:
child4src -
Parentdst
child1src--|
child4src--| UseOneAsMany -- Splitbyvalue --- child1dst
child4src--|
child2src--|
child4src--|UseOneAsMany --Splitbyvalue --- child2dst
child4src--|
child3src--|
child4src--| UseOneAsMany -- Splitbyvalue --- child3dst
child4src--|
child4src -- SplitbyValue -- child4src.
Regards
Suraj -
Java user-defined function for mapping a complex structure
All,
Hope one of you can help me with this. I have a structure with over 15 fields and would like to concatenate all the fields into one target field and while I do this, I need to ensure that each field is padded with blanks as defined the data type. Can one of tell me if this is possible with a java user-defined function and if so, what type of logic is needed.
Input_MT
Field_1 string len=10 "need"
Field_2 string len=6 "java"
Field_3 string len=7 "help"
Field_4 string len=8 "asap"
etc,
Output_MT
DataOut string "need java help asap "
(for some reason the exact spaces in between the words disappear in my Preview message)
I have several fields in the input mt and therefore I find graphical mapping using concatenate and my own user defined function padWithSpace too messy.
Thank you for you help.Hi,
If your final req is to write all these fields next each other in a file, you can configure this in receiver file adapter by specifying the fixed length for each field.
If you want the padded string as your MM o/p, you can create a simple user defined funtion with 15 fields as input and 15 constants for their lengths, and find out the length of the each string and pad it with required no of spaces.
int max_len = 10;
int actual_len;
actual_len = a.lengh();
for(int i=0; i < (max_len-actual_len; i++)
a = a.append(" ");
return a;
praveen -
User - defined functions for calculating the taxes of state and country
hi expects,
how can write user-defined function in message mapping in which i want to calculate the states taxes (2500) and country taxes (5000) and give the result as grand total in output.please help me?Hi,
Activities
1. To create a new user-defined function, in the data-flow editor, choose Create New Function (This
graphic is explained in the accompanying text), which is located on the lower left-hand side of the
screen. In the menu, choose Simple Function or Advanced Function.
2. In the window that appears, specify the attributes of the new function:
Name
Technical name of the function. The name is displayed in the function chooser and on the data-flow
object.
Description
Description of how the function is used.
Cache
Function type (see above)
Argument Count
In this table, you specify the number of input values the function can process, and name them. All
functions are of type String.
3. In the window that appears, you can create Java source code:
a. You can import Java packages to your methods from the Imports input field, by specifying them
separated by a comma or semi-colon:
You do not need to import the packages java.lang., java.util., java.io., and java.lang.reflect. since
all message mappings require these packages and therefore import them. You should be able to
access standard JDK and J2EE packages of the SAP Web Application Server by simply specifying the
package under Import. In other words, you do not have to import it as an archive into the Integration
Repository. You can also access classes of the SAP XML Toolkit, the SAP Java Connector, and the
SAP Logging Service (see also: Runtime Environment (Java-Mappings)).
In addition to the standard packages, you can also specify Java packages that you have imported as
archives and that are located in the same, or in an underlying software component version as the
message mapping.
b. Create your Java source text in the editor window or copy source text from another editor.
4. Confirm with Save and Close.
5. User-defined functions are limited to the message mapping in which you created the function. To
save the new function, save the message mapping.
6. To test the function, use the test environment.
The new function is now visible in the User-Defined function category. When you select this category,
a corresponding button is displayed in the function chooser pushbutton bar. To edit, delete, or add the
function to the data-flow editor, choose the arrow next to the button and select from the list box
displayed.
Regards
Seshagiri -
Need user define function for the message mapping structure
Hi All
I am new to XI.I need the java code for Udf for the following structure.
i have two input and one out put as error.
order_nos----
user define function-------error message
order_details----
num of orders---- i.e. 10
order_details------ i.e. whole order records details
1.i have to compare the 1st input with 2nd one means if the ist input contain 10 means there are 10 orders in 2nd input.if not then i have to give error message .
2.then i have to check the fields in 2nd input has no null values.if no values the output will be error message.
Edited by: Rohit Kumar on Dec 18, 2008 4:43 PMHi Sudhir
thanks for your continues help.i need some help so that i can fulfill my requirmrnt
this is my message mapping xml.
<?xml version="1.0" encoding="UTF-8" ?>
- <ns0:methodCall_MT xmlns:ns0="http://www.dfdsf">
<num_orders>10</num_orders>
<test_mode />
- <order_x> ( which is order details)
<order_id>t78tyu8t</order_id>
<order_date />
<mfg_id />
<catalog_id />
<first_name />
<last_name />
<recipient />
<message />
<address1 />
<address2 />
<address3 />
<city />
<state />
<zip />
<country />
<country_code />
<phone />
<subtotal />
<tax />
<shipping />
<total />
<shopatron_total />
<fulfiller_total />
<shipment_id />
- <additional_info>
<in_store_pickup />
- <express_shipping>
<express_shipping_flag />
<express_shipping_text />
<express_shipping_arrival />
</express_shipping>
</additional_info>
- <discount>
<discount_description />
<discount_percentage />
<discount_total />
</discount>
<lang_id />
<currency_id />
<packing_list />
<num_items />
- <items>
<item_id />
<quantity />
<price />
<part_number />
<fulfiller_total />
<shopatron_total />
- <options>
<option_x />
</options>
</items>
</order_x>
</ns0:methodCall_MT>
this my mapping where under one element number elements are there.when i am excuting the code to check the null value its always giving the there is null val but i have filled evrything.its due to first its checking the order_x and which will be always null.uder this all data will be filled.please suggest what to change in the udf.the code given by u is working fine but its failing in this scenario because it getting the parent filed is null. -
UDF(user defined function) for standard date transformate function,
Hi All,
Hope you are doing good !!!
I have a requirement where i need to write an UDF(user defined function). Please help me in writing the code for below logic-
I am getting my Input as 111213 where 11 denotes HH 12 denotes mm 13 denotes ss. I need ti insert : between hh:mm:ss
Please help me achieving a code for below logic
I have used standard date transformate function, there i am getting spaces as separator in my input resulting an errors i am sending without spaces.
Regards,
Vijay Kumar.Hello,
I am getting my Input as 111213 where 11 denotes HH 12 denotes mm 13 denotes ss. I need ti insert : between hh:mm:ss
Please help me achieving a code for below logic
I have used standard date transformate function, there i am getting spaces as separator in my input resulting an errors i am sending without spaces.
What do you mean by spaces? Can you try the mapping below?
inputDate -> replaceString -> dateTrans(inputDateFormat: HHmmss outputDateFormat: HH:mm:ss) -> target
Constant: -> /
Constant:-> /
Hope this helps,
Mark -
How to convert Oracle User defined datatype to SQL Server 2014 using SSMA Version 6.0
I am trying to convert Oracle 11g OE schema to SQL Server 2014, using SSMA version 6.0
Getting an error in converting the Oracle View to SQL Server
CREATE OR REPLACE VIEW OC_CUSTOMERS OF OE.CUSTOMER_TYP WITH OBJECT IDENTIFIER (customer_id) AS
SELECT c.customer_id, c.cust_first_name, c.cust_last_name, c.cust_address,
c.phone_numbers,c.nls_language,c.nls_territory,c.credit_limit,
c.cust_email,
CAST(MULTISET(SELECT o.order_id, o.order_mode,
MAKE_REF(oc_customers,o.customer_id),
o.order_status,
o.order_total,o.sales_rep_id,
CAST(MULTISET(SELECT l.order_id,l.line_item_id,
l.unit_price,l.quantity,
MAKE_REF(oc_product_information,
l.product_id)
FROM order_items l
WHERE o.order_id = l.order_id)
AS order_item_list_typ)
FROM orders o
WHERE c.customer_id = o.customer_id)
AS order_list_typ)
FROM customers c
* SSMA error messages:
* O2SS0461: Conversion of object view is not supported.
* OF OE.CUSTOMER_TYP
* WITH OBJECT IDENTIFIER (customer_id)
CREATE VIEW dbo.OC_CUSTOMERS
AS
/*Generated by SQL Server Migration Assistant for Oracle version 6.0.0.*/
* SSMA error messages:
* O2SS0481: Conversion of statement containing user defined type column 'c.cust_address' not supported.
* O2SS0481: Conversion of statement containing user defined type column 'c.phone_numbers' not supported.
* O2SS0430: Conversion of multiset conditions is not supported.
* CAST(MULTISET
* SELECT
* o.order_id,
* o.order_mode,
* MAKE_REF(oc_customers, o.customer_id),
* o.order_status,
* o.order_total,
* o.sales_rep_id,
* CAST(MULTISET
* SELECT
* l.order_id,
* l.line_item_id,
* l.unit_price,
* l.quantity,
* MAKE_REF(oc_product_information, l.product_id)
* FROM order_items l
* WHERE o.order_id = l.order_id
* ) AS order_item_list_typ)
* FROM orders o
* WHERE c.customer_id = o.customer_id
* ) AS order_list_typ)
SELECT
c.CUSTOMER_ID,
c.CUST_FIRST_NAME,
c.CUST_LAST_NAME,
c.cust_address,
c.phone_numbers,
c.NLS_LANGUAGE,
c.NLS_TERRITORY,
c.CREDIT_LIMIT,
c.CUST_EMAIL,
NULL
FROM dbo.CUSTOMERS AS c */
Any suggestion on converting this view would be helpful.
Kind regards.Thanks Lydia Zhang for your reference urls.
Please let me know if you come across any reference articles related to
Creating a SQL Server table and View with columns as SQL Server TVP similar to Oracle UDT like
CREATE TABLE "OE"."CUSTOMERS"
( "CUSTOMER_ID" NUMBER(6,0),
"CUST_FIRST_NAME" VARCHAR2(20 BYTE) CONSTRAINT "CUST_FNAME_NN" NOT NULL ENABLE,
"CUST_LAST_NAME" VARCHAR2(20 BYTE) CONSTRAINT "CUST_LNAME_NN" NOT NULL ENABLE,
"CUST_ADDRESS" "OE"."CUST_ADDRESS_TYP" ,
"PHONE_NUMBERS" "OE"."PHONE_LIST_TYP" ,
"NLS_LANGUAGE" VARCHAR2(3 BYTE),
And also creating a SQL Server TVP inside an another SQL Server TVP as in Oracle
create or replace TYPE customer_typ
AS OBJECT
( customer_id NUMBER(6)
, cust_first_name VARCHAR2(20)
, cust_last_name VARCHAR2(20)
, cust_address cust_address_typ
, credit_limit NUMBER(9,2)
, cust_email VARCHAR2(30)
, cust_orders order_list_typ
NOT FINAL;
Kind regards.
Venkatesha
Maybe you are looking for
-
How can I sync the Mac contacts app with my friends Facebook photos?
Hi, I have an iPhone 5 and and iPad so I'm not to new to Apple products, however i did just get my first MacBook (I'm in love!) I have a question, is it possible to sync the Mac Contacts app with Facebook so that my friends Facebook photos will show
-
Freeing connections in a connection pool
I am using WLS8.1.2 on IA64 with jrockit 8.1.2. I have created a connection pool using Microsoft's type 4 non-xa jdbc driver fpr SQLServer2000. My application performs a number of db operations, then using the retrieved information, makes a call to a
-
HI All, I have a issue with the budget. When ever i have gone thorugh for debugg the issue, i came to know there was a down payment exist for the PO. Is it down payment effect the committment? I have gone through the sdn search also. i got input
-
Function CALCULATE_DATE and leap year
Hi, I need to substract some months from a date. I tried to use the standard function CALCULATE_DATE but it has a proble with leap years. If I execute it with the following parameters: CALL FUNCTION 'CALCULATE_DATE' EXPORTING days
-
Source system connection for DB connect.
hi experts presently the data is available in sql server(legacy system).so we have to extract data from sql server to bw server through DBconnect.tell me the procedure for how to connect sql server to BW server through DB connect.