Simple function program in pl sql




















This subprogram unit in the Oracle database is stored as a database object. Note: Subprogram is nothing but a procedure, and it needs to be created manually as per the requirement. Once created they will be stored as database objects. In this example, we are going to create an Oracle procedure that takes the name as input and prints the welcome message as output.

We are going to use EXEC command to call procedure. Below are some of the characteristics of functions. In this program, we are going to create a function that takes the name as input and returns the welcome message as output. We are going to use anonymous block and select statement to call the function. Here we are going to see the commonly used functions and their usage. The first script builds the database tables processed by the sample programs.

The second script loads or reloads the database tables. The following example uses a simple FOR loop to insert ten rows into a database table. The values of a loop index, counter variable, and either of two character strings are inserted.

Which string is inserted depends on the value of the loop index. The following example uses a cursor to select the five highest paid employees from the emp table. The following example illustrates block structure and scope rules. An outer block declares two variables named x and counter and loops four times. Inside this loop is a sub-block that also declares a variable named x.

The values inserted into the temp table show that the two x 's are indeed different. In the next example the accounts table is modified according to instructions stored in the action table. Each row in the action table contains an account number, an action to be taken I, U, or D for insert, update, or delete , an amount by which to update the account, and a time tag used to sequence the transactions.

Angular 7. Machine Learning. Data Structures. Operating System. Computer Network. Compiler Design. Computer Organization. Discrete Mathematics. Ethical Hacking. Computer Graphics. Software Engineering. Web Technology. Cyber Security. When a program calls a function, the program control is transferred to the called function. A called function performs the defined task and when its return statement is executed or when the last end statement is reached, it returns the program control back to the main program.

To call a function, you simply need to pass the required parameters along with the function name and if the function returns a value, then you can store the returned value. We have seen that a program or subprogram may call another subprogram.



0コメント

  • 1000 / 1000