Oracle error ORA-00942, rails 3 environment - sql

Hoping someone will have some insight into this issue. There are a lot of posts regarding this error, and I have read all of them.
Running a Rails 3 app on an Oracle 11 db. Rails attempts to create a new object, and it blows up (500) and I get back ORA 00942, table or view does not exist. Table does exist. Sequence exists and I can both write to the table and pull sequence numbers using SQL Developer and the same credentials that are used to run the rails app. Permissions look fine. I have looked at the rails model associations, and tracked down all of the tables and sequences of those objects as well.
One of the columns in the table is a CLOB column, and it seems like there can be issues with that datatype. But those seem to come from Java environments.
I have schema owner credentials, is there a log I could check to see the exact sql statement that is causing the error? Any sort of lower level logging I could turn on to get more insight into what is going on?

This ended up being a missing grant on a sequence. Very frustrating that Oracle reports this as 00942.
If you get this problem, and the table is present, look carefully at the grants that have been made to both the table and the sequence. You can do this with the following syntax in SQL Developer:
select * from DBA_TAB_PRIVS where table_name = name_of_thing_you_want
Yes, sequences also fall under the table_name heading.
To create a grant:
grant select ON the_name_of_the_object TO name_of_the_user
I hope this helps someone.

Related

Running a basic select on SQL Sever asks for column name that doesn't exist, why?

We had another developer come through and complete some work for us. Unfortunately he didn’t work well within our team and management let him go.
Because of this now I’m stuck debugging his code and undoing work that was done. He did not document his code (one of the reasons he was let go), rarely notating anything, therefore I have no idea where to begin looking.
When I run a basic SELECT on two specific tables in our DB:
SELECT * FROM table_name
Using SQL Server Management Studio I get this...
Msg 207, Level 16, State 1, Line 1
Invalid column name 'eventTime'.
There was an eventTime column but wasn’t necessary and wasn't being used in any PHP file, however it seems somehow directly tied to the table now and I have no idea where to look to find it. The error message provided is pointing to my SELECT statement, but there is nothing wrong with it, nor does it even reference the eventTime column.
I’ve looked and there don’t seem to be any triggers or stored procedures referencing this table. Is there another way I can try to track this down?
This sounds like a hard'ish problem. Here are some ideas.
My first thought is that table_name is a view, and somehow the view has gotten out-of-sync with the underlying table definitions. I have seen problems with types in some circumstances. I imagine the same could happen with column names.
The next thought is that table_name has computed columns. In this case, the computed columns could be using a function and the function call could be generating the error. I cannot think of any other way to run code with a simple select.
I don't think the problem would be a foreign key constraint unless. So, a third option is that a foreign key constraint is referencing a table in the same database but a different schema. The different schema could have permissions that make the table inaccessible.
For any of these, scripting out the definition in SSMS will help you fix the problem.

Binding error in MSSQL Views 'DWView.dbo.whatever'

I was given a database by a client. I can't access any of the data in the Views in this database because I get this error:
Invalid object name 'DWView.dbo.Person_C'.
I have no user/role/anything called DWView. The view exists, but nothing can access it. This happens in all of the views.
One thing I'm not clear on -- what is DWView.dbo? I know dbo is the schema/owner, but what about the DWView part? I've never encountered this in 15+ years of working with MSSQL databases.
Any attempt to access the views fails with that error, including sp_refreshview.
Is there anything I can do to remove this DWView thing? Thanks.
The error means the object doesn't exist. Like you mentioned, the schema comes before the view in syntax; so when you ask ...
One thing I'm not clear on -- what is DWView.dbo
... it means database.schema. So your query is looking for the database DWView, the schema dbo, and the object name Person_C.
As a note, if you're already on the database (USE Database GO), you don't have to use the database in your query; you can simply use SchemaName.ObjectName.
Try executing this ..
USE Your_Database_Name
GO
SELECT * FROM dbo.Person_C
GO
It should be [database].[schema].[objectname].

Why does this query throw ORA-00942 on 10g while it works on 11g?

I execute this query without problem on my 11g installation :
SELECT
PRODUCT_INFOS_idm.FIELD_VALUE "mother_id",
PRODUCT_INFOS_ep.FIELD_VALUE "product_thickness",
COIL_INFOS.TIME_STAMP,
COIL_INFOS.IN_THICKNESS,
COIL_INFOS.MEASURED_LENGTH,
COIL_INFOS.MEASURED_WIDTH,
COIL_INFOS.PARAM_SET_TOP_SIDE,
COIL_INFOS.PARAM_SET_BOTTOM_SIDE
FROM
COIL_INFOS
INNER JOIN
PRODUCT_INFOS PRODUCT_INFOS_idm
on PRODUCT_INFOS_idm.COIL_ID_SYSTEM=COIL_INFOS.COIL_ID_SYSTEM
and PRODUCT_INFOS_idm.TIME_STAMP=COIL_INFOS.TIME_STAMP
and PRODUCT_INFOS_idm.FIELD_NAME='ID bobina'
INNER JOIN
PRODUCT_INFOS PRODUCT_INFOS_ep
on PRODUCT_INFOS_ep.COIL_ID_SYSTEM=COIL_INFOS.COIL_ID_SYSTEM
and PRODUCT_INFOS_ep.TIME_STAMP=COIL_INFOS.TIME_STAMP
and PRODUCT_INFOS_ep.FIELD_NAME='Anchura'
WHERE
(COIL_INFOS.COIL_ID_SYSTEM LIKE '14051800' OR COIL_INFOS.COIL_ID LIKE '14051800')
But when my customer (who may have a 10g installation) executes it, he gets
ORA-00942: table or view does not exist
Other queries show that he has the same tables and columns. The following queries executes without problem :
select count(*) from COIL_INFOS
select count(*) from PRODUCT_INFOS
What can be the problem ? Is there a syntax error somewhere ? I suspect there is a problem with the Oracle version (I already had to remove the "as" I usually use for column aliasing). Does Oracle 10g support table aliasing ?
There are several reasons why we might get ORA-00942.
The most obvious one is, the table does not exist in the database. That's easy enough to check in the data dictionary views, such as DBA_TABLES.
The table exists but we are referencing it wrongly. The common scenario is when the table was created with a mixed-case name in double quotes; when this happens we always have to refer to the table name with a mixed-case name in double quotes, because EMPLOYEES != "Employees".
The table is owned by a different user and our code doesn't include the schema name when we call it (and we don't have a synonym either).
The table is owned by a different user and that user hasn't granted us privileges on it.
The table is owned by a different user and that user has granted us privileges on it through a role but we want to reference it in a stored procedure or a view. In this situation we must have the privileges granted to our user directly, because the Oracle Security model works that way.
Given that you say "Other queries show that he has the same tables and columns" we can rule out the first option, and probably the second one. So it's most likely a problem with a missing synonym or missing permissions.
As was hinted by Bob in comments, the problem was due to a bad version of Oracle 10g.
There are a few servers on which the same schema and the same query are used, only the one with version 10.2.0.1.0 had the problem. Oracle experts think the bug doesn't exist on 10.2.0.4 but I have no access to Oracle bug database.
As patching the server was out of question for our customer, we finally got around the bug by creating a view for this query.
TLDR : when Oracle says a version is buggy and should not be used, it should not be used.
There's no problem with Oracle version. You are using standard queries that will work in even older version of Oracle than 10.
I suspect one or more of the following will be true:
you may have synonyms in your 11g database but not in 10g at the client.
The client is using different credentials to test select count(*) from table than that used to run the query.

How to deal with a Firebird table that's apparently both there and not there

I've just had something very strange happen to me with a Firebird database.
I was trying to create a table, and the CREATE TABLE failed for some reason. But now it's stuck in a very strange state:
If I try to CREATE TABLE again with the same table name, it gives an error: the table already exists. But if I try to DROP TABLE that table, it gives an error: the table does not exist. Trying to SELECT * FROM that table gives the "table does not exist" error, and the name does not show up in the metadata query:
SELECT RDB$RELATION_NAME
FROM RDB$RELATIONS
WHERE RDB$SYSTEM_FLAG=0
So for some reason, the table really seems to not be there, but I can't create it because something somewhere indicates that it does exist.
Does anyone have any idea how to fix this? I've already tried closing all connections to that database, which has helped with inconsistency issues in the past, but this time it doesn't help.
You didn't give details about what was the error when you tried to create the table, so I cannot comment it. But RDB$RELATIONS is not the only system table affected when you create a table. Maybe you are now in an inconsistent situation where some information about that table exists in some system tables and doesn't exists in others.
Another option is corrupted indexes in the system tables, so the record is not there but the index think it still exists.
Try to do a backup/restore and see if it helps. It it doesnt work, try to search for records related to that "non created" table in the other system tables (RDB$RELATION_FIELDS, etc) and if you find any, try to delete them.
As a last option, you may create a new clean database with correct metadata and pump your data to it using IBDataPump.

ORA-01775: looping chain of synonyms with no synonyms

I have been using a script run from a batch file to create and edit a table. As far as I cold tell it was working and I worked on a different issue.
However, at some point something has gone wrong.
In PLSQL Developer I tried to select from the table and I got the error:
ORA-01775: looping chain of synonyms
If I try to drop the table I get the error:
ORA-00942: table or view does not exist
I have never, intentionally, created and synonyms so I checked with this:
SELECT owner,synonym_name,table_owner,table_name from dba_synonyms where synonym_name='broken_table';
There are no results returned. The other similar questions on here do not seem to have the same situation or the actual solution, can anyone give any advice on how to proceed here?
(as you can guess sql is not my strong suit).
I got the ORA-01775 error from trying to access a table via a synonym where the table did not exist. The table had been dropped and had not yet been recreated. The synonym was still there. There was no looping synonym.