I want to write SQL UDF with Multiple Lines:
1. Declare variables.
2. Set those variables with select into statement.
3. some if conditions on Variables
4. return some value.
What is the syntax to write this.
I'm using teradata Version 14.00.03.02.
I think it is better for your case to write in java or c or c++.
Few cases I write in SQL. But many I write in Java, because I can reuse in MR jobs in hadoop and few in c,c++. I always run on Linux environment.
That is what they are made of. Love unix and C programming too but I choose java here.For example, there are few udfs I made in java, say like search for a pattern. Compile that java code. Create a function of that java code in Teradata, then use it, similar to the examples above.
So far I have not seen a performance issue. Even if there is a performance issue, you can tweak somehow.
Just to share with you,I have seen people scream about performance issue. It depends how we deal with it. There are many techniques. Only when we bump into issues and we solve them , we remember and find out ways and means.
SQL UDFs are "only" wrapper to encapsulate some SQL code to make code reusable and more readable.
What you descibe sounds much more like a Stored Proceedure
Can anybody help me write an SQL UDF to add days to a date ?
It simply needs to be accepting a date and a number and adding them together to return another date
Please help .
REPLACE FUNCTION ADD_DAYS(p1 DATE, p2 INTEGER)
SQL SECURITY DEFINER
INLINE TYPE 1
RETURN p1 + CAST(p2 AS INTERVAL DAY) ;