Call SQL Server functions via Oracle database link - sql-server

Is there a way to execute the following statement from Oracle using a database link to a SQL Server instance without having to create a view on the target instance?
select db_name(), ##SERVERNAME
I have tried
"select db_name(), ##SERVERNAME"#DbLink
but that did not succeed.
Any help would be greatly appreciated

Here:
select dbo.FunctionName#dblink('value') from dual;
But you need to tell the dblink which functions must be available through the dblink. See the manual at: http://docs.oracle.com/cd/E11882_01/server.112/e11050/admin.htm#i1007467

Related

Azure - How to execute UDF from external data source in select statement

I have an external data source created in DB1 and its pointing to DB2 database in Azure.
I want to query a UDF defined in DB2 from DB1.
Following syntax works, from DB1:
EXEC sp_execute_remote
N'Ext_DB2',
N'SELECT Result'
But I want to use following syntax:
select C1, C2, < function_in_DB2 >
from t1
I tried searching web, this format is not mentioned anywhere, is it not supported? Any pointers will help.
Thanks !
Just per my experience, I think Azure SQL database doesn't support it. As we know, we can't do cross database query directly.
Since none document talk about this, I would suggest you ask Azure SQL support to get more support, ref: How to create an Azure support request.
Hope this helps.

DB Link from Oracle to MS Server

I am new to this forum and already searched for 45 minutes to find a solution for my problem. I hope you can help me.
A Gateway to a remote Microsoft SQL Database was installed on a Oracle Server (Oracle 12c). The tsnnames.ora file was appropiately set up.
For the connection, I created a database link (In the Oracle DB) as follows:
CREATE DATABASE LINK TEL CONNECT TO "fb_B2C" IDENTIFIED BY "passwort" USING 'dg1msql';
When I now execute the Select statement:
SELECT "name" FROM "sys"."databases"#TEL
it shows me the according databases. Among others, I can see the AB_Colors database.
Now, I want to select a view in the AB_Colors database.
Due to the fact I can connect to this database via Excel, I know that in the database AB_Colors, there are 10 Views(A,B,C,..). I would like to select the View C from the database AB_Colors via the DB LInk.
Owner of the View is b2b.
How do i need to formulate the select statement to do it?
I already tried different writings:
SELECT * FROM b2b.C#TEL;
SELECT * FROM "AB_colors"."b2b"."C"#TEL;
SELECT * FROM [AB_Colors].[b2b].[C]#TEL;
The common error message is: View/Table does not exist
I highly appreciate your help,
Fedja
This is the correct format
SELECT * FROM "b2b"."C"#TEL;
The issue maybe because the database you want to select from is not the one specified in the gateway for dg1msql. You can't add the database name to the query so you must specify it in the gateway connection.
This is defined in
$ORACLE_HOME/dg4msql/admin/initdg4msql.ora
where you should check HS_FDS_CONNECT_INFO

how can I enumerate the databases of a sql server

Given an instance of SQL server, what's the best way to enumerate the databases?
In SQL Server 2000+:
select * from sysdatabases
In SQL Server 2005+:
select * from sys.databases
The difference is subtle and barely worth mentioning for a one-liner like this. But depending on how much you're going to be accessing the system catalog, you may get some use out of this article:
Querying the SQL Server System Catalog
You can also execute sp_helpdb without an argument to get basic information about all databases. (Pass in a database name as an argument to get more detailed information about that database).
Try this:
SELECT [name] FROM sys.sysdatabases
You could also get this from exec sp_databases;
These commands will work from SQL 2000+.
EXECUTE master.sys.sp_MSforeachdb 'USE [?]; EXEC sp_spaceused'

On SQL Server 2008, how to find out when was any database offline/online?

I have to include one report in my application showing offline/online activity of few databases on SQL Server 2008.
Could you please suggest how can I collect teh same information from sql server?
SELECT DATABASEPROPERTYEX('YOURDATABASE', 'Status')
DatabaseStatus_DATABASEPROPERTYEX
GO
SELECT state_desc DatabaseStatus_sysDatabase
FROM sys.databases
WHERE name = 'YOURDATABASE'
GO
This will tell you the status of the database.
In order to find out when your database was taken OFFLINE, you can use the SQL that I posted before, or the easiest way is to check the Event Viewer and it will tell you when the Database was taken OFFLINE. I have just tested this on my local machine and SQL Server writes out an Information message to the Application log.
You can also use below query to check database status.
SELECT Name, state_desc FROM sys.databases

Querying a view that's not located on the same server (SQL Server 2005)

I'm trying to query a database view that's not located on the same server as the stored procedure I'm running.
I heard about using "linked servers", but I have no access to the server's configuration at all ...
Thanks in advance !
Use OPENDATASOURCE:
SELECT *
FROM OPENDATASOURCE(
'SQLOLEDB',
'Data Source=ServerName;User ID=MyUID;Password=MyPass'
).Northwind.dbo.Categories
You can do this, but it does require the DBA to set up the link. If you don't have access to the server's configuration and the DBA is not on board, you're out of luck.

Resources