I was trying to use select into statement to copy contents from one table to another.
select* into xyz from xyz_123 where id = 100
but while executing I'm getting an error
ORA-00905: missing keyword
00905. 00000 - "missing keyword"
*Cause:
*Action:
Error at Line: 10 Column: 15
please help me fix this error
If table xyz already exists use this:
INSERT INTO xyz
SELECT * FROM xyz_123 WHERE id = 100
If table xyz does not yet exist, then create it:
CREATE TABLE xyz
AS SELECT * FROM xyz_123 WHERE id = 100
By the way, if you spend a little time searching Stack Overflow here, as well as one other site here, then you can piece this answer together yourself.
It is not correct syntax if you are executing it alone. Use like below.
insert into xyz
select * from xyz_123 where id = 100;
Related
I am trying to create a Pivot in Oracle. I keep getting the error message
ORA-00904: "VALUEZ": invalid identifier
00904. 00000 - "%s: invalid identifier"
*Cause:
*Action: Error at Line: 18 Column: 6
Any thoughts?
SELECT * FROM
(
SELECT ACC.NBR,CTA.NAMEZ
FROM ACCS ACC
JOIN CARS CAR ON CAR.CAR_AAD_ID = ACC.ACC_AAD_ID
JOIN CTAS CTA ON CAR_CUS_ID = CTA_CUS_ID
)
PIVOT
(
MAX(VALUEZ) --comes from table CTAS (ERROR LINE)
FOR NAMEZ IN ('1','2','3') --from table CTAS
)
ORDER BY ACC.NBR;
As a side note, I would love it if it was possible to turn the ('1','2','3') into a subquery, but it looks like that is not possible from other post i have read. If it was easy it would be (select distinct namez from CTAS)
The columns referenced in your PIVOT clause must exist in the row source that is being pivoted. You select ACC.NBR,CTA.NAMEZ from the table; it looks like you need to expand that to ACC.NBR,CTA.NAMEZ,CTA.VALUEZ.
You cannot use a subquery to replace the list of pivot values. I believe the underlying reason for this is that the parser must be able to figure out the columns that the query will produce prior to executing it; so the pivot values must be hardcoded.
What you might be able to do, if it is appropriate to wrap this query up in a procedure or function, is to first execute a query to get the list of pivot values, then build the pivot query string using that information and execute it via dynamic SQL.
ora-01748: only simple column names allowed here pivot
select* from (SELECT TRUNC(I.POST_DATE) DATES FROM INVOICE I
INNER JOIN INVC_TENDER_V T ON T.INVC_SID=I.INVC_SID)
PIVOT
(COUNT(*)
FOR T.TENDER_TYPE IN(0,1) )
I'm doing a basic database assignment on ETL. I'm trying to update a column by referencing three distinct columns in two other tables.
I am getting this error report in SQL Developer:
SQL Error: ORA-00904: "DIMTIME"."DAY_TIME": invalid identifier
00904. 00000 - "%s: invalid identifier"`
I feel my syntax is bad as all listed elements exist.
Code snippet is:
update fact_stage set date_sk = (
select date_sk from time_stage
where (time_stage.year_time = dimtime.year_time)
and (time_stage.month_time = dimtime.month_time)
and (time_stage.day_time = dimtime.day_time)
);
As I understand you want to add some ID from time_stage table into date_sk column in fact_stage table. I propose to change sql query to something like
update fact_stage set date_sk = (
select ID -- identifier column in time_stage table
from time_stage dim join fact_stage fact
on (dim.year_time = fact.year_time
and dim.month_time = fact.month_time
and dim.day_time = fact.day_time)
-- or instead of ON part use "USING (year_time, month_time, day_time)"
);
hope it helps
I have something like this
if object_id('tempdb.#TempHourlyTable') is not null
drop table #TempHourlyTable
select * into #TempHourlyTable
from (
select top 10 * from customers
)
I get an error like this:
Incorrect syntax near ')'.
My first attempt with temporary tables. So what is the mistake here?
EDIT:
Drop and recreate if temporary table exists. Getting error
Msg 2714, Level 16, State 6, Line 55
There is already an object named '#TempHourlyTable' in the database.
You need to alias your derived table (subquery), like:
select * into #TEmpTable
from (
select top 10 * from customers
) as [SomeAlias]
You can also:
select top 10 *
into #temp
from customers
try this
insert into #TEmpTable
select top (10) * from customers
what are you looking to do with the temp. table?
i find using CTEs much more convenient
CTEs
Here's my setup:
CREATE TABLE CUSTOMER
(
CUSTOMER_ID NUMBER(9, 0) NOT NULL
, CUSTOMER_NAME VARCHAR2(61 BYTE)
);
CREATE INDEX CTXCAT_CUSTOMER_NAME
ON CUSTOMER (CUSTOMER_NAME) INDEXTYPE IS CTXSYS.CTXCAT;
My (simplified) query:
select /*+ INDEX(customer CTXCAT_CUSTOMER_NAME)*/*
from customer
where CATSEARCH(customer_name,'ltd Anderson',null) > 0 or customer_id > 100
Error:
Error starting at line 1 in command: select /*+ INDEX(customer
CTXCAT_CUSTOMER_NAME)/ from customer where
CATSEARCH(customer_name,'ltd Anderson',null) > 0 or customer_id > 100
Error report: SQL Error: ORA-20000: Oracle Text error: DRG-10849:
catsearch does not support functional invocation
20000. 00000 - "%s"
*Cause: The stored procedure 'raise_application_error'
was called which causes this error to be generated.
*Action: Correct the problem as described in the error message or contact
the application administrator or DBA for more information.
The HINT suggestion came from here: https://forums.oracle.com/message/2847094 and clearly doesn't work for me.
Any ideas how to resolve?
The problem is that most probably in your query Oracle uses CATSEARCH as a function invocation, rather than using your index. This is because you have the OR condition and Oracle has to check every row in your table. That's also the reason why HINT won't help. Can you show us the execution plan?
Perhaps try this:
select *
from customer
where customer_id > 100
UNION
select /*+ INDEX(customer CTXCAT_CUSTOMER_NAME)*/ *
from customer
where CATSEARCH(customer_name,'ltd Anderson',null) > 0;
(the hint shouldn't be necessary in above example)
This kind of query would work perfectly in SQL Server, but it does not work in Oracle.
select issueno, * from SOMETABLE;
The error message I'm getting is:
ORA-00936: missing expression
00936. 00000 - "missing expression"
*Cause:
*Action: Error at Line: 1 Column: 16
What is wrong?
Try this, when working with oracle db you need alias when you use column name along with *
select issueno, A.* from SOMETABLE A;
On Oracle you have to include the table name or an alias to use the *. Try this:
select issueno, SOMETABLE.*
from SOMETABLE;