## To Print “Hello World!”dropprocedureifexistsHelloWorld;delimiter//CREATEPROCEDUREHelloWorld()BEGINSELECT"Hello World!";END;//delimiter;CALLHelloWorld();
## To Print “Hello (with given name)” using functiondropfunctionifexistsHelloName;CREATEFUNCTIONHelloName(nameVARCHAR(100))RETURNSVARCHAR(120)DETERMINISTICRETURNCONCAT("Hello ",name);SET@fn_res=HelloName("BPDC");select@fn_res;
## function to compute squaredropfunctionifexistscompute_square_fn;delimiter//createfunctioncompute_square_fn(numberint)returnsintbeginreturnnumber*number;end//delimiter;selectcompute_square_fn(3);
## function to compute area of circledropfunctionifexistscompute_circle_area;delimiter//createfunctioncompute_circle_area(radiusint)returnsfloatDETERMINISTICbeginreturn3.14*radius*radius;end//delimiter;selectcompute_circle_area(4);
## Control Statementsdroptableifexistst;createtablet(s1int);INSERTINTOtVALUES(17);
## while loopdropprocedureifexistsp14;delimiter//CREATEPROCEDUREp14()BEGINDECLAREvINT;SETv=0;WHILEv<5DOINSERTINTOtVALUES(v);SETv=v+1;ENDWHILE;END;//delimiter;CALLp14();select*fromt;
## loop ... end loopdropprocedureifexistsp16;delimiter//CREATEPROCEDUREp16()BEGINDECLAREvINT;SETv=10;loop_label:LOOPINSERTINTOtVALUES(v);SETv=v+1;IFv>=15THENLEAVEloop_label;ENDIF;ENDLOOP;END;//delimiter;CALLp16();select*fromt;
## Use “CASE” to insert or updatedropprocedureifexistsassignment;delimiter//CREATEPROCEDUREassignment(INparameter1INT,inparameter2INT)BEGINCASEparameter2WHEN1THENINSERTINTOtVALUES(parameter1/parameter2);WHEN2THENINSERTINTOtVALUES(parameter1/parameter2);ELSEINSERTINTOtVALUES(parameter1);ENDCASE;END;//delimiter;CALLassignment(10,0);CALLassignment(10,1);CALLassignment(10,2);select*fromt;
Last Updated: 2023-01-25 ; Contributors: AhmedThahir