ORA-00904: Invalid identifier when using dbms_random.value - sql

This article here suggests using dbms_random.value to select random values from a table.
My query
select value1, value2 from
(select value1, value2 from my.table order by dbms_random.value)
where rownum <100;
Gives me
Error at Command Line:2 Column://column after the 'by').
Error report:
SQL Error: ORA-00904: : invalid identifier
00904. 00000 - "%s: invalid identifier"
Any suggestions?

Insufficient user priviledges. Don't have access to the dbms_random package.

You need to GRANT EXECUTE to your schema. Login as your SYS user and run the following, replacing 'your-schema-name' with the Oracle user who you wish to allow run DBMS_RANDOM.
GRANT EXECUTE ON DBMS_RANDOM TO your-schema-name;

Related

Implement cursor when select value changes name

I cannot seem to successfully implement the cursor what I change the statement name picked from select,
For example:
SELECT userid as user_no, CURSOR(SELECT user_no
FROM my_table.punter P
WHERE P.user_no = Q.user_no)
FROM another_table.maria_punter Q;
I get the following error:
ORA-00904: "Q"."USER_NO": invalid identifier
00904. 00000 - "%s: invalid identifier"
*Cause:
*Action:
Error at Line: 4 Column: 22
You cannot use the column alias given in the same SELECT clause; instead, use the unaliased column name from the table:
SELECT userid as user_no,
CURSOR(
SELECT user_no
FROM my_table.punter P
WHERE P.user_no = Q.userid
)
FROM another_table.maria_punter Q;
fiddle

Why is the table not able to be selected/viewed in sql plus? [FIXED]

I tried to create a trigger.
This is the code I used
create or replace trigger prod_se15
after insert on product_se15
for each row
begin
insert into product1_se15#link4bomb2 values(:new.pro_id,:new.pro_name,:new.pro_desc);
insert into product2_se15#link4bomb3 values(:new.pro_id,:new.pro_cost,:new.pro_profit);
end;
/
The error
2/3 PL/SQL: ORA-00942: table or view does not exist
2/3 PL/SQL: SQL Statement ignored
3/3 PL/SQL: ORA-00942: table or view does not exist
3/3 PL/SQL: SQL Statement ignored
Note:
The table is displayed when desc product_se15 or select * from product_se15 command is executed.
Tried to grant the privileges method via another user but it did not work.
Fixed
Detailed Error
: LINE/COL ERROR
-------- -----------------------------------------------------------------
0/0 ORA-04052: error occurred when looking up remote object
SCOTT.PRODUCT1_SE15#LINK4BOMB2
ORA-00604: error occurred at recursive SQL level 1
ORA-01017: invalid username/password; logon denied
ORA-02063: preceding line from LINK4BOMB2
#The password string mismatch

Sql error "invalid identifier"

Anyone idea why am I getting error ?
create or replace view PROD as
select
mytable.name as description
from table_name mytable
join another_table another on another.id in (
select mytable1.id
from table_name mytable1
start with mytable1.id = mytable.id
connect by prior mytable1.id = mytable1.parent_id);
Error at Command Line:8 Column:41
Error report:
SQL Error: ORA-00904: "MYTABLE"."ID": invalid identifier
00904. 00000 - "%s: invalid identifier"
*Cause:
*Action:
This actually works for my local database installation. However, not on any other. Running on Oracle database.
Thank you
Version problem:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 -
Production
Oracle Database 12c Standard Edition Release 12.1.0.2.0 - 64bit
Production
Where 1. is the one where this syntax does not work.

ORA-00904 while converting UTC date to Oracle date

I wrote the following query in Oracle, and it is working fine in one schema but giving an ORA-00904 error for the utc_to_oracle converter function in another schema.
SELECT MIN(to_char(utc_to_oracle(start_t),'DD-MON-YYYY hh24:mi:ss')),
MAX(to_char(utc_to_oracle(end_t),'DD-MON-YYYY hh24:mi:ss'))
FROM ts.udata
WHERE entity_type='wxyz'
Error:
ORA-00904: "UTC_TO_ORACLE": invalid identifier
00904. 00000 - "%s: invalid identifier"
*Cause:
*Action: Error at Line: 2 Column: 13
Why is it working on one schema but not the other?
ORA-00904 occurs when you reference an invalid object.
You need to provide grants for the user defined object UTC_TO_ORACLE to the target user to have this executed.
GRANT SELECT ON UTC_TO_ORACLE TO XXX;

ORA-00904 when inserting/querying data from tables

I'm getting the flowing error:
Error starting at line 1 in command:
INSERT INTO driver (registration, make, model, gvw, year, body) VALUES('4585 AW','ALBION','RIEVER',20321,1963, ' ');
Error at Command Line:1 Column:53
Error report:
SQL Error: ORA-00904: "BODY": invalid identifier
00904. 00000 - "%s: invalid identifier"
When I do the following
INSERT INTO driver
(registration, make, model, gvw, year)
VALUES
('4585 AW','ALBION','RIEVER',20321,1963, ' ');
So I temporally deleted the body data and then give the error
Error starting at line 1 in command:
INSERT INTO driver (registration, make, model, gvw, year) VALUES('4585 AW','ALBION','RIEVER',20321,1963)
Error at Command Line:1 Column:53
Error report:
SQL Error: ORA-00904: "YEAR": invalid identifier
00904. 00000 - "%s: invalid identifier"
I have columns both called year and body, yet I'm getting errors. How can I fix this?
Seems like you specified the column names under quotes in your DDL.
Oracle considers identifiers under quotes as a case sensitive, so creating a table with a column name as "body" or "year" will not resolve body or year in your query, because when you omit the quotes, it considers the upper case variant.
So when you have this:
create table driver_case (registration varchar2(60),
make varchar2(60),
model varchar2(60),
gvw number,
"year" number,
"body" varchar2(60));
and then try to do
select year, body from driver_case
then Oracle tries to find column "YEAR", "BODY" (remember, without an identifier without quotes gets converted to upper case) which is not the same as "year", "body" in your table.
Your solutions?
Don't mention column names under quotes in the DDL
If you disregard the above point, then you must mention the column names under quotes in all your DML statements.
I demonstrate the above point in this SQL Fiddle
Try this:
INSERT
WHEN city='palanpur' THEN INTO Ashish
When city='Aburoad' THEN INTO abhi
SELECT no, name
FROM arpit;