How to Change the Date Format in your Oracle Session

When working with functions that return dates, Oracle Database returns these dates based on the value of the NLS_DATE_FORMAT parameter.

There is also an NLS_TIMESTAMP_FORMAT parameter and an NLS_TIMESTAMP_TZ_FORMAT parameter, both of which have a datetime format mask that can be specified separately.

All of these parameters have their default values derived from the NLS_TERRITORY parameter (which by default, is operating system-dependent).

So, to change the date format for your session, you can either update the NLS_TERRITORY parameter, or explicitly update each parameter individually.

This article provides examples of checking and changing these values, and viewing the results.

Continue reading

Return the Current Workstation Name that’s Connected to SQL Server (T-SQL)

Occasionally you might find yourself in the situation where you need to get the name of the current workstation that’s connected to SQL Server.

For example, maybe you have a stored procedure that inserts data, and you want to record the name of the workstation that inserted the data.

In such cases, you can use the HOST_NAME() function.

This is not to be confused with getting the server name.

Continue reading

Remove Duplicates when using $unionWith in MongoDB

In MongoDB, the $unionWith aggregation pipeline stage performs a union of two collections, and it includes duplicates.

This behaves in a similar way to SQL’s UNION ALL, which also includes duplicates. By contrast, using just UNION (i.e. without the ALL)in SQL removes duplicates.

In MongoDB, we don’t have the option of specifying $unionWith ALL or similar, so we need to reduce duplicates in another way.

In MongoDB, we can remove duplicates by using the $group stage.

Continue reading

SET SQLBLANKLINES: How to Allow Blank Lines in SQLcl & SQL*Plus

If you’re trying to run a multi-line query in SQLcl or SQL*Plus, and you keep getting an error such as “Unknown Command”, but running it in SQL Developer causes no such error, maybe this post will help.

By default, SQLcl and SQL*Plus don’t allow blank lines in SQL statements. However, you can change this with the SET SQLBLANKLINES command.

Continue reading