does not allow me to use "S.NO" as column name [closed] - oracle

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed last year.
Improve this question
i am trying to create a table in oracle sql as shown below
create table Employee
(
S.NO NUMBER(2) PRIMARY KEY,
NAME VARCHAR(20),
DESIGNATION VARCHAR(20),
BRANCH VARCHAR(20)
)
it shows an error "only simple column names allowed here"
please help!!

Generally, it's a bad idea to name columns like that because it might (and will) make your code less readable.
But if you really-really-really need it, you can use quotes
create table test(
"s.no" number
);
dbfiddle

Almost every character can be used in an identifier if and only if you're using quotation at table definition. Let's see an example.
SQL> create table t1 ("S.NO" number, "!##$%^&*()" varchar2(10));
Table created.
SQL> desc t1;
Name Null? Type
----------------------------------------- -------- ----------------------------
S.NO NUMBER
!##$%^&*() VARCHAR2(10)
From now on, you have to use quotation to wrap these weird identifiers in every statement you used.
SQL> insert into t1 ("S.NO", "!##$%^&*()") values (1, 'abc');
1 row created.
SQL> select "!##$%^&*()" from t1 where "S.NO" = 1;
!##$%^&*()
----------
abc
Normally, we don't use quotation to define column or table identifier, simply because it's error prone.

Related

PL/SQL: ERROR ORA-00984 can anyone save my life? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 months ago.
Improve this question
hello guys can you help me here
CREATE TRIGGER operation
AFTER UPDATE ON COMPTE
for each row
BEGIN
IF :old.solde > :new.solde THEN
INSERT INTO HISTORY VALUES(NUMEROCOMPTE,DATESOLDE,'Retrait');
end if;
IF :old.solde < :new.solde THEN
INSERT INTO HISTORY VALUES(NUMEROCOMPTE,DATESOLDE,'Versement');
end if;
end;
/
this is what i get
3/1 PL/SQL: SQL Statement ignored
3/41 PL/SQL: ORA-00984: Column Not Allowed
6/1 PL/SQL: SQL Statement ignored
6/41 PL/SQL: ORA-00984: Column Not Allowed
Errors : check compiler log
i'm new so i dont know what to do
Do as Ken commented.
Problem is with insert statements (both of them) and values you're trying to insert into the history table. You can't insert column names as such - you have to precede their names with :new or :old pseudorecord identifier, just as you did in if.
I don't know which values (old or new) you want to store into the history table so it is just my guess, but you should know it and you'll therefore be able to fix
it.
Sample tables:
SQL> create table compte (solde number, numerocompte number, datesolde date);
Table created.
SQL> create table history (muberocompte number, datesolde date, description varchar2(20));
Table created.
Trigger:
SQL> CREATE TRIGGER operation
2 AFTER UPDATE ON COMPTE
3 for each row
4 BEGIN
5 IF :old.solde > :new.solde THEN
6 INSERT INTO HISTORY VALUES(:old.NUMEROCOMPTE, :old.DATESOLDE, 'Retrait');
7 ELSIF :old.solde < :new.solde THEN
8 INSERT INTO HISTORY VALUES(:new.NUMEROCOMPTE, :new.DATESOLDE, 'Versement');
9 END IF;
10 end;
11 /
Trigger created.
SQL>

How oracle statement works? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
create table samp
(
empno number(2),
ename varchar2(30),
sal number(7,2),
dob date
)
SQL> /
SQL> insert into samp values(1,'MASTAN',24000,'24-JUL-1987');
1 row created.
here i did not commit data so it is in redo log buffer,but when retrieving , how the below Query giving data? How internally works ?kindly suggest me
SQL> SELECT * FROM SAMP;
EMPNO ENAME SAL DOB
---------- ------------------------------ ---------- ---------
1 MASTAN 24000 24-JUL-87
It seems you did not commit or rollback so you are seeing the correct result from your select statement because it happens in single transaction. Try rollback and check the results. Another good way to understand transactions is to try opening two separate sqlplus shell and trying insert statements in one and select statements in the other shell.

Unable to insert date to table [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I'm trying to insert a date into oracle table using below
SQL> insert into temp (tst,thistime) values ('test3',TO_DATE('MM/DD/YYYY HH24:MI
:SS','01/01/2014 16:45:45') );
but its giving below error
ERROR at line 1:
ORA-01821: date format not recognized
Below is the description of table
SQL> describe temp;
Name Null? Type
----------------------------------------- -------- ---------------------------
TST VARCHAR2(10)
THISTIME DATE
Use the insert . . . select form of insert:
insert into temp (tst, thistime)
select 'test3', TO_DATE('01/01/2014 16:45:45', 'MM/DD/YYYY HH24:MI:SS')
from dual;
In addition to having the arguments backwards for to_date(), values doesn't evaluate expressions that belong in a select statement.

Trying to create a table, but it comes up with this error [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I am new to mysql and I can't really figure out as to why I keep on getting the missing right parenthesis error from this code:
/*second oracle program */
/*Franklin Tong */
set echo on
spool c:hw3.text
drop table student;
create table student(
snn char(9),
lastname char(10),
firstname char(10),
major char(10),
GPA number(3,2)
DOB date
);
insert into student (111,Smith,Johnny,IS,3.41,5/18/82);
insert into student (102,Smith,Jack,FIN,3.25,3/11/80);
select * from student;
spool off
system returns a message saying:
error at line 7
ora-00907: missing right parathesis
You are missing a ',' after 'GPA number(3,2)'.
You should put a comma ',' after 'GPA number(3,2)'.

How to create a public synynom in oracle [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
There is a schema say 'A' in which there is a package called 'B' in which this is a function (below). In this function 'TIMESTMAP' is used which while compiling in 11g is giving error. I want to create a public synonym for TIMESTAMP. Can anyone please provide me the script for the same.
FUNCTION generate_random_number
Return Number
IS
l_seq_no VARCHA2(6)
l_sys_date CHAR(10)
BEGIN
SELECT LTRIM(TO_CHAR(TIMESTAMP.NEXTVAL,'000000'), ' ')
INTO l_seq_no
from DUAL;
SELECT TO_CHAR(SYSDATE, 'H24:MI:SS')
INTO l_sys_date
from DUAL
TIMESTAMP is a reserved word so it will be interpreting your code as TIMESTAMP being a datatype (so I guess the error your getting is nextval must be declared or something). So whilst you can create a sequence called TIMESTAMP, it is extremely silly to do so. you should rename the synonym. Failing that you can create a synonym (public or private) with a different name.
eg:
SQL> create sequence timestamp start with 1;
Sequence created.
SQL>
This sequence can be used in SQL but it cannot be used in PL/SQL (which is what the OP is trying to do). The function won't compile (with a PL-00302 error). So we must create a synonym for it:
SQL> create synonym t for timestamp;
Synonym created.
then use T in your code.
your code also has numerous other typos. missing ; and mistyped varchar2. Finally char(10) for the time will mean its blank padded with 2 trailing spaces (as the length of the string will be 8 chars).

Resources