I'm trying to delete some information from a table that has a date < 16/16/2019 in C#. The query gave me an exception so I'm trying to do it directly in MS Access and even here it gave me error.
SELECT *
FROM TableName
WHERE (((TableName.Date)<= #16/06/2019#));
If I use the above, the query gives me the result that I expect which is all information which is stored before a specific date.
But if I use the DELETE statement:
DELETE
FROM TableName
WHERE (((TableName.Date)<= #16/06/2019#));
It gives me the error:
The search key was not found in any record
Why?
Given the information in the comments, I would suggest the following:
delete from TableName t where t.data <= #2019-06-16#
Related
my query just runs and doesnt execute, what is wrong. work on oracle sql developer, company server
CREATE TABLE voice2020 AS
SELECT
to_char(SDATE , 'YYYYMM') as month,
MSISDN,
SUM(CH_MONEY_SUBS_DED)/100 AS AIRTIME_VOICE,
SUM(CALLDURATION/60) AS MIN_USAGE,
sum(DUR_ONNET_OOB/60) as DUR_ONNET_OOB,
sum(DUR_ONNET_IB/60) as DUR_ONNET_IB,
sum(DUR_ONNET_FREE/60) as DUR_ONNET_FREE,
sum(DUR_OFFNET_OOB/60) as DUR_OFFNET_OOB,
sum(DUR_OFFNET_IB/60) as DUR_OFFNET_IB,
sum(DUR_OFFNET_FREE/60) as DUR_OFFNET_FREE,
SUM(case when sdate < to_date('20190301','YYYYMMDD')
then CH_MONEY_PAID_DED-nvl(CH_MONEY_SUBS_DED,0)-REV_VOICE_INT-REV_VOICE_ROAM_OUTGOING-REV_VOICE_ROAM_Incoming
else (CH_MONEY_OOB-REV_VOICE_INT-REV_VOICE_ROAM_OUTGOING-REV_VOICE_ROAM_Incoming) end)/100 AS VOICE_OOB_SPEND
FROM CCN.CCN_VOICE_MSISDN_MM#xdr1
where MSISDN IN ( SELECT MSISDN FROM saayma_a.BASE30112020) --change date
GROUP BY
MSISDN,
to_char(SDATE , 'YYYYMM')
;
This is a performance issue. Clearly the query driving your CREATE TABLE statement is taking too long to return a result set.
You are querying from a table in a remote database (CCN.CCN_VOICE_MSISDN_MM#xdr1) and then filtering against a local table (saayma_a.BASE30112020) . This means you are going to copy all of that remote table across the network, then discard the records which don't match the WHERE clause.
You know your data (or at least you should know it): does that sound efficient? If you're actually discarding most of the records you should try to filter CCN_VOICE_MSIDN_MM in the remote database.
If you need more advice you need to provide more information. Please read this post about asking Oracle tuning questions on this site, then edit your question to include some details.
You are executing CTAS (CREATE TABLE AS SELECT) and the purpose of this query is to create the table with data which is generated via this query.
If you want to just execute the query and see the data then remove first line of your query.
-- CREATE TABLE voice2020 AS
SELECT
.....
Also, the data of your actual query must be present in the voice2020 table if you have already executed it once.
Select * from voice2020;
Looks like you are trying to copying the data from one table to another table, Can you once create the table if it's not created and then try this statement.
insert into target_table select * from source_table;
Can somebody help me?
I am try execute the command below in Oracle 11 and I get this error:
SQL Error [905] [42000]: ORA-00905: keyword not found.
Code:
SELECT *
INTO SAJ.ETMP_TESTE
FROM SAJ.ESAJOBJETO O
WHERE CDOBJETO = 'P800000000J03'
I read the Oracle docs and haven't found any obvious error in my statement.
https://docs.oracle.com/cd/B19306_01/appdev.102/b14261/selectinto_statement.htm
My objective is to create the table ETMP_TESTE with structure from ESAJOBJETO.
I checked user permission and user has permission to action.
You need create table and not select into for create a table based on the result of a query
CREATE TABLE SAJ.ETMP_TESTE
AS SELECT *
FROM SAJ.ESAJOBJETO O
WHERE CDOBJETO = 'P800000000J03'
This will create an empty table named ETMP_TESTE, with the structure of the SAJ.EASJOBJETO table.
CREATE TABLE ETMP_TESTE AS
SELECT *
FROM SAJ.EASJOBJETO
WHERE 1 = 0;
This does not handle contraints and primary keys and things like that, but it will get you the table structure. The 1 = 0 makes sure no data is copied.
If you need primary keys and the like, look into extracting the DDL for EASJOBJETO. Most SQL IDEs have that functionality built in. You can edit it to correct the table name and run the script and get everything.
I am using APEX collections to store some values and pass them between pages in Oracle Application Express 4.2.3.
I would like to then perform an update statement on a table called "project" with the values from the collection.
My code so far is as follows:
update project
SET name=c.c002,
description=c.c007,
start_date=c.c004,
timeframe=c.c005,
status=c.c009
FROM
apex_collections c
WHERE
c.collection_name = 'PROJECT_DETAILS_COLLECTION'
and id = :p14_id;
where :p14_id is the value of a page item.
However, I am getting the following error:
ORA-00933: SQL command not properly ended
Anyone have any idea on how to approach this?
Thanks!
The UPDATE syntax you are using is not valid in Oracle; it does not allow you to use FROM in the way you are attempting.
The simplest way to do this in Oracle would with a subquery:
update project
set (name, description, start_date, timeframe, status) =
(select c.c002, c.c007, c.c004, c.c005, c.c009
FROM
apex_collections c
WHERE
c.collection_name = 'PROJECT_DETAILS_COLLECTION'
)
WHERE
id = :p14_id
;
Note that if the subquery returns no rows, the columns in the target table will be updated to NULL; this could be avoided by adding a similar EXISTS condition in the predicate for the update. It could also be avoided by using a MERGE statement instead of an UPDATE.
If the subquery returns multiple rows, the statement will throw an error. It looks like tthat should not be the case here.
I try to write a query to delete some rows in treasure-data but the server ignored it. I'm missing documentation to resolve this issue.
Here is the logs:
Use 'td job:show 2485728' to show the status.
queued...
started at 2013-04-18T10:22:32Z
Hive history file=/mnt/hive/tmp/2073/hive_job_log__336863980.txt
finished at 2013-04-18T10:22:39Z
Ignored "delete from mytable where time < unix_timestamp() - 30*60*60*24"
Sorry, but there is no delete statement in HIVE. One possible trick could be rewriting the table:
INSERT OVERWRITE TABLE mytable
SELECT * FROM mytable
WHERE time >= unix_timestamp() - 30*60*60*24
I have a table MRU, that has 3 columns.
(VALUE varchar(255); TYPE varchar(20); DT_ADD datetime)
This is a table simply storing an entry and recording the date time it was recorded. What I wanted to do is: delete the oldest entry whenever I add a new entry that exceeds a certain number.
Here is my query:
delete from MRU
where type = 'FILENAME'
ORDER BY DT_ADD limit 1;
The error message is:
SQL Error: near "ORDER": syntax error ...
The query returns an error.
First of all, it always helps posting as much information as you have. In this particular instance, "an error" is unhelpful and it would've taken you perhaps 2 seconds to copy and paste the actual error message given, which would give us valuable clues when helping you.
Instead, I went to the documentation for the DELETE statement of SQLite, found here, and notice that lo and behold, DELETE does not have ORDER BY, unless it is compiled in a specific manner. I assume your version isn't, although without the error message it is hard to tell.
What you can try instead is this:
delete from MRU where DT_ADD = (
SELECT MIN(DT_ADD) FROM MRU WHERE type = 'FILENAME'
)
I'm not saying that you should do so, since it's completely non-portable, but if there's a compelling need, this will work:
In SQLite the rowid column always exists unless an integer primary key is defined elsewhere. This can be used in something like:
delete from MRU where rowid = (
select rowid from MRU order by DT_ADD limit 1
)