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;
Related
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
I am trying to use range partition on a table for a column of type number. However, Oracle 12c throws an error saying it is an invalid data-type. I don't understand why/what is invalid in the command.
create table partition_tester (
some_column number not null,
another_column varchar2(10),
partition by range(some_column) interval(10)
);
I am connecting to the database using SQL developer. It seems to have issue with the range function. On executing above script it throws:
Error report -
ORA-00902: invalid datatype
00902. 00000 - "invalid datatype"
*Cause:
*Action:
Any help is appreciated.
remove the comma after " another_column varchar2(10)," and specify at least one partition.
create table partition_tester (
some_column number not null,
another_column varchar2(10))
partition by range(some_column) interval(10)
(
partition p0 values less than (10)
)
Supposing i have this hierarchy :
create or replace type tperson as object(
fname varchar2(20),
lname tprenom,
adress tadr,
phone_num varchar2(10),
email varchar2(50)
)not final;
create or replace type tuser under tperson(
username varchar2(20),
password varchar2(20)
);
create table agent(
id_ag int,
infos tuser not null
);
insert into agent values(1,tuser('name',tprenom('bilel','dani','lastname3')
,tadr(3,'ain delfa','miliana','hammama',20),
'2140547854','email#gmail.com','username','password'));
How could i select, update only a single attribute from agent table ?
I've tried that sql but it didn't work :
select infos.fname, infos.lname, infos.adress, infos.phone_num, infos.email,
infos.username, infos.password from agent where id_ag=1;
But i'm getting this error :
invalid identifier 00904. 00000 - "%s: invalid identifier"
What am i missing ?
Thanks for your response.
You have a semicolon before the where that should not be there.
When it comes to accessing the user-defined column, use a table prefix and you should be fine.
Here is the syntax for your SELECT query :
select
ag.infos.fname,
ag.infos.lname,
ag.infos.adress,
ag.infos.phone_num,
ag.infos.email,
ag.infos.username,
ag.infos.password
from agent ag
where ag.id_ag = 1;
If you are looking to perform an UPDATE :
update agent ag
set ag.infos.fname = 'foo', ag.infos.lname = 'bar'
where ag.infos.id_ag = 1
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;
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: