I linked an Oracle Database to my SQL Server in Microsoft SQL Server Management Studio 18. Server Objects -> Linked Servers.
I have a SQL Statement that when I run on the Oracle Developer Tool/Platform it returns the information as expected. But when I run the exact same query on the SQL Server it returns the incorrect results (The actual values in the rows and columns do not match).
What I know.
The table I am query in lives in the Oracle Database.
I can get the same/matching results on the Oracle Developer and SQL Server if I exclude in my WHERE statement anything involving a DATE.
Any thoughts?
The example of the query below.
Works on Oracle Developer but not on MSSQL
SELECT * FROM TABLE1
WHERE status = 'Deviation' and trunc(SRC_ROW_UPDT) BETWEEN TO_DATE('01/03/2020', 'DD/MM/YYYY') AND TO_DATE('10/12/2020','DD/MM/YYYY');
The example of the query below.
Works on both Oracle Developer and MSSQL
SELECT * FROM TABLE1
WHERE status = 'Deviation' and BATCHID = 'ThisBAtchID';
You cannot use ORACLE specific functions like TO_DATE in SQL Server calls. You have to execute them remotely using OPENQUERY. OPENQUERY in MSDN
SELECT * FROM OPENQUERY (OracleSvr, 'SELECT * FROM TABLE1
WHERE status = ''Deviation'' and trunc(SRC_ROW_UPDT) BETWEEN TO_DATE(''01/03/2020'', ''DD/MM/YYYY'') AND TO_DATE(''10/12/2020'',''DD/MM/YYYY'');');
I am writing a performance/system monitoring tool to augment load testing for my team's product and I am trying to store database system information with the results bundle but do not know how to write the query to capture this in Oracle (I'm a developer not a DBA).
I have this all working the way I want for SQL Server, but I need to do the same for Oracle. Below is a query I found online for this is SQL Server:
SELECT CONVERT(varchar(128),SERVERPROPERTY('ComputerNamePhysicalNetBIOS')) AS 'computerNamePhysicalNetBIOS',
CONVERT(varchar(128),SERVERPROPERTY('MachineName')) AS 'machineName',
CONVERT(varchar(128),SERVERPROPERTY('Edition')) AS 'edition',
CONVERT(varchar(128),SERVERPROPERTY('ProductLevel')) AS 'productLevel',
CONVERT(varchar(128),SERVERPROPERTY('ProductVersion')) AS 'productVersion',
CONVERT(varchar(128),SERVERPROPERTY('BuildClrVersion')) AS 'buildClrVersion',
CONVERT(INT,SERVERPROPERTY('ProcessID')) AS 'processID',
CONVERT(INT,SERVERPROPERTY('EngineEdition')) AS 'engineEdition',
CONVERT(INT,SERVERPROPERTY('HadrManagerStatus')) AS 'hadrManagerStatus',
CONVERT(INT,SERVERPROPERTY('IsHadrEnabled')) AS 'hadrEnabled',
CONVERT(INT,SERVERPROPERTY('IsAdvancedAnalyticsInstalled')) AS 'advancedAnalyticsInstalled',
CONVERT(INT,SERVERPROPERTY('IsClustered')) AS 'clustered',
CONVERT(INT,SERVERPROPERTY('IsPolybaseInstalled')) AS 'polybaseInstalled',
CONVERT(INT,SERVERPROPERTY('IsXTPSupported')) AS 'xtpSupported',
CONVERT(INT,SERVERPROPERTY('LCID')) AS 'lcid',
CONVERT(varchar(128),SERVERPROPERTY('ResourceVersion')) AS 'resourceVersion',
CONVERT(varchar(128),SERVERPROPERTY('ServerName')) AS 'serverName',
CONVERT(varchar(128),APP_NAME() )AS 'appName',
CONVERT(INT,DB_ID()) AS 'dbId',
CONVERT(varchar(128),DB_NAME()) AS 'dbName'
I don't really expect a one-to-one column match between the above query and Oracle's version, but in general, how can I get very similar information from Oracle?
I don't really expect a one-to-one column match between the above
query and Oracle's version, but in general, how can I get very similar
information from Oracle?
Most of that stuff, if it exists at all in the Oracle database, will be accessible through V$ views in the Oracle database. To get you started, here are some that are going to be most relevant to answering your question:
select * from v$instance;
select * from v$version;
select * from v$sql_feature;
select * from v$license;
select * from v$option;
If you want to get a complete list of V$ views to look around better,
select * from dict where table_name like 'V$%';
Some of those things are specific to MSSQL and have no meaning in Oracle. But you can get many of them with sys_context() using the userenv namespace.
For instance, to get the database name:
select sys_context('userenv', 'DB_NAME') as db_name
from dual;
I have few tables I need to load from linked firebird server into SQL Server from time to time. I use statement like this:
SELECT * into dekr FROM OPENQUERY ( [PLINK] ,'select * from dekr' )
It takes a while since it's going over network etc, is there a way to update once created
table dekr only with changes since last time?
thanks
If I run the following SQL in SQL Server CE,
alter table audit add new_key nvarchar(100) null
Can that be changed to check whether the column exists before trying to add it in the same SQL statement? I am aware you can do that quite easily in SQL Server, but SQL Server CE?
If you are looking for something like you can do with SQL server: IF NOT EXISTS (..., unfortunately, this is not possible with SQL Server Compact (the T-SQL IF is not supported). See SQL Reference (SQL Server Compact).
Based on this thread, you can do something like this:
select * from Information_SCHEMA.columns
where Table_name='audit' and column_name='new_key'
(ie no result = does not exist).
Also note that batch queries are not supported in SQL Server Compact at all. So you can't check if the column exists and add the column if needed in the same SQL statement.
Or if you are looking for a snippet that you can use with VB.NET or C#, take a look at this SO question: How can I determine whether a column exists in a SQL Server CE table with C#?
The easiest way would be to query information_schema and see if the column is in there.
IF NOT EXISTS(
SELECT * FROM information_schema.columns
WHERE Table_Schema = 'dbo'
AND Table_Name = 'audit'
AND Column_Name = 'new_key'
) BEGIN
alter table audit add new_key nvarchar(100) null
END
I just recently moved a SQL DB from SQL2005 32 bit --> 64 bit. I am having an issue connecting to Oracle using the OraOLEDB.Oracle Provider.
I was able to install Oracle 10G Client , ODAC 64 bit. I was also able to add a linked server to the Oracle instance. I am able to run a query using the linked server name directly:
SELECT top 10 *
FROM [DB0PBB0]..[DB0PBB0].[DM_CLICK]
So far it is good, however, the problem occurs when I try to use OPENQUERY. I tried the following:
select * from
OPENQUERY(DB0PBB0,'select * from DB0PBB0.DM_CLICK where Date_stamp <''24-Jul-09'' and Date_stamp >= ''23-Jul-09'' ')
SET FMTONLY OFF
select * from
OPENQUERY(DB0PBB0,'select * from DB0PBB0.DM_CLICK where Date_stamp <''24-Jul-09'' and Date_stamp >= ''23-Jul-09'' ')
and I get only the column names, no rows :(
if I run this script:
SET FMTONLY OFF
select * from
OPENQUERY(DB0PBB0,'select ''hello'' from dual ')
I get
hello
My question is, has anyone tried running OPENQUERY against Oracle from a SQL05 64bit ? Any ?Idea why would I get only columns back instead of data? I tried the same query on another server with the same link and it worked, it returned rows.
since you are getting rows with the SELECT * FROM DUAL chances are that it is a query issue. Regarding your query one potential pitfall is that you are comparing what looks like a date column (DATE_STAMP) with a VARCHAR.
You should not rely on implicit conversions to compare dates. Instead you should use the appropriate explicit functions, for exemple:
select * from
OPENQUERY(DB0PBB0,'select *
from DB0PBB0.DM_CLICK
where Date_stamp < to_date(''24-Jul-09'', ''dd-mon-rr'')
and Date_stamp >= to_date(''23-Jul-09'', ''dd-mon-rr'')')