Trending February 2024 # How Does Continuation Statement Work? # Suggested March 2024 # Top 5 Popular

You are reading the article How Does Continuation Statement Work? updated in February 2024 on the website Eastwest.edu.vn. We hope that the information we have shared is helpful to you. If you find the content interesting and meaningful, please share it with your friends and continue to follow and support us for the latest updates. Suggested March 2024 How Does Continuation Statement Work?

Introduction to Golang Continue Statement

In go language continue statement allow the developer to skip the particular condition and start from the next value, for example, if we have a list of students and we want to add some extra marks to each student except for the students belongs to a particular section, in that case, we can put continue statement in the loop and the execution will start from the next section, we can say continue is little similar to break of other programing language and it allows us to skip the iteration of the loop at any time inside the loop, with the help of the continue statement we are able to avoid unnecessary execution of some codes.

Start Your Free Software Development Course

Syntax

Below is a simple syntax for the continue statement, here we have written continue inside the loop, this loop can be for a loop. Generally, we put this continue on any condition where we want to skip the execution and go to the next iteration of the execution of the program. Mostly we use the continue statement to skip the execution of some specific conditions or simply move to the next iteration of the loop.

Loop{ continue; } How Does Continuation Statement Work in Go language?

To explain the working of the continue statement in go language we have taken the diagram below .If we have used break of other languages then it is very much similar to those breaks. In case if we do not want to execute code for some specific iteration of the code then we go with the continue statement. we can say continue statement allow us to avoid execution of peace of the code for some specific iteration, hence we can understand it saves our program of extra execution of the codes. Let me explain working with the help of a given diagram.

Once the continue statement is read by go language it will simply go to the next statement, by skipping the current iteration, you can even consider it like breaking of the current iteration. Remember iteration will be continued with the next iteration with skipping the current one.

It may be confusing for many people with names continuing, as it is breaking iteration. Actual it is stopping execution of current item of iteration and going to the next item for iteration which means it allows loop iteration to be continued with the next item.

In the below statement the first condition will be checked, if the condition is successful or true then the statement will execute with a new or next value.

Let us take an example, suppose university decided to pass all the students of the school except the students belongs to any particular section, then that case we will run a loop over all students of the school and we will put a condition where we will check for the section of students. We will keep passing the all students, but once we found that particular section we will use the continue statement which will skip the processing of the students of that section.

In Go, language continuation is similar to the break of other languages.

In memory, it keeps track of the next iteration and once we put continue inside the loop, it will go to the next iteration by skipping the current iteration.

Please see the below diagram for some understanding of the continue in go language.

Examples to Implement Golang Continue

In the below, we have given some examples where we can understand the working and uses of the continue statement. in case if we want to execute these examples we can create a file like chúng tôi and paste the codes of the examples on this file and we can run the command go run chúng tôi and we can get the output of the program.

Example #1

In the below example we are printing the number from 15 to 25, we have used a condition where we are using number== 20 and if the condition matches, the continue will execute hence 20 will not be printed.

Code:

package main import "fmt" func main() { var number int = 15 for number < 25 { if number == 20 { number = number + 1; continue; } fmt.Printf("The value of the number is: %dn", number); number++; } }

Output:

Example #2

Code:

package main import "fmt" func main() { var oddNumber int = 15 for oddNumber< 25 { if oddNumber%2==0 { oddNumber = oddNumber + 1; continue; } fmt.Printf("The odd numbers are: %dn", oddNumber); oddNumber++; } }

Output:

Example #3

In the below example we are simply printing all the even numbers between 15 to 25, so we have used the condition! (evenNumber%2==0).

Code:

package main import "fmt" func main() { var evenNumber int = 15 for evenNumber< 25 { if !(evenNumber%2==0) { evenNumber = evenNumber + 1; continue; } fmt.Printf("The Even numbers are: %dn", evenNumber); evenNumber++; } }

Example #4

In the below example we are printing the number from three to nine, we have used a condition where we are using number== 8 and if the condition matches the continue will execute the hence 8 will not be printed, 8 iterations will be skipped.

Code:

package main import "fmt" func main() { for number := 3; number < 10; number++ { if number == 8 { fmt.Println("Here loop will continue for the next iteration") continue } fmt.Println("The values of the variable number is", number) } fmt.Println("End of the program happens") }

Output:

Conclusion

From this tutorial, we learned the basics of the continue statement in the go language and we learned the concept with the help of the various examples. We learned the working of the continue with the help of a diagram and focus on a simple syntax.

Recommended Article

This is a guide to Golang Continue. Here we discuss the introduction, syntax, and working of Golang Continue Statement along with different examples and code implementation. You can also go through our other suggested articles to learn more –

You're reading How Does Continuation Statement Work?

How Does The Sessions Work?

Introduction to Laravel Session

Sessions are an essential part of the Laravel PHP framework. It helps to make it possible to store information of the user across multiple requests on the server. Unified API helps to access various session backends that Laravel ships. All the files of the session configuration are stored at config/session.php. Laravel automatically uses the file session driver which is compatible with many applications. Driver configuration is a session that defines where the session data is to be stored for each of the requests. Different drivers available in Laravel are file, APC, array, cookie, Redis, Memcached, and database. They assist in handling session data.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

What are the Laravel Sessions?

The different drivers which are made available in laravel session are as follows:

File: Here, the sessions are stored in the directory – storage/framework/sessions.

Cookie: Secure and encrypted cookies are where the sessions are stored.

Database: Sessions here are stored in a relational database.

Array: A PHP array is where the sessions are stored and they will not be persisted any further.

Memcached/Redis: These are fast and cache-based stores and sessions are also stored inside them.

Given below are the two ways of operating session:

Request instance

Global session helper

Whenever the session data needs to be accessed, it is accessed via an instance of a session with the help of an HTTP request. The get() method is used after getting the instance wherein one argument “key” is used to get the session data.

For, global helper the code is as follows:

The retrieving of Session Data is possible in Laravel. When you store data and want to retrieve it anytime later.

You can do so in two different ways, i.e. with the help of Session Helper and Request Instance.

To retrieve with the help of Global Helper.

$result= session ('key');

To retrieve with Request Instance.

This is how the sessions are retrieved with the help of the key.

To retrieve all the data that is stored in the application, we can use all method on the request instance.

Another option to retrieve session data is with the available default argument.

// Closure Return 'default value'; });

How does Laravel Sessions work?

Laravel session helps you to access session data, store session data, delete session data, and also retrieve session data. There are various designated steps to perform these varied actions in the Laravel application. With the help of sessions, you can handle the data of the users and also store it securely in your application. The data is well organized and saved in the application. The user can refer to the data at any point in time with the help of the retrieving option that is available in the application. Also if there is a need to delete the data from the stored space, it is possible with sessions. Also, the sole authority is in the hands of the administrator. Nobody else can handle data; be it storing, deleting, or retrieving.

Sessions are very crucial for any web application. It is important to know of all its use cases. Even authentication status and similar kind of log data can be stored in the sessions. There can be errors that may arise in the sessions if they are not coded or followed properly by the user. There can be HTTP request errors too. Do not panic during such situations and rework on the following of the instructions carefully.

Has method needs to be used to confirm if a value you want to find about is present in the session. The purpose of the has method is that it helps in returning the true value if it is present in the session and if it is not present the return will be null in confirmation.

// }

How to remove all items from the session?

The flush method needs to be used if you want to flush out all the data from the session. This will wipe every single data present and therefore it is termed as flush symbolically.

When you want to flash all the data that is present in the session you will have to use a different approach. It can be possible that there may be times when you may have to store items in your session only for the next request that follows. Use the flash method when such a demand may arise. Only during a subsequent HTTP request, this data will be available following which it will be deleted.

Example of Laravel Session

Given below is the example mentioned:

1. Create a migration table

first generate a migration file

Php artisan session: table

now, migrate generated sessions table

2. Php artisan migrate

The sample migration file will be generated with the following contents in it.

Schema::create('sessions', function ($table) { });

Once the migration table has been created, open the .env file to change the following line in it.

SESSION_DRIVER=database Conclusion

In conclusion, we can say that Laravel Sessions plays an important role in securing and storing data of the users and the log details which can be stored, deleted, or retrieved when needed. They can be customized as per the need of handling the data in a particular way. The users need to follow the method appropriately to get the correct results.

Recommended Articles

We hope that this EDUCBA information on “Laravel Session” was beneficial to you. You can view EDUCBA’s recommended articles for more information.

How Does Leveraged Etf Work?

Definition of Leveraged ETF

Start Your Free Investment Banking Course

Download Corporate Valuation, Investment Banking, Accounting, CFA Calculator & others

Some investors have ample funds and want to speculate about forecasting the direction of the prices of an asset and earning huge profits from such speculations. A leveraged exchange-traded fund (ETF) is such a fund that uses borrowed funds to invest in derivative instruments such as options and futures in the underlying securities as that of its benchmark index so that the returns that are generated on such an ETF get magnified as compared to the returns of its benchmark index. However, the leverage technique, if fails, can also multiply the investor’s losses. Unlike a regular ETF, which can only track the securities in its underlying index on a 1:1 ratio, a leveraged ETF may aim to multiply the returns for a 2:1 or even 3:1 ratio.

How Does It Work?

Leveraged ETFs are mutual funds that trade in the stock exchanges. The fund might be fully or partially tracking its benchmark index or might be actively managed. Leveraged ETFs try to double or triple the daily performance of the index or asset classes by using debts and financial derivatives. Returns are high in a short-term period due to price fluctuations. Such ETFs attract investors ready to bear the risk and have huge funds to speculate to earn, as the profit in leveraged ETFs is exceptionally high.

Example of Leveraged ETF Leveraged ETF Risk Importance of Leveraged ETF

It is deemed important due to the following reasons:

The main importance is that it gives the investor the potential to magnify the investment returns and earn a high-profit level.

It is profitable for the investors even when the market is declining, as they can profit by using inversely leveraged ETFs.

The leveraged ETF can be purchased easily, so even a newbie can purchase it, as there are managers to manage it efficiently.

The opportunity to liquidate the investment is available for the investors.

The returns generated are higher in the case of a leveraged ETF than in a regular ETF.

Advantages

Huge opportunity for returns: ETF gives investors a huge opportunity to earn as their investments can be multiplied here only if they are ready to take risks.

Earning at the time of market decline: The investors in the leveraged ETF can earn profit even at the time of market decline by using inverse leveraged ETF.

Potential to earn: It gives its investors a huge potential to earn as their return can be amplified twice or thrice.

High risk: There is a high level of risk in the leveraged ETF as the losses can be multiplied here.

Expense ratio: Some managers manage the work of investment for which they charge some fees, which increases the expense ratio also.

Not a long-term investment: It is suitable for investors looking for a short-term horizon, and the investors willing to invest for a long period of time do not find it attractive.

Conclusion

Many risk factors are involved in leveraged ETFs, but for an investor willing to earn profit and ready to bear exaggerated risk, that is not a bar. These are funds for risk lovers. So, one must grab the in-depth knowledge of the path to be traveled as risk is accompanied by profit here depending on the type of investor and preferences.

Recommended Articles

How Does Anchorpane Work In Javafx

Introduction to JavaFX AnchorPane

The JavaFX Anchor Pane is used for anchoring to an offset from an anchor pane edges by its child node edges. If the anchor pane has a border or padding set, the off sets is measuring from the inside corner edges of the insets. Anchor pane lay out managing child of the child’s makes visible-property value and non-managing child are not considered for calculating layouts. We have facility to add CSS styles with Anchor pane of JavaFX. Anchor Pane is a JavaFX class, which is available in scene.layout.AnchorPane package. We can apply JavaFX Anchor pane with label, cylinder structure, rectangle structure, buttons etc.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

Constructors

AnchorPane(): Creates an anchor pane object with new keyword without any argument in the constructor.

AnchorPane(Node n1, Node n2, Node n3,….): Creates an anchor pane object with new keyword with required number of arguments in the constructor.

Frequently Used Methods

setBottomAnchor(Node b, Double value): setBottomAnchor() method is used to set Bottom anchor.

getBottomAnchor(Node b): getBottomAnchor() method returns bottom anchor.

setLeftAnchor(Node l, Double value): setLeftAnchor() method is used to set left anchor.

getLeftAnchor(Node l): getLeftAnchor() method returns left anchor.

setRightAnchor(Node r, Double value): setRightAnchor() method is used to set right anchor.

getRightAnchor(Node r): getRightAnchor() method returns right anchor.

setTopAnchor(Node t, Double value): setRightAnchor() method is used to set top anchor.

getTopAnchor(Node t): getTopAnchor() method returns top anchor.

How does AnchorPane work in JavaFX?

Accessing JavaFX features user defined class must extends Application class.

1. In JavaFX creating AnchorPane is first step. AnchorPane can instantiate by using new keyword.

Syntax:

AnchorPane anchorPaneRef=new AnchorPane();

2. Creating Label or Button or any JavaFX element is second step.

Syntax:

Label lableRef=new Label(“Any Message”); anchorPaneRef.setTopAnchor(labelRef, value, value);

3. Create VBox or any other display(like TilePane or HBox as per requirement) class to add the items is third step.

Syntax:

VBox vBox=new VBox(anchorPaneRef);

4. Fourth for apply show method on to it.

Syntax:

Step is creating scene.

Scene screen = new Scene(vBox, length, width);

5. Adding Scene reference screen to the Stage object reference is fifth step. Adding output screen to Stage. We will get this stage object reference from start predefined JavaFX method.

Syntax:

stage.setScene(screen);

Syntax:

stage.show(); Examples of JavaFX AnchorPane

Given below are the examples:

Example #1

Anchor pane with Label.

Code:

package com.anchorpanae; import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.control.Label; import javafx.scene.layout.AnchorPane; import javafx.stage.Stage; public class AnchorPaneLabel extends Application { public void start(Stage outStage) { try { outStage.setTitle("AnchorPane Label"); Label lableAnchor = new Label("I am anchor pane lable to show the demo."); AnchorPane anchorPaneObject = new AnchorPane(lableAnchor); AnchorPane.setTopAnchor(lableAnchor, 20.0); AnchorPane.setLeftAnchor(lableAnchor, 100.0); AnchorPane.setRightAnchor(lableAnchor, 20.0); AnchorPane.setBottomAnchor(lableAnchor, 20.0); Scene screen = new Scene(anchorPaneObject, 410, 310); outStage.setScene(screen); outStage.show(); } catch (Exception e) { System.out.println(e.getMessage()); } } public static void main(String args[]) { launch(args); } }

Output:

Example #2

Anchor pane with Buttons.

package com.anchorpanae; import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.ScrollPane; import javafx.scene.layout.AnchorPane; import javafx.scene.layout.VBox; import javafx.stage.Stage; public class AnchorPaneButton extends Application { public void start(Stage outStage) { try { outStage.setTitle("AnchorPane Buttons"); Button button1 = new Button("First Button"); Button button2 = new Button("Second Button"); AnchorPane anchorPaneObject1 = new AnchorPane(button1); anchorPaneObject1.setTopAnchor(button1, 125.0); anchorPaneObject1.setLeftAnchor(button1, 200.0); anchorPaneObject1.setRightAnchor(button1, 100.0); anchorPaneObject1.setBottomAnchor(button1, 500.0); anchorPaneObject1.setMinHeight(500); anchorPaneObject1.setMinWidth(500); AnchorPane anchorPaneObject2 = new AnchorPane(button2); anchorPaneObject2.setTopAnchor(button2, 150.0); anchorPaneObject2.setLeftAnchor(button2, 200.0); anchorPaneObject2.setRightAnchor(button2, 100.0); anchorPaneObject2.setBottomAnchor(button2, 500.0); anchorPaneObject2.setMinHeight(500); anchorPaneObject2.setMinWidth(500) VBox vBox=new VBox(); vBox.getChildren().add(anchorPaneObject1); vBox.getChildren().add(anchorPaneObject2); ScrollPane scrollPnae=new ScrollPane(); scrollPnae.setContent(vBox); Scene screen = new Scene(scrollPnae, 400, 300); outStage.setScene(screen); outStage.show(); } catch (Exception e) { System.out.println(e.getMessage()); } } public static void main(String args[]) { launch(args); } }

Output:

Example #3

Anchor pane with Rectangle shape.

Code:

package com.anchorpanae; import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.layout.AnchorPane; import javafx.scene.paint.Color; import javafx.scene.shape.Rectangle; import javafx.stage.Stage; public class AnchorPaneImage extends Application { public void start(Stage outStage) { try { outStage.setTitle("AnchorPane Rectangle Shape"); Rectangle rectangleShape = new Rectangle(300,200,Color.GREEN); rectangleShape.relocate(70,70); AnchorPane anchorPaneObject = new AnchorPane(rectangleShape); AnchorPane.setTopAnchor(rectangleShape, 20.0); AnchorPane.setLeftAnchor(rectangleShape, 100.0); AnchorPane.setRightAnchor(rectangleShape, 20.0); AnchorPane.setBottomAnchor(rectangleShape, 20.0); Scene screen = new Scene(anchorPaneObject, 500, 400); outStage.setScene(screen); outStage.show(); } catch (Exception e) { System.out.println(e.getMessage()); } } public static void main(String args[]) { launch(args); } }

Output:

Recommended Articles

This is a guide to JavaFX AnchorPane. Here we discuss the introduction, how does AnchorPane work in JavaFX along with constructors, frequently used methods and examples. You may also have a look at the following articles to learn more –

How Does Undefined Work In Javascript?

Introduction to JavaScript undefined

If you want to understand the definition of undefined in JavaScript, you must know the definition of declaration and definition in JavaScript. Declaring a variable in JavaScript with the keyword var is said to be a declaration.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

Example: var name;

Definition: People say assigning a value to a declared variable in JavaScript is the definition.

Example: name=10;

Undefined: JavaScript does not define a declared variable and considers it undefined. We have not assigned any value to the declared variable.

How does undefined work in JavaScript?

As JavaScript is loosely typed (a type of variable is not important), if we do not assign any value to a variable, then automatically JavaScript machine assigns an undefined value to it.

Syntax:

a. var book; b. var obj={}; c. var array=[]; d. var fun=function() { return; }; e. var fun=function(a) { return a; } fun();

Explanation:

In Syntax, a variable book is not defined, so the JavaScript machine assigned undefined as its value.

In Syntax b object variable obj is not defined, so the JavaScript machine assigned undefined as its value.

In Syntax, the c array variable array is not defined, so the JavaScript machine assigned undefined as its value.

In the Syntax d function variable, fun is not returning any value, so the JavaScript machine assigned undefined as its value.

In Syntax e function variable fun is trying to return an undefined value, so the JavaScript machine assigned undefined as its value.

The best way to compare value is the undefined value or not in JavaScript by using the typeof keyword.

Note: The program sets the value of null, while JavaScript internally assigns the value of undefined.

Examples of JavaScript undefined

Examples of the following are given below:

Example #1 – Returning undefined variable

Code:

var name; document.write(“My name is : “+name);

Output:

Explanation:

In the above code, we tried to print an undefined variable name, so we got the output My name is: undefined.

Example #2 – Assigning a value to an undefined variable

Code:

var name; if(typeof name===’undefined’) { name=”Amardeep”; } document.write(“My name is : “+name+” after reassing”);

Output:

Explanation:

We are checking first name variable is “undefined” or not with the type operator

If the condition becomes true, the programmer has not defined the “name” variable.

name variable reassigns to String “Amardeep.”

Printing the reassigned value in the last line.

Example #3 – Printing undefined object value

Code:

var obj={}; document.write(“My object name is : “+obj.name);

Output:

Explanation:

In the above code, we are trying to print an undefined object value name from obj, so we got an undefined value as output.

Example #4 – Assigning a value to the undefined object

Code:

var x={}; if(typeof x.age===’undefined’) { x.age=24; } document.write(“My object value is : “+x.age+” after reassigning age”);

Explanation:

We are checking whether the first age object is “undefined” or not with the typof operator.

If the condition becomes true, the programmer has not defined the age variable.

The age variable reassigns to the number 24.

Printing the reassigned value in the last line.

Example #5 – Printing undefined array value

Code:

var x=[]; document.write(“My array value is : “+x[0]);

Output:

Explanation:

In the above code, we are trying to print the undefined array value of x[0] from the x array, so we got the undefined value as output.

Example #6 – Assigning a value to an undefined array index

Code:

var x=[]; if(typeof x[0]===’undefined’) { x[0]=”Paramesh”; } document.write(“My array value is : “+x[0]+” after reassinging”);

Output:

Explanation:

We are checking first x[0] value is “undefined” or not with typof

The x[0] array value is not defined if the condition becomes true.

X[0] variable reassigns to String “Paramesh.”

Printing the reassigned value in the last line.

Example #7 – Returning an undefined value from the function

Code:

var x=function() { return; }; var output=x(); document.write(“My function value is : “+output);

Explanation:

In the above code, we are trying to print an undefined function value, so we got an undefined value as output.

Example #8

Code:

var x=function() { return; }; output=x(); if(typeof output===’undefined’) { output=”Hi” } document.write(“My function value is : “+output+” after reassigning”);

Output:

Explanation:

We are checking first x() function value is “undefined” or not with typof

The condition cannot become true because we have not defined the value of the x() array.

x() function output stored in a variable name with output.

Output variable reassigns to String “Hi.”

Printing the reassigned value in the last line.

Example #9

Code:

var x=function(number) { return number; }; output=x(); if(typeof output===’undefined’) { output=”I am reassigned” } document.write(“My function value is : “+output);

Output:

Explanation:

First, we define a function with a parameter.

We are checking first if the x() function value is “undefined” or not with typof

The x() function does not define the array value because it does not receive the number argument. Therefore, if the condition becomes true, an error will occur.

x() function output stored in a variable name with output.

Output variable reassigns to String “I am reassigned.”

Printing the reassigned value in the last line.

Conclusion

JavaScript all declared and not defined variables automatically assigned to undefined value through JavaScript Machine. The best way to check whether a variable or function is undefined is by using a typeof operator.

Recommended Articles

This is a guide to JavaScript undefined. Here we discuss how undefined works in JavaScript, along with appropriate Syntax and respective examples. You can also go through our other related articles to learn more–

JavaScript split String

JavaScript Set Class

JavaScript String replace

JavaScript Compare Strings

How Does The Plsql Replace Function Work?

Definition of PLSQL Replace

PL/ SQL REPLACE is a function which allows the replacement of character string with another set of character strings. This function is widely used while programming in case of some spelling mistakes of the data. Instead of deleting the data and interesting again, REPLACE can be used which will modify the data according to the specific requirements. The REPLACE function takes 3 parameters in which one parameter is Optional. It also works great in case of removal of string characters from the particular input string expression. As this function works on the strings, the return type is also a string type but the char set depends on the input string data type.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

Syntax:

REPLACE (string1, string_to_replace [, replacement_string])

where,

string1: The string or expression where the sequence of characters needs to be replaced with other characters. This is basically an input string.

string_to_replace: The string which will be searched in string1 and will be replaced in the expression.

replacement_string: It is an Optional parameter. It is a replacement string. All the occurrences of ‘string_to_replace’ will be replaced with ‘replacement_string’. If the replacement_string is not present in the string expression, all the occurrences of ‘replacement_string’ are removed from the string1.

Return type: The REPLACE function returns the string value to the user.

How does the PLSQL Replace Function Work?

Below given are some of the important points which needs to keep in mind related to the working of REPLACE function in PL/SQL:

The REPLACE function of PL/SQL is used to replace a sequence of string with another set of string/ characters.

It accepts 3 parameters in which 1 parameter is Optional , i.e. string1( input string), string_to_replace (string to be searched), replacement_string (Optional. replacing string).

In case when the string_to_replace( string to be searched) is null, it will return the same string1 (input string expression).

All the parameters, i.e. string1, string_to_replace and replacement_string can be of any data type, i.e. CHAR, VARCHAR2, NVARCHAR2, NCHAR, CLOB. The resulting string is of the same character set as char.

The REPLACE function of PL/ SQL provides the functionality somewhat similar to that of TRANSLATE function, only difference being that TRANSLATE allows one-to-one substitution whereas REPLACE allows replacement of string/ characters, even removal of character strings (in case of omission of Optional parameter).

If the replacement_string is not present in the REPLACE function of PL/ SQL, it works for the removal of string characters. It removes all the occurrences of string_to_replace in the string1. Function returns the removed characters string.

Supported versions Oracle which supports the REPLACE function in PL/ SQL are given below:

Oracle 8i

Oracle 9i

Oracle 10g

Oracle 11g

Oracle 12c

Examples of PLSQL Replace

Some of the examples of PL/ SQL showing the implementation of REPLACE function in the code are given below:

Example #1

Code:

END;

Output:

Explanation: In the above code, string1 or the string expression is ‘hellohello’. REPLACE function used above has 2 parameters, i.e. ‘Tst_String’ which has a string expression and the string_to_replace is ‘h’. There is no replacement_string in the above REPLACE function. So, first, the string ‘hi’ is searched in the string expression and will be removed from it. So, the resulting string expression is ‘elloello’ removing all the occurences of ‘h’.

Example #2

END;

Output:

Explanation: In the above code, string1 or the string expression is ‘hello how are you’. The REPLACE function used above has 3 parameters ‘Tst_String’ which has a string expression, string_to_replace is ‘hello’ and the replacement_string is ‘hi’. Since ‘hello’ is present 1 time in the expression, it would be replaced with ‘hi’ in the input expression. So, the resulting string expression is ‘hi how are you’ in the above code.

Example #3

END;

Output:

Explanation: In the above code, string1 or the string expression is ‘hello how are you’. The REPLACE function used above has the input parameter Tst_String (which is string1), string_to_replace is  ‘are’ and the replacement_string is ‘  ‘ (two blank spaces). So in the string expression, ‘are’ is replaced with the blank spaces. So, the resulting string is ‘hello how you’ in the code mentioned above.

Example #4

Code:

END;

Output:

Explanation: In the above code, string1 or the string expression is ‘hi how are you hi’. So in the function ‘REPLACE’, there are 2 parameters, Tst_String which is string1 and the string_to_replace is ‘hi’. There is no replacement_string parameter written above, so ‘hi’ is removed from the expression (nothing would be replaced). So the resulting string is    ‘   how are you   ‘ replacing all the ‘hi’ from the string expression.

Example #5

END;

Output:

Example #6

 Code:

END;

Output:

Explanation: In the above code, ‘Congratulations to our world’ is the string expression, ‘tua’ is the ‘string_to_replace’ and ‘ih’ is the ‘replacement_string’. So, in the above string expression, there is no string ‘tua’ present. So, if the searchable string is not present in the expression, the resulting string expression remains the same as the string 1. There would be no change in the input string chúng tôi the resulting string in the above code would be ‘Congratulations to our world’.

Conclusion

The above description clearly explains what the REPLACE function is and how it works in PL/SQL. Though Oracle also provides the TRANSLATE function which works similar to that of REPLACE only one-to-one substitution is allowed in it whereas REPLACE allows the substitution of a sequence of the whole string. For a programmer, it is important to understand both of them and the difference between them to have a clear understanding.

Recommended Articles

This is a guide to PLSQL Replace. Here we also discuss the definition and how does the PLSQL Replace function works? along with different examples and its code implementation. You may also have a look at the following articles to learn more –

Update the detailed information about How Does Continuation Statement Work? on the Eastwest.edu.vn website. We hope the article's content will meet your needs, and we will regularly update the information to provide you with the fastest and most accurate information. Have a great day!