Samual Sam has Published 2310 Articles

MySQL query to retrieve records from the part of a comma-separated list?

Samual Sam

Samual Sam

Updated on 30-Jul-2019 22:30:25

530 Views

To retrieve records from the part of a comma-separated list, you can use built in function FIND_IN_SET().Let us first create a table −mysql> create table DemoTable    (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    Name varchar(20),    Marks varchar(200)    ); Query OK, 0 rows affected (0.61 ... Read More

Count distinct value in MongoDB?

Samual Sam

Samual Sam

Updated on 30-Jul-2019 22:30:25

398 Views

Use the concept of length to count distinct value. Following is the syntax −db.yourCollectionName.distinct("yourFieldName").length;Let us create a collection with documents −> db.countDistinctDemo.insertOne({"StudentName":"John"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cbd6166de8cc557214c0dfa") } > db.countDistinctDemo.insertOne({"StudentName":"Chris"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cbd616ade8cc557214c0dfb") } > db.countDistinctDemo.insertOne({"StudentName":"Chris"}); {    "acknowledged" : ... Read More

ByteBuffer asLongBuffer() method in Java

Samual Sam

Samual Sam

Updated on 30-Jul-2019 22:30:25

110 Views

A view of the ByteBuffer can be created as a LongBuffer using the asLongBuffer() method in the class java.nio.ByteBuffer. This method requires no parameters and it returns a long buffer as required. This buffer reflects the changes made to the original buffer and vice versa.A program that demonstrates this is ... Read More

Duration of() method in Java

Samual Sam

Samual Sam

Updated on 30-Jul-2019 22:30:25

223 Views

The required duration using a particular temporal unit can be calculated with the method of() in the Duration class in Java. This method requires two parameters i.e. the time value and the temporal unit for that value. It returns the time duration with the particular value and temporal unit.A program ... Read More

What is the PHP equivalent of MySQL's UNHEX()?

Samual Sam

Samual Sam

Updated on 30-Jul-2019 22:30:25

637 Views

You can use hex2bin() function since it is the PHP equivalent of MySQL's UNHEX().The syntax is as follows −$anyVariableName = hex2bin("yourHexadecimalValue");To understand the above syntax, let us implement the above syntax in PHP. The PHP code is as follows −$myFirstValue = hex2bin("7777772E4D7953514C4578616D706C652E636F6D"); var_dump($myFirstValue); $mySecondValue=hex2bin("416476616E6365644A617661576974684672616D65776F726B"); echo(''); var_dump($mySecondValue);The snapshot of PHP code ... Read More

Setting column values as column names in the MySQL query result?

Samual Sam

Samual Sam

Updated on 30-Jul-2019 22:30:25

4K+ Views

To set column values as column names in the query result, you need to use a CASE statement.The syntax is as follows −select yourIdColumnName, max(case when (yourColumnName1='yourValue1') then yourColumnName2 else NULL end) as 'yourValue1', max(case when (yourColumnName1='yourValue2') then yourColumnName2 else NULL end) as 'yourValue2', max(case when yourColumnName1='yourValue3') then yourColumnName2 else ... Read More

What is a Quartet class in JavaTuples?

Samual Sam

Samual Sam

Updated on 30-Jul-2019 22:30:25

128 Views

A Quartet class is a Tuple of four elements. It is part of the JavaTuples library.The following is the declaration −public final class Quartet extends Tuple implements IValue0, IValue0, IValue0, IValue0Let us first see what we need to work with JavaTuples. To work with Quartet class in JavaTuples, you need ... Read More

Instant toString() method in Java

Samual Sam

Samual Sam

Updated on 30-Jul-2019 22:30:25

257 Views

The range of values for a field can be obtained using the range() method in the Instant class in Java. This method requires a single parameter i.e. the ChronoField for which the range of values are required and it returns the range of valid values for the ChronoField.A program that ... Read More

Java Program to evaluate mathematical expressions in String

Samual Sam

Samual Sam

Updated on 30-Jul-2019 22:30:25

3K+ Views

To evaluate mathematical expression in String, use Nashorn JavaScript in Java i.e. scripting. Nashorn invoke dynamics feature, introduced in Java 7 to improve performance.For scripting, use the ScriptEngineManager class for the engine −ScriptEngineManager scriptEngineManager = new ScriptEngineManager(); ScriptEngine scriptEngine = scriptEngineManager.getEngineByName("JavaScript");Now for JavaScript code from string, use eval i.e. execute ... Read More

MySQL query to get a substring from a string except the last three characters?

Samual Sam

Samual Sam

Updated on 30-Jul-2019 22:30:25

810 Views

For this, you can use SUBSTR along with length().Let us first create a table −mysql> create table DemoTable    (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    FirstName varchar(20)    ); Query OK, 0 rows affected (1.31 sec)Following is the query to insert some records in the table ... Read More

Advertisements