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
Related
I have a user defined data type CRM_IDS:
create or replace TYPE CRM_IDS AS VARRAY(10) OF VARCHAR(32);
In my table purecov_summary, the data type of column NAV_CRM_ID is CRM_IDS:
CREATE TABLE "PE_REG"."PURECOV_SUMMARY"
(
...
"NAV_CRM_ID" "PE_REG"."CRM_IDS" ,
...
)
When I select the nav_crm_id of the first line with:
select nav_crm_id
from purecov_summary
where rownum = 1
I can get "PE_REG.CRM_IDS('10035005')".
But when I run:
select *
from purecov_summary
where nav_crm_id = PE_REG.CRM_IDS('10035005')
I get this error:
ORA-00932: inconsistent datatypes: expected - got PE_REG.CRM_IDS
00932. 00000 - "inconsistent datatypes: expected %s got %s"
*Cause:
*Action:
Error at Line: 1 Column: 37
How can I select with PE_REG.CRM_IDS type?
The trick is to use nested varray column (nav_crm_id) within table keyword as table(nav_crm_id). So consider one of the following :
select p.*
from purecov_summary p
where exists (select column_value from table(p.nav_crm_id) where column_value = '10035005')
or
select p.*
from purecov_summary p
join table(p.nav_crm_id) c
on c.column_value = '10035005';
Demo
Getting error while running the below query
select xt.IssueDate, xt.SequenceNumber from xml_tab x ,
XMLTABLE('/EmployeeInfo'
PASSING x.xml_data COLUMNS
"IssueDate" varchar2(10) path '#IssueDate',
"SequenceNumber" integer path '#SequenceNumber'
) xt;
error I am getting
ORA-00904: "XT"."SEQUENCENUMBER": invalid identifier
00904. 00000 - "%s: invalid identifier"
*Cause:
*Action: Error at Line: 114 Column: 22
You are mixing quoted and non-quoted identifiers. The columns clause in the XMLTable call is defining SQL-type names, not XML-type names.
You can either quote both:
select xt."IssueDate", xt."SequenceNumber" from xml_tab x ,
XMLTABLE('/EmployeeInfo'
PASSING x.xml_data COLUMNS
"IssueDate" varchar2(10) path '#IssueDate',
"SequenceNumber" integer path '#SequenceNumber'
) xt;
or preferably quote neither:
select xt.IssueDate, xt.SequenceNumber from xml_tab x ,
XMLTABLE('/EmployeeInfo'
PASSING x.xml_data COLUMNS
IssueDate varchar2(10) path '#IssueDate',
SequenceNumber integer path '#SequenceNumber'
) xt;
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;
I want to get the value SESSIONID from this table:
CREATE TABLE SESSIONSLOG(
SESSIONID VARCHAR2(30 ) NOT NULL,
USERNAME VARCHAR2(30 ),
IPADDRESS VARCHAR2(30 ),
LOGINTIME TIMESTAMP(6),
LOGOUTTIME TIMESTAMP(6)
)
/
I tried this SQL query:
SELECT SESSIONID FROM ACTIVESESSIONSLOG
But I get this error message:
ORA-00904: "SESSIONID": invalid identifier
00904. 00000 - "%s: invalid identifier"
*Cause:
*Action:
Error at Line: 1 Column: 7
How I can fix this?
You're querying the wrong table:
CREATE TABLE SESSIONSLOG
...
SELECT SESSIONID FROM ACTIVESESSIONSLOG
ACTIVESESSIONSLOG is not the same as SESSIONSLOG.
You are querying wrong table ... table should be SESSIONSLOG
SELECT SESSIONID FROM SESSIONSLOG
#user1285928 you are not supposed to use " ACTIVESESSIONSLOG " .
Instead Use SESSIONSLOG. Also use the delimiter symbol ;
SELECT SESSIONID FROM SESSIONSLOG;
I have a column name in one of my tables called: 3RD_DIAG_CODE - VARCHAR2 (10 Byte)
When I try to run a query, it gives me the following error highlighting 3RD_DIAG_CODE.
ORA-00923: FROM keyword not found where expected.
How can I bring this field in without it throwing an error every time I bring this field in?
If you are using column names that start with a number then you need to use double quotes. For example:
create table foo (
"3RD_DIAG_CODE" varchar2(10 byte) --make sure you use uppercase for variable name
);
insert into foo values ('abc');
insert into foo values ('def');
insert into foo values ('ghi');
insert into foo values ('jkl');
insert into foo values ('mno');
commit;
select * from foo;
3RD_DIAG_C
----------
abc
def
ghi
jkl
mno
select 3RD_DIAG_CODE from foo;
RD_DIAG_CODE
------------
3
3
3
3
3
select "3RD_DIAG_CODE" from foo;
3RD_DIAG_C
----------
abc
def
ghi
jkl
mno
Edit: As for the error message itself, you are probably (as BQ wrote) missing a comma from the select clause.
Check your specification, but in SQL Server we would have to enclose that column name in square brackets: [3RD_DIAG_CODE]
You probably have two columns listed without a comma between them.
create table t (id number primary key, 3d varchar2(30))
Error at Command Line:1 Column:39
Error report:
SQL Error: ORA-00904: : invalid identifier
00904. 00000 - "%s: invalid identifier"
create table t (id number primary key, "3d" varchar2(30));
table T created.
desc t
Name Null Type
---- -------- ------------
ID NOT NULL NUMBER
3d VARCHAR2(30)
> select id, 3d from t --[as #gsiem mentions: THIS IS BAD]
ID 3D
---------------------- --------
> select id, "3d" from t
ID 3d
---------------------- ------------------------------
> select id, [3d] from t
Error starting at line 7 in command:
select id, [3d] from t
Error at Command Line:7 Column:11
Error report:
SQL Error: ORA-00936: missing expression
00936. 00000 - "missing expression"
*Cause:
*Action:
> select id 3d from t
Error starting at line 8 in command:
select id 3d from t
Error at Command Line:8 Column:10
Error report:
SQL Error: ORA-00923: FROM keyword not found where expected
00923. 00000 - "FROM keyword not found where expected"
*Cause:
*Action: