SlideShare a Scribd company logo
SCALAR USER DEFINED
FUNCTION IN SAP HANA
Kabilarasan RPresented by
Scalar User Defined Function
 The simplest database object for which you can make use of SQL
Script are Scalar User- Defined Functions (Scalar UDFs)
 Scalar UDFs allow you to the define functions which take a number
of input parameters and return scalar values.
 Only expressions are allowed in the body of the UDF, so no table
operations, CE functions or array operations.
Scalar User-Defined Functions Support
the Following:
 They can have any number of scalar input parameters (primitive SQL types). Input parameters of
table type are not supported.
 They can return multiple scalar values.
 They can contain expressions within their body. Table and array operations are not supported.
 They can be used in the field list or the WHERE clause of SELECT statements — like built-in
functions.
 They are callable via direct assignment in other user-defined functions or stored procedures (x :=
my_scalar_func () ).
 They must be free of side-effects and do not support any type of SQL statement in their body.
Basic Syntax to Define a Scalar User-
Defined Function
CREATE FUNCTION <function name> (<list of input parameters with
type>)
RETURNS <scalar result parameter name and type>
AS BEGIN
<function body>
END;
Note:
 You can create scalar user-defined functions for use like built-in functions.
 Prefix parameter names with “:”to access their values.
create column table "KABIL_PRACTICE"."OVERTIME"
(
"E_ID" integer,
"E_NAME" Nvarchar(35),
"OVERTIME(in_Hrs)" Integer
);
Code:
To Create a table:
To Insert the values into a
table:
Insert into "KABIL_PRACTICE"."OVERTIME" values
(1,'Kabil',20);
Insert into "KABIL_PRACTICE"."OVERTIME" values
(2,'Nazeer',15);
Insert into "KABIL_PRACTICE"."OVERTIME" values
(3,'Kalai',10);
To Create function:
Create Function "KABIL_PRACTICE"."CONVERT_HRS"
(i_Hours integer)
returns result Decimal(34,2)
as begin
result := :i_Hours * 60;
End;
To Call the function using Dummy:
Select
"KABIL_PRACTICE"."CONVERT_HRS"
(1) from dummy;
Code: Result:
To Use the function with the Table:
select
*,"KABIL_PRACTICE"."CONVERT_H
RS"("OVERTIME(in_Hrs)") as
"OVERTIME_in_Minutues" from
"KABIL_PRACTICE"."OVERTIME";
Code: Result:
NOTE:
 The only way to change the body of an existing user-defined function using SQL
statements is to delete the function and re-create it.
 You can also use imperative logic in scalar user-defined functions, to the extent this
does not conflict with the statements above.
 Imperative language constructs allow the developer to control data and control flow,
for example loops, scalar variables and if-then-else statements.
For More Details Visit: http://kabilsapworld.blogspot.com/
THANK YOU!

More Related Content

What's hot

Customer exit variables in sap
Customer exit variables in sapCustomer exit variables in sap
Customer exit variables in sap
Sidharth Sriram
 
Version management of abap programs
Version management of abap programsVersion management of abap programs
Version management of abap programs
icatalysts buddy
 
Dialog Programming Overview
Dialog Programming OverviewDialog Programming Overview
Dialog Programming Overview
sapdocs. info
 
Using infoset query ,sap query and quick viewer
Using infoset query ,sap query and quick viewerUsing infoset query ,sap query and quick viewer
Using infoset query ,sap query and quick viewer
bsm fico
 
SAP Modularization techniques
SAP Modularization techniquesSAP Modularization techniques
SAP Modularization techniques
Jugul Crasta
 
SAP BW - Info object (characteristics)
SAP BW - Info object (characteristics)SAP BW - Info object (characteristics)
SAP BW - Info object (characteristics)
Yasmin Ashraf
 
BW Adjusting settings and monitoring data loads
BW Adjusting settings and monitoring data loadsBW Adjusting settings and monitoring data loads
BW Adjusting settings and monitoring data loads
Luc Vanrobays
 
OOPS ABAP.docx
OOPS ABAP.docxOOPS ABAP.docx
OOPS ABAP.docx
JayantaPatra16
 
07.Advanced Abap
07.Advanced Abap07.Advanced Abap
07.Advanced Abap
sapdocs. info
 
Sap abap-data structures and internal tables
Sap abap-data structures and internal tablesSap abap-data structures and internal tables
Sap abap-data structures and internal tables
Mustafa Nadim
 
Enhancing data sources with badi in SAP ABAP
Enhancing data sources with badi in SAP ABAPEnhancing data sources with badi in SAP ABAP
Enhancing data sources with badi in SAP ABAP
Aabid Khan
 
Automate user creation using sap gui scripting
Automate user creation using sap gui scriptingAutomate user creation using sap gui scripting
Automate user creation using sap gui scripting
sparten369
 
Module pool programming
Module pool programmingModule pool programming
Module pool programming
Subhojit- Opekkhay
 
Sap bw lo extraction
Sap bw lo extractionSap bw lo extraction
Sap bw lo extraction
Obaid shaikh
 
08.Abap Dialog Programming Overview
08.Abap Dialog Programming Overview08.Abap Dialog Programming Overview
08.Abap Dialog Programming Overview
sapdocs. info
 
SAP ABAP Latest Interview Questions with Answers by Garuda Trainings
SAP ABAP Latest Interview Questions with Answers by Garuda TrainingsSAP ABAP Latest Interview Questions with Answers by Garuda Trainings
SAP ABAP Latest Interview Questions with Answers by Garuda Trainings
Garuda Trainings
 
Oops abap fundamental
Oops abap fundamentalOops abap fundamental
Oops abap fundamental
biswajit2015
 
SAP BADI Implementation Learning for Functional Consultant
SAP BADI Implementation Learning for Functional ConsultantSAP BADI Implementation Learning for Functional Consultant
SAP BADI Implementation Learning for Functional Consultant
Ankit Sharma
 
Smartforms interview questions with answers
Smartforms interview questions with answersSmartforms interview questions with answers
Smartforms interview questions with answers
Uttam Agrawal
 

What's hot (20)

Abap reports
Abap reportsAbap reports
Abap reports
 
Customer exit variables in sap
Customer exit variables in sapCustomer exit variables in sap
Customer exit variables in sap
 
Version management of abap programs
Version management of abap programsVersion management of abap programs
Version management of abap programs
 
Dialog Programming Overview
Dialog Programming OverviewDialog Programming Overview
Dialog Programming Overview
 
Using infoset query ,sap query and quick viewer
Using infoset query ,sap query and quick viewerUsing infoset query ,sap query and quick viewer
Using infoset query ,sap query and quick viewer
 
SAP Modularization techniques
SAP Modularization techniquesSAP Modularization techniques
SAP Modularization techniques
 
SAP BW - Info object (characteristics)
SAP BW - Info object (characteristics)SAP BW - Info object (characteristics)
SAP BW - Info object (characteristics)
 
BW Adjusting settings and monitoring data loads
BW Adjusting settings and monitoring data loadsBW Adjusting settings and monitoring data loads
BW Adjusting settings and monitoring data loads
 
OOPS ABAP.docx
OOPS ABAP.docxOOPS ABAP.docx
OOPS ABAP.docx
 
07.Advanced Abap
07.Advanced Abap07.Advanced Abap
07.Advanced Abap
 
Sap abap-data structures and internal tables
Sap abap-data structures and internal tablesSap abap-data structures and internal tables
Sap abap-data structures and internal tables
 
Enhancing data sources with badi in SAP ABAP
Enhancing data sources with badi in SAP ABAPEnhancing data sources with badi in SAP ABAP
Enhancing data sources with badi in SAP ABAP
 
Automate user creation using sap gui scripting
Automate user creation using sap gui scriptingAutomate user creation using sap gui scripting
Automate user creation using sap gui scripting
 
Module pool programming
Module pool programmingModule pool programming
Module pool programming
 
Sap bw lo extraction
Sap bw lo extractionSap bw lo extraction
Sap bw lo extraction
 
08.Abap Dialog Programming Overview
08.Abap Dialog Programming Overview08.Abap Dialog Programming Overview
08.Abap Dialog Programming Overview
 
SAP ABAP Latest Interview Questions with Answers by Garuda Trainings
SAP ABAP Latest Interview Questions with Answers by Garuda TrainingsSAP ABAP Latest Interview Questions with Answers by Garuda Trainings
SAP ABAP Latest Interview Questions with Answers by Garuda Trainings
 
Oops abap fundamental
Oops abap fundamentalOops abap fundamental
Oops abap fundamental
 
SAP BADI Implementation Learning for Functional Consultant
SAP BADI Implementation Learning for Functional ConsultantSAP BADI Implementation Learning for Functional Consultant
SAP BADI Implementation Learning for Functional Consultant
 
Smartforms interview questions with answers
Smartforms interview questions with answersSmartforms interview questions with answers
Smartforms interview questions with answers
 

Similar to Scalar user defined function in sap hana

Mysqlppt
MysqlpptMysqlppt
Mysqlppt
MysqlpptMysqlppt
Function
FunctionFunction
Mysql creating stored function
Mysql  creating stored function Mysql  creating stored function
Mysql creating stored function
Prof.Nilesh Magar
 
Understand when to use user defined functions in sql server tech-republic
Understand when to use user defined functions in sql server   tech-republicUnderstand when to use user defined functions in sql server   tech-republic
Understand when to use user defined functions in sql server tech-republic
Kaing Menglieng
 
ADVANCED MODELLING.pptx
ADVANCED MODELLING.pptxADVANCED MODELLING.pptx
ADVANCED MODELLING.pptx
RUPAK BHATTACHARJEE
 
Database COMPLETE
Database COMPLETEDatabase COMPLETE
Database COMPLETE
Abrar ali
 
Sql functions
Sql functionsSql functions
Sql functions
Ankit Dubey
 
Les13
Les13Les13
[Www.pkbulk.blogspot.com]dbms07
[Www.pkbulk.blogspot.com]dbms07[Www.pkbulk.blogspot.com]dbms07
[Www.pkbulk.blogspot.com]dbms07
AnusAhmad
 
Functions in sap hana
Functions in sap hanaFunctions in sap hana
Functions in sap hana
kabilarasan R
 
SQL
SQLSQL
Advanced plsql mock_assessment
Advanced plsql mock_assessmentAdvanced plsql mock_assessment
Advanced plsql mock_assessment
Saurabh K. Gupta
 
Sqlapi0.1
Sqlapi0.1Sqlapi0.1
Sqlapi0.1
jitendral
 
Cursors, triggers, procedures
Cursors, triggers, proceduresCursors, triggers, procedures
Cursors, triggers, procedures
Vaibhav Kathuria
 
Introduction to Oracle Database.pptx
Introduction to Oracle Database.pptxIntroduction to Oracle Database.pptx
Introduction to Oracle Database.pptx
SiddhantBhardwaj26
 
Chapter09
Chapter09Chapter09
Chapter09
sasa_eldoby
 
Sql views, stored procedure, functions
Sql views, stored procedure, functionsSql views, stored procedure, functions
Sql views, stored procedure, functions
Om Vikram Thapa
 
Sq lite
Sq liteSq lite
Sql tutorial
Sql tutorialSql tutorial
Sql tutorial
prabhu rajendran
 

Similar to Scalar user defined function in sap hana (20)

Mysqlppt
MysqlpptMysqlppt
Mysqlppt
 
Mysqlppt
MysqlpptMysqlppt
Mysqlppt
 
Function
FunctionFunction
Function
 
Mysql creating stored function
Mysql  creating stored function Mysql  creating stored function
Mysql creating stored function
 
Understand when to use user defined functions in sql server tech-republic
Understand when to use user defined functions in sql server   tech-republicUnderstand when to use user defined functions in sql server   tech-republic
Understand when to use user defined functions in sql server tech-republic
 
ADVANCED MODELLING.pptx
ADVANCED MODELLING.pptxADVANCED MODELLING.pptx
ADVANCED MODELLING.pptx
 
Database COMPLETE
Database COMPLETEDatabase COMPLETE
Database COMPLETE
 
Sql functions
Sql functionsSql functions
Sql functions
 
Les13
Les13Les13
Les13
 
[Www.pkbulk.blogspot.com]dbms07
[Www.pkbulk.blogspot.com]dbms07[Www.pkbulk.blogspot.com]dbms07
[Www.pkbulk.blogspot.com]dbms07
 
Functions in sap hana
Functions in sap hanaFunctions in sap hana
Functions in sap hana
 
SQL
SQLSQL
SQL
 
Advanced plsql mock_assessment
Advanced plsql mock_assessmentAdvanced plsql mock_assessment
Advanced plsql mock_assessment
 
Sqlapi0.1
Sqlapi0.1Sqlapi0.1
Sqlapi0.1
 
Cursors, triggers, procedures
Cursors, triggers, proceduresCursors, triggers, procedures
Cursors, triggers, procedures
 
Introduction to Oracle Database.pptx
Introduction to Oracle Database.pptxIntroduction to Oracle Database.pptx
Introduction to Oracle Database.pptx
 
Chapter09
Chapter09Chapter09
Chapter09
 
Sql views, stored procedure, functions
Sql views, stored procedure, functionsSql views, stored procedure, functions
Sql views, stored procedure, functions
 
Sq lite
Sq liteSq lite
Sq lite
 
Sql tutorial
Sql tutorialSql tutorial
Sql tutorial
 

Recently uploaded

Open Source Contributions to Postgres: The Basics POSETTE 2024
Open Source Contributions to Postgres: The Basics POSETTE 2024Open Source Contributions to Postgres: The Basics POSETTE 2024
Open Source Contributions to Postgres: The Basics POSETTE 2024
ElizabethGarrettChri
 
一比一原版(harvard毕业证书)哈佛大学毕业证如何办理
一比一原版(harvard毕业证书)哈佛大学毕业证如何办理一比一原版(harvard毕业证书)哈佛大学毕业证如何办理
一比一原版(harvard毕业证书)哈佛大学毕业证如何办理
taqyea
 
University of New South Wales degree offer diploma Transcript
University of New South Wales degree offer diploma TranscriptUniversity of New South Wales degree offer diploma Transcript
University of New South Wales degree offer diploma Transcript
soxrziqu
 
writing report business partner b1+ .pdf
writing report business partner b1+ .pdfwriting report business partner b1+ .pdf
writing report business partner b1+ .pdf
VyNguyen709676
 
DATA COMMS-NETWORKS YR2 lecture 08 NAT & CLOUD.docx
DATA COMMS-NETWORKS YR2 lecture 08 NAT & CLOUD.docxDATA COMMS-NETWORKS YR2 lecture 08 NAT & CLOUD.docx
DATA COMMS-NETWORKS YR2 lecture 08 NAT & CLOUD.docx
SaffaIbrahim1
 
一比一原版(UCSB文凭证书)圣芭芭拉分校毕业证如何办理
一比一原版(UCSB文凭证书)圣芭芭拉分校毕业证如何办理一比一原版(UCSB文凭证书)圣芭芭拉分校毕业证如何办理
一比一原版(UCSB文凭证书)圣芭芭拉分校毕业证如何办理
nuttdpt
 
一比一原版(lbs毕业证书)伦敦商学院毕业证如何办理
一比一原版(lbs毕业证书)伦敦商学院毕业证如何办理一比一原版(lbs毕业证书)伦敦商学院毕业证如何办理
一比一原版(lbs毕业证书)伦敦商学院毕业证如何办理
ywqeos
 
一比一原版多伦多大学毕业证(UofT毕业证书)学历如何办理
一比一原版多伦多大学毕业证(UofT毕业证书)学历如何办理一比一原版多伦多大学毕业证(UofT毕业证书)学历如何办理
一比一原版多伦多大学毕业证(UofT毕业证书)学历如何办理
eoxhsaa
 
原版一比一多伦多大学毕业证(UofT毕业证书)如何办理
原版一比一多伦多大学毕业证(UofT毕业证书)如何办理原版一比一多伦多大学毕业证(UofT毕业证书)如何办理
原版一比一多伦多大学毕业证(UofT毕业证书)如何办理
mkkikqvo
 
The Ipsos - AI - Monitor 2024 Report.pdf
The  Ipsos - AI - Monitor 2024 Report.pdfThe  Ipsos - AI - Monitor 2024 Report.pdf
The Ipsos - AI - Monitor 2024 Report.pdf
Social Samosa
 
一比一原版(Sheffield毕业证书)谢菲尔德大学毕业证如何办理
一比一原版(Sheffield毕业证书)谢菲尔德大学毕业证如何办理一比一原版(Sheffield毕业证书)谢菲尔德大学毕业证如何办理
一比一原版(Sheffield毕业证书)谢菲尔德大学毕业证如何办理
1tyxnjpia
 
一比一原版兰加拉学院毕业证(Langara毕业证书)学历如何办理
一比一原版兰加拉学院毕业证(Langara毕业证书)学历如何办理一比一原版兰加拉学院毕业证(Langara毕业证书)学历如何办理
一比一原版兰加拉学院毕业证(Langara毕业证书)学历如何办理
hyfjgavov
 
一比一原版格里菲斯大学毕业证(Griffith毕业证书)学历如何办理
一比一原版格里菲斯大学毕业证(Griffith毕业证书)学历如何办理一比一原版格里菲斯大学毕业证(Griffith毕业证书)学历如何办理
一比一原版格里菲斯大学毕业证(Griffith毕业证书)学历如何办理
lzdvtmy8
 
End-to-end pipeline agility - Berlin Buzzwords 2024
End-to-end pipeline agility - Berlin Buzzwords 2024End-to-end pipeline agility - Berlin Buzzwords 2024
End-to-end pipeline agility - Berlin Buzzwords 2024
Lars Albertsson
 
Sample Devops SRE Product Companies .pdf
Sample Devops SRE  Product Companies .pdfSample Devops SRE  Product Companies .pdf
Sample Devops SRE Product Companies .pdf
Vineet
 
一比一原版(UO毕业证)渥太华大学毕业证如何办理
一比一原版(UO毕业证)渥太华大学毕业证如何办理一比一原版(UO毕业证)渥太华大学毕业证如何办理
一比一原版(UO毕业证)渥太华大学毕业证如何办理
bmucuha
 
Build applications with generative AI on Google Cloud
Build applications with generative AI on Google CloudBuild applications with generative AI on Google Cloud
Build applications with generative AI on Google Cloud
Márton Kodok
 
一比一原版英国赫特福德大学毕业证(hertfordshire毕业证书)如何办理
一比一原版英国赫特福德大学毕业证(hertfordshire毕业证书)如何办理一比一原版英国赫特福德大学毕业证(hertfordshire毕业证书)如何办理
一比一原版英国赫特福德大学毕业证(hertfordshire毕业证书)如何办理
nyvan3
 
Orchestrating the Future: Navigating Today's Data Workflow Challenges with Ai...
Orchestrating the Future: Navigating Today's Data Workflow Challenges with Ai...Orchestrating the Future: Navigating Today's Data Workflow Challenges with Ai...
Orchestrating the Future: Navigating Today's Data Workflow Challenges with Ai...
Kaxil Naik
 
Beyond the Basics of A/B Tests: Highly Innovative Experimentation Tactics You...
Beyond the Basics of A/B Tests: Highly Innovative Experimentation Tactics You...Beyond the Basics of A/B Tests: Highly Innovative Experimentation Tactics You...
Beyond the Basics of A/B Tests: Highly Innovative Experimentation Tactics You...
Aggregage
 

Recently uploaded (20)

Open Source Contributions to Postgres: The Basics POSETTE 2024
Open Source Contributions to Postgres: The Basics POSETTE 2024Open Source Contributions to Postgres: The Basics POSETTE 2024
Open Source Contributions to Postgres: The Basics POSETTE 2024
 
一比一原版(harvard毕业证书)哈佛大学毕业证如何办理
一比一原版(harvard毕业证书)哈佛大学毕业证如何办理一比一原版(harvard毕业证书)哈佛大学毕业证如何办理
一比一原版(harvard毕业证书)哈佛大学毕业证如何办理
 
University of New South Wales degree offer diploma Transcript
University of New South Wales degree offer diploma TranscriptUniversity of New South Wales degree offer diploma Transcript
University of New South Wales degree offer diploma Transcript
 
writing report business partner b1+ .pdf
writing report business partner b1+ .pdfwriting report business partner b1+ .pdf
writing report business partner b1+ .pdf
 
DATA COMMS-NETWORKS YR2 lecture 08 NAT & CLOUD.docx
DATA COMMS-NETWORKS YR2 lecture 08 NAT & CLOUD.docxDATA COMMS-NETWORKS YR2 lecture 08 NAT & CLOUD.docx
DATA COMMS-NETWORKS YR2 lecture 08 NAT & CLOUD.docx
 
一比一原版(UCSB文凭证书)圣芭芭拉分校毕业证如何办理
一比一原版(UCSB文凭证书)圣芭芭拉分校毕业证如何办理一比一原版(UCSB文凭证书)圣芭芭拉分校毕业证如何办理
一比一原版(UCSB文凭证书)圣芭芭拉分校毕业证如何办理
 
一比一原版(lbs毕业证书)伦敦商学院毕业证如何办理
一比一原版(lbs毕业证书)伦敦商学院毕业证如何办理一比一原版(lbs毕业证书)伦敦商学院毕业证如何办理
一比一原版(lbs毕业证书)伦敦商学院毕业证如何办理
 
一比一原版多伦多大学毕业证(UofT毕业证书)学历如何办理
一比一原版多伦多大学毕业证(UofT毕业证书)学历如何办理一比一原版多伦多大学毕业证(UofT毕业证书)学历如何办理
一比一原版多伦多大学毕业证(UofT毕业证书)学历如何办理
 
原版一比一多伦多大学毕业证(UofT毕业证书)如何办理
原版一比一多伦多大学毕业证(UofT毕业证书)如何办理原版一比一多伦多大学毕业证(UofT毕业证书)如何办理
原版一比一多伦多大学毕业证(UofT毕业证书)如何办理
 
The Ipsos - AI - Monitor 2024 Report.pdf
The  Ipsos - AI - Monitor 2024 Report.pdfThe  Ipsos - AI - Monitor 2024 Report.pdf
The Ipsos - AI - Monitor 2024 Report.pdf
 
一比一原版(Sheffield毕业证书)谢菲尔德大学毕业证如何办理
一比一原版(Sheffield毕业证书)谢菲尔德大学毕业证如何办理一比一原版(Sheffield毕业证书)谢菲尔德大学毕业证如何办理
一比一原版(Sheffield毕业证书)谢菲尔德大学毕业证如何办理
 
一比一原版兰加拉学院毕业证(Langara毕业证书)学历如何办理
一比一原版兰加拉学院毕业证(Langara毕业证书)学历如何办理一比一原版兰加拉学院毕业证(Langara毕业证书)学历如何办理
一比一原版兰加拉学院毕业证(Langara毕业证书)学历如何办理
 
一比一原版格里菲斯大学毕业证(Griffith毕业证书)学历如何办理
一比一原版格里菲斯大学毕业证(Griffith毕业证书)学历如何办理一比一原版格里菲斯大学毕业证(Griffith毕业证书)学历如何办理
一比一原版格里菲斯大学毕业证(Griffith毕业证书)学历如何办理
 
End-to-end pipeline agility - Berlin Buzzwords 2024
End-to-end pipeline agility - Berlin Buzzwords 2024End-to-end pipeline agility - Berlin Buzzwords 2024
End-to-end pipeline agility - Berlin Buzzwords 2024
 
Sample Devops SRE Product Companies .pdf
Sample Devops SRE  Product Companies .pdfSample Devops SRE  Product Companies .pdf
Sample Devops SRE Product Companies .pdf
 
一比一原版(UO毕业证)渥太华大学毕业证如何办理
一比一原版(UO毕业证)渥太华大学毕业证如何办理一比一原版(UO毕业证)渥太华大学毕业证如何办理
一比一原版(UO毕业证)渥太华大学毕业证如何办理
 
Build applications with generative AI on Google Cloud
Build applications with generative AI on Google CloudBuild applications with generative AI on Google Cloud
Build applications with generative AI on Google Cloud
 
一比一原版英国赫特福德大学毕业证(hertfordshire毕业证书)如何办理
一比一原版英国赫特福德大学毕业证(hertfordshire毕业证书)如何办理一比一原版英国赫特福德大学毕业证(hertfordshire毕业证书)如何办理
一比一原版英国赫特福德大学毕业证(hertfordshire毕业证书)如何办理
 
Orchestrating the Future: Navigating Today's Data Workflow Challenges with Ai...
Orchestrating the Future: Navigating Today's Data Workflow Challenges with Ai...Orchestrating the Future: Navigating Today's Data Workflow Challenges with Ai...
Orchestrating the Future: Navigating Today's Data Workflow Challenges with Ai...
 
Beyond the Basics of A/B Tests: Highly Innovative Experimentation Tactics You...
Beyond the Basics of A/B Tests: Highly Innovative Experimentation Tactics You...Beyond the Basics of A/B Tests: Highly Innovative Experimentation Tactics You...
Beyond the Basics of A/B Tests: Highly Innovative Experimentation Tactics You...
 

Scalar user defined function in sap hana

  • 1. SCALAR USER DEFINED FUNCTION IN SAP HANA Kabilarasan RPresented by
  • 2. Scalar User Defined Function  The simplest database object for which you can make use of SQL Script are Scalar User- Defined Functions (Scalar UDFs)  Scalar UDFs allow you to the define functions which take a number of input parameters and return scalar values.  Only expressions are allowed in the body of the UDF, so no table operations, CE functions or array operations.
  • 3. Scalar User-Defined Functions Support the Following:  They can have any number of scalar input parameters (primitive SQL types). Input parameters of table type are not supported.  They can return multiple scalar values.  They can contain expressions within their body. Table and array operations are not supported.  They can be used in the field list or the WHERE clause of SELECT statements — like built-in functions.  They are callable via direct assignment in other user-defined functions or stored procedures (x := my_scalar_func () ).  They must be free of side-effects and do not support any type of SQL statement in their body.
  • 4. Basic Syntax to Define a Scalar User- Defined Function CREATE FUNCTION <function name> (<list of input parameters with type>) RETURNS <scalar result parameter name and type> AS BEGIN <function body> END; Note:  You can create scalar user-defined functions for use like built-in functions.  Prefix parameter names with “:”to access their values.
  • 5. create column table "KABIL_PRACTICE"."OVERTIME" ( "E_ID" integer, "E_NAME" Nvarchar(35), "OVERTIME(in_Hrs)" Integer ); Code: To Create a table: To Insert the values into a table: Insert into "KABIL_PRACTICE"."OVERTIME" values (1,'Kabil',20); Insert into "KABIL_PRACTICE"."OVERTIME" values (2,'Nazeer',15); Insert into "KABIL_PRACTICE"."OVERTIME" values (3,'Kalai',10);
  • 6. To Create function: Create Function "KABIL_PRACTICE"."CONVERT_HRS" (i_Hours integer) returns result Decimal(34,2) as begin result := :i_Hours * 60; End;
  • 7. To Call the function using Dummy: Select "KABIL_PRACTICE"."CONVERT_HRS" (1) from dummy; Code: Result:
  • 8. To Use the function with the Table: select *,"KABIL_PRACTICE"."CONVERT_H RS"("OVERTIME(in_Hrs)") as "OVERTIME_in_Minutues" from "KABIL_PRACTICE"."OVERTIME"; Code: Result:
  • 9. NOTE:  The only way to change the body of an existing user-defined function using SQL statements is to delete the function and re-create it.  You can also use imperative logic in scalar user-defined functions, to the extent this does not conflict with the statements above.  Imperative language constructs allow the developer to control data and control flow, for example loops, scalar variables and if-then-else statements.
  • 10. For More Details Visit: http://kabilsapworld.blogspot.com/ THANK YOU!