Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 3

SQL script and procedueres

-- it supports
Case expressions
Aggregation expressions ,
Function expressions
subquieries in expression

-- SQL built in functions can be used as expresison

-- Aggreagation expression

Example : Count(*) , ALL | DISTINCT


MIN | MAX | SUM |AVG| STDDEV |VAR|

Creation of tables in sap hana :

CREATE [TABLE_TYPE] TABLE TABLE_NAME <TABLE_CONTENTS_SOURCE> ;

Table_type : COLUMN | ROW | HISTORY COLUMN | GLOBAL TEMPORARY


LOCAL TEMPORARY

Table_contents_Source: talbe_element | (column_name. ... ) |


like_table_clause | as_table_subquery
with [NO] DATA .

table_element : column_definition column_contraint | table_constraint


(Column_name)

Like_table_clause : LIKE like_table_name

as_table_subquery : AS (<select query>)

column_definition : column_name data tyoe [<column store data type>]


[<ddic data type> DEFAULT default_value]
[GENERATED ALWAYS AS <Expression>]

SQL script is a collectionof extnsions to strucvtures query language

Data extesion : Allows the definition of table types without corresponding tables

Functional extension : Allows the definition of functions whch can be used to


express
and encapsulate dataflows

Procedural extension : Provides imperative xonstructs executed in the context of


database process

SQL DATA TYPES :

Sql supports sql 92 standard system and also primitive data type
TINYINT , SMALLINT , INTEGER , BIGINT
DECIMAL (p,s ), REAL , FLOAT , DOUBLE ,
VARCHAR , NVARCHAR , CLOB, NLOB,
VARBINARY , BLOB ,
DATE ,TIMe ,TIMESTAMP

Table type extension :

create type [schema].[type_name] as table


(
name1 type1 ,
name2 type2
)

DROP type [scehma].[type] cascade

declaring a variable

DECLARE <VARIABLE_NAME> Type <NOT NULL >

devlare a int ;
declare b int = 0 ;

a = selct count(*) from base_table ;

b = :a + 5 .

Control statement s : IF THEN

IF <bool-expr1>

THEN
statements ---

ELSEIF <bool-expr2>

THEN
statements ----

ELSe .
statements ---
ENDIF.

Example :

select count(*) from base_table where fact = :var

if :found is null then


call ins1_msg_proc

else .

call ins2_msg_proc2

endif.

WHILE <bool-expr> DO

STATEMENTS

END WHILE

FOR <loop-var> in <start> -- <end> DO

{statements}

ENDFOR

You might also like