Detemining a database's OS with a SQL query? - sql

I'm writing a tool to gather customer configuration information. One of the questions I want to answer, what OS is the customer database running on.
I haven't found a generic way to find the OS with SQL and I can't create stored procedures on the customer's database.
If there is a way, it's probably vendor specific.
Suggestions? Thanks in advance.

Yes, it will be vendor specific. For Oracle you can obtain it via this query:
SQL> select banner from v$version;
BANNER
----------------------------------------------------------------
Oracle9i Enterprise Edition Release 9.2.0.8.0 - 64bit Production
PL/SQL Release 9.2.0.8.0 - Production
CORE 9.2.0.8.0 Production
TNS for Solaris: Version 9.2.0.8.0 - Production
NLSRTL Version 9.2.0.8.0 - Production
The 4th row of output shows that my 9i database is running on Solaris (well, it shows that it is running "TNS for Solaris", which implies that the OS is Solaris anyway).

For Oracle, you could use
SELECT DBMS_UTILITY.PORT_STRING FROM dual;
(From Ask Tom)

how about:
select platform_name from v$database;

sybase ASE & Sybase IQ are the same as sqlserver: select ##version
eg
Sybase IQ/12.7.0/090824/P/ESD 7/Sun_Sparc/OS 5.9/64bit/2009-08-24 16:17:12
Adaptive Server Enterprise/12.5.3/EBF 12455 ESD#2/P/Sun_svr4/OS 5.8/ase1253/1904/64-bit/FBO/Wed Mar 23 03:04:04 2005

Related

Oracle SQL alternative to using DEFINE

I'm currently using
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0
PL/SQL Release 12.1.0.2.0
The following doesn't work for me ...
-- Since PL/SQL 20.2.0.175
DEFINE usr = 'YourName';
SELECT * FROM Department WHERE CreatedBy = '&usr';
Can someone give me an equivalent for my version?
Thanks!

How would I obtain the versions/dialects of SQL used for these online SQL editors?

I am learning SQL by running test queries using online SQL editors below.
https://www.w3schools.com/sql/trysql.asp?filename=trysql_asc
https://www.mycompiler.io/new/sql
http://sqlfiddle.com/
I've noticed that each editor has some different keywords/syntax that it supports/ doesn't support. For example, 1 supports "WITH temp_table AS (some_query) SELECT ... " which I couldn't get to work on the other two. Also, 3 supports copying a table using "CREATE TABLE new_table SELECT * FROM old_table" which I couldn't get to work on the other 2.
Can someone shed some light on the different dialects of SQL and which are used for these online editors?
WITH is not supported in SQLite until v3.8.3, and not on MySQL until v8, which is why that only works on 1, and SQLite lacks the SELECT INTO ability, which is why that only works on 3. Some of those SQL engines on sqlfiddle should support the WITH construction, though. I tested with this:
WITH temp_table AS (select * from test)
SELECT * FROM temp_table;
and every engine allowed it EXCEPT mySQL, which is expected because it didn't support WITH in 5.6.
Thanks to Jeroen Mostert for pointing out that not every browser supports WebSQL, so the version shown for those (the SQLite engines) will depend.
Number 1 (w3schools) as of 11/24/2021, SQLite 3.36.0.
Number 2 (mycompiler), SQLite 3.7.17.
Number 3 (sqlfiddle), lets you choose the engine, and they are:
MySQL 5.6.48;
Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production;
PostgreSQL 9.6.17 on x86_64-pc-linux-gnu (Debian 9.6.17-2.pgdg90+1), compiled by gcc (Debian 6.3.0-18+deb9u1) 6.3.0 20170516, 64-bit;
PostgreSQL 9.3.25 on x86_64-pc-linux-gnu (Debian 9.3.25-1.pgdg90+1), compiled by gcc (Debian 6.3.0-18+deb9u1) 6.3.0 20170516, 64-bit;
SQLite Web SQL: 3.36.0 (this is using whatever your browser uses, as pointed out by Jeroen Mostert in comments);
SQLite js: 3.15.1;
Microsoft SQL Server 2017 (RTM-CU2) (KB4052574) - 14.0.3008.27 (X64) Nov 16 2017 10:00:49 Copyright (C) 2017 Microsoft Corporation Express Edition (64-bit) on Linux (Ubuntu 16.04.3 LTS);
And I determined these with the following methods:
MySQL, SQL Server: SELECT ##version;
Oracle: SELECT * FROM V$VERSION;
PostGRE: SELECT version();
SQLite: SELECT sqlite_version()

Oracle - query failed statements

Is there a view (or other method) in Oracle, from which I can extract the failed sql statements, which were executed by the user? I tried to check v$sql but, as it turned out, it contains only the successful ones. I'm using Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production.
Thank You.
Blaim me if I'm wrong but as far as I understand sql gets logged on shared pool check and statements Laszlo mentioned select nonexistingcolumn from dual; failed on semantic check. My answer is you won't find invalid statements in DB.
https://docs.oracle.com/database/121/TGSQL/tgsql_sqlproc.htm#TGSQL178

Oracle CONNECT_BY query.

SELECT LPAD('*', 2*level-1)||SYS_CONNECT_BY_PATH(unit_data, '/') "battle_unit_id"
FROM battle_units
START WITH battle_unit_id= 600
CONNECT BY PRIOR parent_id = battle_unit_id;
returns
/Doctrine
/Doctrine/Air
/Doctrine/Air/Jet powered aircraft
/Doctrine/Air/Jet powered aircraft/F-16
All i want is just /Doctrine/Air/Jet powered aircraft/F-16 without the other three results. Is there a way for that?
Edit:
My oracle version:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - Production
PL/SQL Release 11.2.0.3.0 - Production
CORE 11.2.0.3.0 Production
TNS for Linux: Version 11.2.0.3.0 - Production
NLSRTL Version 11.2.0.3.0 - Production
If I understand you correctly, you just want the leafs of the tree:
SELECT LPAD('*', 2*level-1)||SYS_CONNECT_BY_PATH(unit_data, '/') "battle_unit_id"
FROM battle_units
WHERE connect_by_isleaf = 1 -- <<< this selects only the leaf nodes
START WITH battle_unit_id= 600
CONNECT BY PRIOR battle_unit_id = parent_id;
See the manual for details: http://docs.oracle.com/cd/E11882_01/server.112/e26088/pseudocolumns001.htm#SQLRF00251
If you know the exact level where that line is going to occur this is doable.
Please see this fiddle.
Edit:
Since you are going for the max, this may work for you.

How to determine SQL server version number for Compact edition 4 up to full sql server 2008?

Lot's of people have asked and been responded to about how to determine the version of the sql server using things like ##VERSION, or SERVERPROPERTY('productversion') but none of these work with sql server compact edition 4.
Is there some universally supported method to determine which sql server edition and version is in use through a sql query or ado.net code that works for compact edition all the way to full sql server?
I want to determine which exact edition / version of SQL server is in use so I know what type of paging query to issue from my code. Sql CE 4 uses a new format for paging queries same as sql server 2011 (denali) and 2005 and 2008 have their own method that is unsupported in CE 4.
I think the answer is that it's impossible but I just want to be sure I didn't overlook something.
I don't really work with SQL Server anymore but here is my attempt at this little problem.
For version 4 of compact edition the following should give you the version and build.
var ver = new System.Data.SqlServerCe.SqlCeConnection().ServerVersion;
And the following should give you the assembly version
var version = typeof(System.Data.SqlServerCe.SqlCeConnection).Assembly.GetName().Version;
Take a look at this blog post. It has a link to download a utility that detects which version of SQL Compact edition you're running. It also has a link to the source code for the utility which may be of interest to you.
You can use PowerShell , in versions of Windows 7 or newer , it comes pre- installed by default. Use the following command lines :
[System.Reflection.Assembly]::LoadFrom("SQLCeAssembly.dll").GetName().Version
Outputs this:
Major Minor Build Revision
----- ----- ----- --------
4 0 0 0
run this
SELECT SERVERPROPERTY('productversion'), SERVERPROPERTY ('productlevel'), SERVERPROPERTY ('edition')
See details here