Viewing SQL Server data to Oracle - sql

Hello I have created a Database Link from Oracle to SQL Server 2008 using Oracle Gateway.
DB LINK:
create public database link mssql
connect to "user" identified by "password"
using 'gateway-SID';
When I use a simple query as SELECT * FROM TABLE#MSSQL the results are clearly ok.
The problem occurs when I select a distinct column from a table e.g.
SELECT COLUMN_NAME FROM TABLE#mssql
I get a query error from my SQL Developer saying:
ORA-00904: "CUSTOMERID": invalid identifier
00904. 00000 - "%s: invalid identifier"
Cause:
Action:
Error at Line: 1 Column: 8
Can anyone help me on this please?

(Disclaimer: I'm no SQL Server expert, but I'll give it a go)
SQL Server is case sensitive - you have to quote your column names, so instead of
SELECT COLUMN_NAME FROM TABLE#mssql
you need
SELECT "COLUMN_NAME" FROM TABLE#mssql
or even
SELECT "COLUMN_NAME" FROM "TABLE"#mssql
See Oracle forums on SQL Server, Oracle Gateway and ORA-00904

Related

Case sensitivity issue on SQL server

I have a Dblink in place between my Oracle database and Microsoft SQL Server, fetching data from SQL server while on Oracle. Connectivity is fine but I am getting invalid column names whenever I try to include any column name in my select query.
On Oracle with Dblink:
select COLUMN1 from table1#dblink
Fails with:
ORA-00904: COLUMN1: invalid identifier
On Oracle with Dblink, this works fine.
select "COLUMN1" from table1#dblink
On SQL server this works fine:
select column1,COLUMN1 from table1
Seems case sensitivity is not enforced when on SQLserver, however, while trying from oracle it is enforced, any idea how I can bypass this,
The collation on my SQL server is SQL_Latin1_General_CP1_CI_AS.

Invalid identifier SQL error displaying upon executing a update query for a tables in different schema in Oracle database

Here I am using Oracle SQL developer and I need to update a table in an another schema. Here is the update query which I have written.
update dcs.lte_pin_register set pin = ''
where dcs.lte_pin_register.subscriber_seqno = dcs.subscriber.subscriber_seqno
and dcs.subscriber.sub_number = '?';
In the above query,
dcs -> Refer to another schema in the database
lte_pin_register and subscriber are two tables in the dcs schema
subscriber_seqno and sub_number are the columns in the respective tables.
However when I am going to execute the above query using a valid sub_number I am getting an error mentioning follows.
Error report -
SQL Error: ORA-00904: "DCS"."SUBSCRIBER"."SUB_NUMBER": invalid identifier
00904. 00000 - "%s: invalid identifier"
*Cause:
*Action:
I can call a column name in the same schema for the update query using (tableName.columnName). But how can I modify the above query to refer to columns in tables in different schemas?
You have to use a co-related subquery to achieve this -
UPDATE dcs.lte_pin_register
SET pin = ''
WHERE EXISTS (SELECT 1
FROM dcs.subscriber
WHERE dcs.lte_pin_register.subscriber_seqno = dcs.subscriber.subscriber_seqno
AND dcs.subscriber.sub_number = '?');

Oracle SQL Developer - Create View with parameters

I'm new to Oracle SQL and I'm currently working on an Oracle SQL view in Oracle SQL Developer.
I need two parameters in my View
fruitType (string)
fruitNumber (int)
I tried the following (simplified) statement in Oracle SQL Developer:
CREATE VIEW FRUITSRESULT (fruitType, fruitNumber) AS
SELECT
fruit_col1 as FruitType,
fruit_col2 as FruitNumber
fruit_col3 as FruitInfo
FROM
FRUITGARDEN
WHERE
fruit_col1 = fruitType
fruit_col2 = fruitNumber
;
Unfortunately this does not work, I always get the following error:
Error starting at line : 1 in command -
...
ORA-00904: "FRUITNUMBER": invalid identifier
00904. 00000 - "%s: invalid identifier"
*Cause:
*Action:
Do you know how to solve this error?
Is it actually possible to create a parameterized View in Oracle SQL?
Is it actually possible to create a parameterized View in Oracle SQL?
No, that is not possible.
What you are thinking of as parameters are the column aliases for the output:
CREATE VIEW FRUITSRESULT (fruitType, fruitNumber, FruitInfo) AS
SELECT fruit_col1,
fruit_col2,
fruit_col3
FROM FRUITGARDEN;
Will output the values fruit_col1, fruit_col2 and fruit_col3 with the columns aliased to fruitType, fruitNumber, and FruitInfo (respectively). They are not, as you assumed, input parameters.

Selecting variable_of_tablename.* from tablename gives 00904. 00000 - "%s: invalid identifier"

SELECT sur.* FROM table_name
Whenever I run this code in SQLDeveloper it it gives me the error
ORA-00904: "SUR": invalid identifier
00000 - "%s: invalid identifier"
I'm not sure how to fix this and haven't been able to find anything online. The reason I have to use this format is because it follows a format already being implemented by previous developers and I have to adhere to that standard.
Has anyone had any experience with this?
Try this
SELECT sur.* FROM table_name sur;
You have used a sur alias for referring all the columns of the table table_name but before you can use that you need to give table table_name an alias like sur
However the below query will work fine as you are using the actual table name instead of a different alias name.
select table_name.* from table_name;
Here, you ask to list columns from table "SUR" but since no such table exists in "from" clause, Oracle raises this error.
There are 2 options here:
Give an alias (a second name) to any of the table in from clause
For eg:
select sur.* from tablename1 sur, tablename2 foo where sur.col1=foo.col1
Use table name itself rather than using column alias "SUR"
For eg:
select tablename1.* from tablename1, tablename2 where tablename1.col1=tablename2.col1
Refer: http://www.techonthenet.com/oracle/alias.php

Oracle SQL Developer - Unable to run queries using varchar field as identifier

I'm new to using Oracle SQL Developer and to using an Oracle DB (have mainly used MySQL before)
I'm trying to do something like:
select * from content_definition where content_id = "hhhh233";
Where content_id is:
VARCHAR2(1000 BYTE)
But am getting:
ORA-00904: "hhhh233": invalid identifier
00904. 00000 - "%s: invalid identifier"
*Cause:
*Action:
Error at Line: 1 Column: 52
I'm not really understanding why this isn't working as I used to do queries like this all the time with MySQL. I have been searching on this but nothing seems to be for my specific use case. I would appreciate if anyone can set me in the right direction on this. Thanks
You need to use single quotes for character data; double quotes signify identifiers and aliases:
select * from content_definition where content_id = 'hhhh233';
String delimiter in Oracle is a single quote ('), like this:
select * from content_definition where content_id = 'hhhh233';
Double quotes are only used for identifiers (e.g. column names and tables).