How to Query Database Name in Oracle SQL Developer? - sql

How do I query the database name in Oracle SQL Developer? I have tried the following and they all fail:
SELECT DB_NAME();
SELECT DATABASE();
Why do these basic MySQL queries fail in SQL Developer? Even this one fails too:
show tables;
EDIT: I can connect to the database and run queries such as:
select * from table_name_here;
EDIT 2: The database type is Oracle, this is why MySQL queries are failing. I thought it was related to the database client not the database itself. I was wrong. I'll leave the question as is for other as lost as I was.

Once I realized I was running an Oracle database, not MySQL, I found the answer
select * from v$database;
or
select ora_database_name from dual;
Try both. Credit and source goes to: http://www.perlmonks.org/?node_id=520376.

try this:
select * from global_name;

You can use the following command to know just the name of the database without the extra columns shown.
select name from v$database;
If you need any other information about the db then first know which are the columns names available using
describe v$database;
and select the columns that you want to see;

I know this is an old thread but you can also get some useful info from the V$INSTANCE view as well. the V$DATABASE displays info from the control file, the V$INSTANCE view displays state of the current instance.

Edit: Whoops, didn't check your question tags before answering.
Check that you can actually connect to DB (have the driver placed? tested the conn when creating it?).
If so, try runnung those queries with F5

To see database name,
startup;
then type
show parameter db_name;

DESCRIBE DATABASE NAME; you need to specify the name of the database and the results will include the data type of each attribute.

Related

How to move table data from one environment to another environment in Oracle

I am a novice Oracle User.
I want to move a table records from QA to Test environment. The table already exists in Test. Would it be something like this ?
insert into wKTest01.MyTableIWantToMove select * from wkQA01.MyTableIWantToMove ;
Any help is greatly appreciated.
Both the tables in both environments have same number of columns with same data types.
You can use database links in Oracle to do this.Create a database link in your test database called myQADBLink which points to your QA DB.
The code would look something like this
CREATE DATABASE LINK myQADBLink CONNECT TO <username> identified by
<password> USING
'<QA DBconnect string>';
SELECT 1 FROM dual#myQADBLink; -- This is to test if your dblink is created properly.
Now you can copy from QA to test by saying
INSERT INTO wKTest01.MyTableIWantToMove select * from wkQA01.MyTableIWantToMove#myQADBLink;
Yes, it actually exists, right like you put it.
Here is the full syntax guide for this: http://docs.oracle.com/cd/E17952_01/refman-5.1-en/insert-select.html.
Later, when you might place your tables at the different Oracle instances, google 'Orace DBLink' for the good ;)

Querying another DB while connecting to other Database in SQL

In my SQL script I am using one database(Lets assume MyDb1).
In side that script I need to query extended property of another DB (MyDb2).
I have no Idea to do this.
Please advise me.
You can use this Query :
SELECT * FROM MyDb1.DBO.TableName as tbl1,MyDb2.DBO.TableName as tbl2
WHERE tbl1.ID=tbl2.ID

Access 2007 to Oracle 10g linked table -- query with flawed results, but no errors thrown

Access 2007 databases querying linked oracle 10g tables are returning flawed result sets when using the WHERE clause to filter-out unwanted records. Oddly, some filtering is happening, but not reliably.
I can reliably demonstrate/produce the problem like this:
Create a *new* database with Access 2007.
Create a second *new* database with Access 2007, and then "save-as" 2000.
Create a third *new* database with an older version of Access.
Run the following query in each database:
SELECT
STATUS,
ID,
LAST_NAME,
FIRST_NAME
FROM
Oracle10g_table
WHERE
STATUS="A"
In both databases created with Access 2007, running this query will give you a result set in which some of the records where (STATUS="A") = false have been filtered out, but not all of them.
In databases created with older versions of access, the where clause filters properly, and the result set is correct.
STATUS is a text field
The table is a "linked" table to an Oracle10g Database
The table has 68k rows
I've tested my timeout at 60, 1000 and 0
Has anyone run into this problem?
I wonder if this is a new "feature" of access that will also affect 2010. Could this have anything to do with ODBC?
Thanks for any help,
- dave
MORE...
I just tried an alternate form of the query, using HAVING instead of WHERE, and it worked! Problem is, besides that this shouldn't change anything (yes -- more virtual tables, but shouldn't change the end result) my end-users will be using the Access 2007 visual query designer, not typing SQL directly, which is going to default any criteria they enter into a WHERE.
My hunch is that one of your ODBC drivers used by Access to connect to Oracle is treating "A" as a column name not the literal 'A'. Have you tried single quotes on the 'A'? In Oracle double quotes are used to reference column names, is there a column named "A" by any chance?
Oracle Query Example #1
Select object_name from all_objects
where "OBJECT_NAME" = 'DUAL'
Oracle Query Example #2
with example as (
Select object_name as "Fancy Column Name" from all_objects
)
select * from example
where "Fancy Column Name" = 'DUAL'
I've had a similar problem. In my case, changing the ODBC driver worked, but I could also just change the 'unique record identifier' to a column with no nulls in it. It still doesn't have to be the "right" unique record identifier.
This turned-out to be an ODBC-related issue. Our tech support service unit installs connectivity on each of our workstations -- they program it themselves, and who knows what they actually put into it -- but the net result is that when you link to an ODBC datasource with Access (of any version), our network servers show-up in the 'machine data source' tab, so we just click on the one we want and away we go. This has worked well until Access 2007.
What I did was create a "new" machine data source, which let me choose the ODBC driver myself (instead of making me use the one our tech support folks created). I picked "Microsoft ODBC for Oracle", entered the name of the server I wanted, and that all it took. Now the WHERE-clause inconsistent filtering problem is solved (I hope).
The only thing remaining is to send this back to our tech support folks, so they can clean-up their installation. Should I ask for hazard pay? :-) hehe

Cannot see table in Object Explorer, SQL Server 2005/2008

This may be a dumb question. But I just received permissions to read/write to this DB. I see the tables of the DB, except for one. I can select from it, But I cannot see it in the Object Explorer. I restarted my computer, refreshed the object explorer and everything. Is there a restriction on viewing this table?
I"m so sorry I had to check the connection of the query. I was looking at two different versions of the same DATABASE. gosh. Should I take this question down?
The query
SELECT type, type_desc FROM sys.objects WHERE name = 'my_table_name'
should tell you what type of object your table really is.
Could it be a synonym, or a view? Check under the synonyms node and the views node. Also check the schema... if you are just saying SELECT * FROM table, try with SELECT * FROM dbo.table. It may be under a different schema.
You need to use the schema name in your create table query(eg. dbo.table name). By default it is getting created under your local server and hence it is available for you when you use the select query but once you check on server ita is not available.
When all else fails, right click on Tables and click Refresh.

DESCRIBE via database link?

I tried to execute the DESCRIBE command via a database link, but this was the return message:
DESCRIBE <table>#<database>;
ERROR:
------------------------------------
ERROR: object <table> does not exist
1 rows selected
A SELECT on this table works well.
Does Oracle permitts DESCRIBE via a database link?
I'm using the Oracle SQL Developer 1.5.1.
Edit:
Is there another option to describe a table?
Thanks in advance!
You could do something with the all_tab_columns table to get some table information.
select column_name, data_type from all_tab_columns where table_name = 'TABLE_NAME';
I think DESCRIBE is a SQL*Plus feature. See here.
The easiest way to get the description of a table on a remote server would be:
CREATE OR REPLACE VIEW TMP_VIEW AS SELECT * FROM TABLE_A#SERVER
/
DESCRIBE TMP_VIEW
/
If you do a select of the metadata from all_tab_columns for that table present on the DBLink, it'll provide the description of the table.
For Ex:
select * from all_tab_Columns#dblink where table_name='ASDF' and owner='XYZ';
You seem to be using PL/SQL Developer.
DESCRIBE is not an SQL command, it's a query tool alias that gets converted into a series of queries to the system tables.
PL/SQL Developer can not describe tables from remote databases, while native SQL*Plus can.
I can't check it right now, but maybe select * from v$tables#remotedb doesn't give similar information?
In PL/SQL Developer, you can right-click on the table name from the tables folder and click on describe...which gives the same result as the describe command in native SQL plus.
Using Oracle SQL Developer I was able to use DESCRIBE to show the definition of a remote table. However, I had to use the notation
describe schema.table#database