Ora-00905 missing keyword error - oracle

Im getting below error while executing below line,
SELECT * INTO employee_Backup FROM employee
Error:
Ora-00905 missing keyword error

Your query should be
INSERT INTO employee_backup
SELECT *
FROM employee
Discussed here
And the syntax is
INSERT INTO table_name
SELECT *
FROM table_name

This is sql-server syntax you're trying to use.
The Oracle equivalent would be:
INSERT INTO employee_backup
(SELECT * FROM employee)

Related

Oracle - ORA-00907: missing right parenthesis in query generated by Odata query generator

this is the query generated by an Odata Sql query generator and I am on Oracle 12c
SELECT ID
FROM MY_TABLE
WHERE (
NAME LIKE 'abc' = true
)
;
and the error it generates is
ORA-00907: missing right parenthesis
00907. 00000 - "missing right parenthesis"
*Cause:
*Action:
Error at Line: 4 Column: 14
Any ideas on how to fix the query ?
Thanks in advance
I know nothing about "Odata Sql query generator", but - if you want to fix this query, then it would be
select id from my_table where name like 'abc'
On the other hand, that's same as
select id from my_table where name = 'abc'
so perhaps you actually meant to use wildcards:
select id from my_table where name like '%abc%'

FRM-40735: post-insert trigger raised unhandled exception ora-01722

I create POST-INSERT Trigger on Block when I am getting this error on Oracle Forms 11gR2
"FRM-40735: post-insert trigger raised unhandled exception ora-01722"
POST-INSERT Trigger Code:
Insert into we_group (GROUP_ID, GROUP_SIZE, NRSP_STATUS, GROUP_RECEIVED)
Select DISTINCT GROUP_ID, ('Select COUNT(*) from we_group_hof_k'),
nrsp_status, sysdate
from we_group_hof_k;
commit_form;
How to solve this problem?
Remove ' to prevent number to char convertion
Select DISTINCT GROUP_ID, (select COUNT(*) from we_group_hof_k),
nrsp_status, sysdate
from we_group_hof_k;
Consider using analytic version of the COUNT function (if Forms version you use supports it; 10g doesn't, I can't tell about 11g):
INSERT INTO we_group (GROUP_ID,
group_size,
nrsp_status,
group_received)
SELECT DISTINCT GROUP_ID,
COUNT (*) OVER (ORDER BY NULL),
nrsp_status,
SYSDATE
FROM we_group_hof_k;
It evidently seems ORA-01722 raises due to an attempt to insert a quoted string
( 'Select COUNT(*) from we_group_hof_k' ) into a numeric column( GROUP_SIZE ).
So, first of all you need to get rid of those quotes, and even whole sub-select, since you already try to select from the same table in the main query, and just consider to include a group by clause instead:
Insert Into we_group(group_id, group_size, nrsp_status, group_received)
Select group_id,Count(1),nrsp_status, sysdate
From we_group_hof_k
Group By group_id,nrsp_status;
Lastly do not use a commit or commit_form inside a POST-INSERT trigger, that usage is considered as illegal restricted there.

Declaring and using variables in PL-SQL

I am new to PL-SQL. I do not understand why I am getting the error "PLS-00428: an INTO clause is expected in this SELECT statement"
What I'm trying to accomplish is to create a variable c_limit and load it's value. I then want to use that variable later to filter data.
Basically I am playing around in the demo db to see what I can/can't do with PL-SQL.
The code worked up to the point that I added "select * from demo_orders where CUSTOMER_ID = custID;"
declare
c_limit NUMBER(9,2);
custID INT;
BEGIN
custID := 6;
-- Save the credit limit
select credit_limit INTO c_limit
from demo_customers cust
where customer_id = custID;
select * from demo_orders where CUSTOMER_ID = custID;
dbms_output.Put_line(c_limit);
END;
If you are using a SQL SELECT statement within an anonymous block (in PL/SQL - between the BEGIN and the END keywords) you must select INTO something so that PL/SQL can utilize a variable to hold your result from the query. It is important to note here that if you are selecting multiple columns, (which you are by "SELECT *"), you must specify multiple variables or a record to insert the results of your query into.
for example:
SELECT 1
INTO v_dummy
FROM dual;
SELECT 1, 2
INTO v_dummy, v_dummy2
FROM dual;
It is also worth pointing out that if your SELECT * FROM.... will return multiple rows, PL/SQL will throw an error. You should only expect to retrieve 1 row of data from a SELECT INTO.
Looks like the error is from the second select query.
select * from demo_orders where CUSTOMER_ID = custID;
PL-SQL won't allow a standalone sql select query for info.
http://pls-00428.ora-code.com/
You need to do some operation with the second select query

SELECT a table from oracle data dictionary

I am new to SQL and recently installed Oracle 11g. I read the post here on selecting all tables from user_tables. I'm trying to select a specific table and following some of the suggestions in the post does not appear to work.
The following executes fine and returns all tables available to me including a table named faculty_t:
select * from user_tables;
select * from dba_tables;
select * from all_tables;
desc faculty_t;
But I get error when I do the following:
select * from user_tables where table_name = FACULTY_T;
The first set of statements confirm that I do have a table named faculty_t. However, trying to select this table from user_tables, all_tables, or dba_tables does not appear to work for me right now. The error message reads something like:
ORA-00904: "FACULTY_T": invalid identifier
00904. 00000 - "%s: invalid identifier"
*Cause:
*Action:
Error at Line: 208 Column: 8
Any thoughts? Thanks!
String literals in SQL are wrapped in '. So:
select * from user_tables where table_name = 'FACULTY_T';
When you did a desc faculty_t, the SQL engine knew that a table name was expected at that spot (the syntax expects a table name there). But in your select query, sql is just looking for the value of a column that happens to have a string data type, so you need to use the ' for a string literal.

Oracle: Selecting * and aggregate column

Is it possible to select fields using the method below?
SELECT *, count(FIELD) FROM TABLE GROUP BY TABLE
I get the following error
ORA-00923: FROM keyword not found where expected
00923. 00000 - "FROM keyword not found where expected"
*Cause:
*Action:
Error at Line: 1 Column: 9
Is it a syntax error or do you have to explicitly define each column rather than using *?
You can't use * and other columns. If you use an alias, then you can:
SELECT t.*
, count(FIELD)
FROM TABLE t
Also, your GROUP BY TABLE is wrong. You can't group by the table name, you must specify some columns, like this:
SELECT t.customer
, count(FIELD)
FROM TABLE t
GROUP BY t.customer
The columns that are selected in the field should be
an expression used as one of the group by criteria , or
an aggregate function , or
a literal value
For this, you need to indicate the fields you needed and should fit in the following criteria mentioned above.
SELECT FIELD1,FIELD2, COUNT(*) FROM TABLE1 GROUP BY FIELD1, FIELD2
If you insist to use the logic of your query, the use of subquery should be helpful.
For example,
SELECT * FROM TABLE1 T1 INNER JOIN (SELECT FIELD1, COUNT(FIELD1) AS [CountOfFIELD1] FROM TABLE1 T2 GROUP BY FIELD1)T3 ON T1.FIELD1=T3.FIELD1
Instead of * you need to give the column names:
SELECT a, b, COUNT(FIELD)
FROM TABLE
GROUP BY a, b;

Resources