Oracle equivalent of suser_name() used in SQL Server - sql

What is the Oracle equivalent of suser_name() used in SQL Server

Mostly they use SYS_CONTEXT for tracking and auditing purposes like the one below :
SELECT SYS_CONTEXT ('USERENV', 'SESSION_USER')
FROM DUAL;

we can get the login identification name of the user by using SUSER_NAME ( [ server_user_id ] ) on SQL Server
try Use the FND_USER table on oracle .
use sif you have the Server_user_id

Related

How to Select Table SQL To Oracle

I want to select data from SQL Server to Oracle (Toad Apps).
If from Oracle to SQL Server its done like this
Insert Into M_CLASSIFICATION_ORACLE
SELECT * From OPENQUERY ([B1APPS], 'select * from V_Classification_Asset' ) AS derivedtbl_1
How about in Oracle (Toad apps)?
You can able to do it by using CREATE DATABASE LINK:
Create a Database Link to connect to SQL Server:
CREATE DATABASE LINK link-name ...
Query SQL Server using the Database Link:
SELECT * FROM sqlserver-table-name#link-name;
Documentation:
https://www.oracletutorial.com/oracle-administration/oracle-create-database-link/
Calling Stored Procedure using Database Link:
https://dba.stackexchange.com/questions/1856/running-a-stored-procedure-across-db-link

select statement ORA-00933: SQL command not properly ended

SELECT tab1.column1 FROM DB2.Schema.table1 tab1;
I try to execute this above query from Database 1. The table1 exist in DB2 database. It showing following error.
ORA-00933: SQL command not properly ended
00933. 00000 - "SQL command not properly ended"
No need to mention database name in your select statment. See below:
SELECT tab1.column1 FROM Schema.table1 tab1;
DB Link Usage:
CREATE DATABASE LINK sales.hq.acme.com
CONNECT TO scott IDENTIFIED BY tiger
USING 'sales';
Once this database link is created, you can query tables in the schema SCOTT on the remote database in this manner:
SELECT *
FROM emp#sales.hq.acme.com;
You can also use DML statements to modify data on the remote database:
INSERT INTO accounts#sales.hq.acme.com(acc_no, acc_name, balance)
VALUES (5001, 'BOWER', 2000);
UPDATE accounts#sales.hq.acme.com
SET balance = balance + 500;
DELETE FROM accounts#sales.hq.acme.com
WHERE acc_name = 'BOWER';
You can also access tables owned by other users on the same database. This statement assumes SCOTT has access to ADAM's DEPT table:
SELECT *
FROM adams.dept#sales.hq.acme.com;
The previous statement connects to the user SCOTT on the remote database and then queries ADAM's DEPT table.
Note: Dblinks are used using '#' symbol.
You don't need to prefix the db. Just make sure you are in the right schema using:
ALTER SESSION SET current_schema = schemaname;

How to find linked_server name in sql server management studio?

I am trying to query the following in sql server management studio:
select colname from openquery (linked_server, 'exec XX.YY.PrcName #Parameter')
When i try to give XX as linked server name i am getting an error.
Is that right or how do i find the linked_server name ?
To check linked server name :
select * from sys.sysservers
you can easily run any procedure in another server through linked server as:
exec <procedure name><parameneters> at <linked server name>
To get a list of linked servers use:
EXEC SP_LINKEDSERVERS
If you want to SELECT something from Linked server:
SELECT *
FROM [SOMESERVER\SOMEINSTANCE].somedatabase.dbo.sometable;
To EXECUTE something on linked server:
EXEC [SOMESERVER\SOMEINSTANCE].somedatabase.dbo.somestoredprocedure
SELECT *
FROM OPENQUERY([SOMESERVER\SOMEINSTANCE].somedatabase.dbo.somestoredprocedure)
More info:
sqlauthority
MSDN
You also can use sys.servers
Select * From SYS.SERVERS
When server_id = 0, this is the server name.
When server_id >0 , this is the local name of linked server.

How do you reference a second SQL Server

How can I reference a second server in SQL.
SELECT A.datasetid,
A.dsdate,
B.datasetid AS Expr1,
B.dsdate AS Expr2
FROM we_ci_db.tblopportunitydatasets AS A
INNER JOIN we_ci_db.tblopportunitydatasets AS B
ON A.datasetid = B.datasetid
Assume that table 'B' is on a different server, what would the syntax be. I've tried putting the server name before the schema, but it doesn't recognise it
You must configure a linked server. Once that is configured, the linked server may be referenced as
server.database.schema.object
You'll first need to create a Linked Server by running the addlinkedserver stored procedure:
USE [master]
GO
EXEC master.dbo.sp_addlinkedserver
#server = N'SRVR002\ACCTG',
#srvproduct=N'SQL Server' ;
GO
After that, you can refer to the linked server with the syntax:
select *
from [SRVR002\ACCTG].[database name].[owner name].[table name]
More Info

How can I get all the database names in a sql server instance using tsql?

How can I get all the database names in a sql server instance using tsql?
SELECT * FROM sys.databases
----SQL SERVER 2005 System Procedures
EXEC sp_databases
EXEC sp_helpdb
----SQL 2000 Method still works in SQL Server 2005
SELECT name
FROM sys.databases
SELECT name
FROM sys.sysdatabases
----SQL SERVER Un-Documented Procedure
EXEC sp_msForEachDB 'PRINT ''?'''
to know more about database : http://blog.sqlauthority.com/2007/05/12/sql-server-2005-list-all-the-database/
this should work on pretty much any version of sql server
USE master;
SELECT NAME FROM sysdatabases;
[edit : it could be SELECT NAME FROM sys.databases too, microsoft's website says both and i'm not on my windows box to test, sorry!]
you could also use (sql 2005 only)
USE master;
EXEC sp_databases;
And for practical use added couple of common filters:
select database_id, [name] database_name
from master.sys.databases
WHERE state <> 6 -- skip offline
AND database_id > 4 -- skip system dbs
AND HAS_DBACCESS([name]) = 1 -- with User Access
SQL 2000
use master
select name from sysdatabases
or
(no need for use master, includes database_size)
exec sp_databases