Need a sql statement to remove data?
Hello,
I need your help regarding my query.
I need to put a sql statement in a shell script that will delete records from a table that is > than 3 months old and if not, do nothing.
The table has a DATE column as shown below:
LOG_ID NOT NULL VARCHAR2(8)
LOG_TYPE NOT NULL VARCHAR2(8)
LOG_MESSAGE NOT NULL VARCHAR2(255)
LOG_DATE DATE
I'm a novoice at sql and request you to provide me a sql statement that will do the above.
Much appreciated!
Regards,
SQL> select sysdate from dual;
SYSDATE
14-JUL-09
SQL> select add_months(sysdate,-3) from dual;
ADD_MONTH
14-APR-09
SQL> select add_months(sysdate,-3)-1 from dual;
ADD_MONTH
13-APR-09
DELETE FROM {table_name} WHERE HIREDATE<={pick the date format from above accordingly}
Similar Messages
-
Hi,
From the SQL statement below, i need help in explaining what does the line "WHERE ( lims_sys.result.result_template_id = lims_sys.result_template_limit.result_template_id (+))" do?
This statement was written by a vendor and now i have problem displaying some new data. Only a portion of what i need is displayed.
SELECT "LIMS_SYS"."RESULT"."DESCRIPTION",
"LIMS_SYS"."RESULT_TEMPLATE_LIMIT"."NUMERIC_LIMIT",
"LIMS_SYS"."RESULT"."FORMATTED_RESULT",
"LIMS_SYS"."RESULT"."CONCLUSION",
"LIMS_SYS"."RESULT_USER"."U_RESULT_SEQUENCE" ,
"LIMS_SYS"."RESULT"."RESULT_ID"
FROM "LIMS_SYS"."RESULT",
"LIMS_SYS"."RESULT_TEMPLATE_LIMIT",
"LIMS_SYS"."RESULT_USER",
"LIMS_SYS"."ALIQUOT",
"LIMS_SYS"."SAMPLE",
"LIMS_SYS"."SDG",
"LIMS_SYS"."TEST"
WHERE ( lims_sys.result.result_template_id = lims_sys.result_template_limit.result_template_id (+)) and
( "LIMS_SYS"."RESULT"."RESULT_ID" = "LIMS_SYS"."RESULT_USER"."RESULT_ID" ) and
( "LIMS_SYS"."SDG"."SDG_ID" = "LIMS_SYS"."SAMPLE"."SDG_ID" ) and
( "LIMS_SYS"."SAMPLE"."SAMPLE_ID" = "LIMS_SYS"."ALIQUOT"."SAMPLE_ID" ) and
( "LIMS_SYS"."ALIQUOT"."ALIQUOT_ID" = "LIMS_SYS"."TEST"."ALIQUOT_ID" ) and
( "LIMS_SYS"."TEST"."TEST_ID" = "LIMS_SYS"."RESULT"."TEST_ID" ) and
( ( LIMS_SYS."SDG"."SDG_ID" = :sdg_id ) AND
( LIMS_SYS."RESULT"."STATUS" <> 'X' ) AND
( LIMS_SYS."RESULT"."REPORTED" = 'T' ) AND
( LIMS_SYS."RESULT_USER"."U_RESULT_CATEGORY" in ( 'Metal' , 'Mean Metal', 'Range Metal')) )
Thanks for all your help.Hi,
After WHERE .......... is indicates an OUTER Join condition.
In this type of join, system retrieves the data for matched and
as well as unmatched.
Example:
EMP table have a column DEPTNO with the data 10, 20, 30 (total rows=14)
DEPT table have a column DEPTNO with the data 10, 20, 30, 40, 50 (total rows=5)
If the WHERE clause contained EMP.DEPTNO(+) = DEPT.DEPTNO
then the output contain the data relative to 10, 20, 30, 40, 50 (total rows = 16)
i.e. 14 rows (with matching data) and 2 rows (with unmatching data)
Regards,
Sailaja -
SQL statement to compare dates and return boolean (yes/no)
I am looking for a SQL statement that can compare 2 dates and return a boolean. 1 (yes) if date 1 is => date2-threshold or 0 (No) if date < date2-threshold
Ie
date1=20130603
threshold=2 days
date2=sysdate-threshold
if [ 20130603 > sysdate-$threshold ]
then
return 1
else
return 0
fi
Thanks to all that answer.Assumming I want to get "date1" from some other table instead of from
dual will this syntax be valid
I was going to invoke another SQLPLUS from my shell script and pass it in
as a variable but if I can do it on one shot it would be better.
In addition, if "no rows" are found for date1 from the below query, would
I need code to handle that
with xx as
select TO_DATE(last_date','yyyymmdd') date1, from dba_audit_table where ...;
select TO_DATE('20130603','yyyymmdd') date1, sysdate date2 from dual;
Thanks to all who answer
[/code1] -
Need pl/sql code to Encrypted data to decryption formate
Hi All,
I have Encrypted data 64 bit formate like
encrypt
780D0287
FA57C55510D258C73DE93059E3DC49EC
need output as a Decryption data..kindly give me outputThis is your duplicate post...
Re: Need pl/sql code to decryption
*009* -
SQL statement - when no data found
I have this SQL statement as follows:
SELECT (Case When tar_customer_id <> 0 Then tar_customer_id Else 0 End) INTO l_balance_customerID FROM sh_ba_balance WHERE tar_customer_id = p.customer_id; However, when I tried run it, I have this error:
ORA-01403: no data foundHow do set l_balance_customerID as 0 when no data is found?[url http://forums.oracle.com/forums/thread.jspa?messageID=2754839�]duplicate thread
-
After specifying a DSN, and an sql statement to SELECT data I can run the Complete SQL
Session VI in the SQL toolkit. The query results return the requested data, and no errors are produced. When I depress the run arrow a second time, I get an illegal operation message and have to shut down Labview. Have you had problems like this before?
Session VI in the SQL toolkit. The query results return the requested data, and no errors are produced. When I depress the run arrow a second time, I get an illegal operation message and have to shut down Labview. Have you had problems like this before?Hello,
You may want to see if there is an update for the ODBC driver of the database you are using. Many times, a crash is caused because of a problem with the driver. You may also want to search the NI website for more information (search for +SQL +Sybase for example, if you are using a Sybase database.)
Good luck!
Sincerely,
Darren Nattinger
Applications Engineer
National Instruments
Darren Nattinger, CLA
LabVIEW Artisan and Nugget Penman -
Help needed with SQL to split huge data into two excel or text files.
Hi,
I have a table which has around 1850000 records. I want to split the data into two sets and import the data in .txt or execl file.
How can i break upthe records using rownum or any thing
select * from tablename where rownum<940000 fetched some records
but
when i gave select * from tablename where rownum>940000 it was not fetching records.
Guidemewhen i gave select * from tablename where rownum>940000 it was not fetching records.try this
select * from (select tablename.*, rownum rn from tablename) where rn >940000 -
Same SQL Statement Works in Data Service but not in its Input Port
Hi Experts,
I am using this query in one of my data service. Test execute success which returned:
E U H M L
2 Less Than 1 Week 0 0 0 0 0
3 1 - 2 weeks 0 0 0 0 0
4 2 - 4weeks 0 0 0 0 0
5 More Than 1 Month 0 0 6 0 0
However, when i copy the same query to the input port, enclosing it with "[my query]"
Deployed and run it. I get an "Unspecified Error" message box prompted in the iView, and null pointer exception error in the log file.
#1.5 #001A64CA3F5600660000034400001140000487DBB6D27A4D#1275277641800#com.sap.portal.visualComposer_NWBIKit_logger#sap.com/irj#com.sap.portal.visualComposer_NWBIKit_logger#TOMAS004#89896##n/a##37c590906c6711df8503001a64ca3f56#SAPEngine_Application_Thread[impl:3]_32##0#0#Error#1#/System/Server#Java###null
[EXCEPTION]
#1#java.lang.NullPointerException
at com.sap.portal.guimachine.bikit.query.relational.impl.BIRelationalQuerySql.processTemplateParams(BIRelationalQuerySql.java:40)
at com.sap.portal.guimachine.bikit.query.relational.impl.BIRelationalQuerySql.<init>(BIRelationalQuerySql.java:31)
at com.sap.portal.guimachine.bikit.query.relational.impl.BIRelationalFactory.newRelationalQuery(BIRelationalFactory.java:59)
Any idea what is the mistake?
Thanks in Advance,
SarahHi Experts,
I am using this query in one of my data service. Test execute success which returned:
E U H M L
2 Less Than 1 Week 0 0 0 0 0
3 1 - 2 weeks 0 0 0 0 0
4 2 - 4weeks 0 0 0 0 0
5 More Than 1 Month 0 0 6 0 0
However, when i copy the same query to the input port, enclosing it with "[my query]"
Deployed and run it. I get an "Unspecified Error" message box prompted in the iView, and null pointer exception error in the log file.
#1.5 #001A64CA3F5600660000034400001140000487DBB6D27A4D#1275277641800#com.sap.portal.visualComposer_NWBIKit_logger#sap.com/irj#com.sap.portal.visualComposer_NWBIKit_logger#TOMAS004#89896##n/a##37c590906c6711df8503001a64ca3f56#SAPEngine_Application_Thread[impl:3]_32##0#0#Error#1#/System/Server#Java###null
[EXCEPTION]
#1#java.lang.NullPointerException
at com.sap.portal.guimachine.bikit.query.relational.impl.BIRelationalQuerySql.processTemplateParams(BIRelationalQuerySql.java:40)
at com.sap.portal.guimachine.bikit.query.relational.impl.BIRelationalQuerySql.<init>(BIRelationalQuerySql.java:31)
at com.sap.portal.guimachine.bikit.query.relational.impl.BIRelationalFactory.newRelationalQuery(BIRelationalFactory.java:59)
Any idea what is the mistake?
Thanks in Advance,
Sarah -
Need efficient SQL query to retrieve data for MLM website
Table cd_members
MemberID LeftID RightID
1 2 3
2 4 5
3 6 7
4 8 -
5 - -
6 - -
7 - -
8 9 10
9 - -
10 - -
i want to execute a query to retrieve downline of a member say MemberID 2
o/p should be Records with MemberID 4,5,8,9,10
i am using this query but don't know how to start from MembeID=2
select a.memberid, a.tradingid, a.refid, a.parentid, a.node, a.leftid, a.rightid, b.memberid from cd_members a, cd_members b
where (a.leftid=b.memberid or a.rightid=b.memberid)Again, assuming that the number of levels is known, you can just do N self joins (note that I intentionally go one level further than necessary in this case
SQL> ed
Wrote file afiedt.buf
1 with t
2 as
3 (
4 select 1 person, 2 left, 3 right from dual union all
5 select 2, 4, 5 from dual union all
6 select 3, 6, 7 from dual union all
7 select 4, 8, null from dual union all
8 select 5, null, null from dual union all
9 select 6, null, null from dual union all
10 select 7, null, null from dual union all
11 select 8, 9, 10 from dual union all
12 select 9, null, null from dual union all
13 select 10, null, null from dual
14 )
15 select t1.left, t1.right, t2.left, t2.right, t3.left, t3.right, t4.left, t
4.right
16 from t t1,
17 t t2,
18 t t3,
19 t t4
20 where t1.person = 2
21 and t1.left = t2.person(+)
22 and t2.left = t3.person(+)
23* and t3.left = t4.person(+)
SQL> /
LEFT RIGHT LEFT RIGHT LEFT RIGHT LEFT
RIGHT
4 5 8 9 10Justin -
SQL Statement needed for Query Generator
Dear Experts,
My view has the following three columns.
1, Start Date
2. End Date
3. Balance.
I need an SQL statement to write in query generator, which has to check if EndDate is less than the Current date and balance is above zero. If so, it assumes the last date of the job is already over, outstanding materials not yet been returned. Hence it has to return 'Pending'. If EndDate is greater than current date, it means final date for completion of the process is yet to come. So the task is in progress, hence it has to return 'Progress'. If the balance is Zero, all materials connected with the task have been received either as a FG or as Raw Materials. So it has to return, 'Completed'. I need a singe SQL Statement for this.
Please help me.
Thanks in advance.
Regards
AnandDear Anand,
Try this one:
CASE balance WHEN 0 THEN 'Completed' ELSE CASE WHEN DATEDIFF(DD, EndDate, GetDate()) >= 0 THEN 'Progress' ELSE 'Pending' END END
I have assumed you don't have negative balance. It that is not true, give me the complete case.
Thanks,
Gordon
Thanks,
Gordon -
Multiple SQL Statements in Data Template
If I have more than 1 sql statements in a data template, how can I target them directly? I would like to link directly to a report and don't want to use the default sql statement.
Sorry, could you please elaborate further.
-
Need help for the sql statement !!!!!
hi all,
i need a sql statement for a query, how can i get the result from the rownum between 100 and 150?
plz helpuse a scrollable statement:
PreparedStatement stat = Connection.prepareStement("select * from blah", ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE);
ResultSet rs = stat.executeQuery();
rs.absolute(100);
while (rs.next()) {
String something = rs.get(1);
Look into the JDK API reference for ResultSet to get an expalantion of scrollable statements. -
Help with SQL statement in a coldfusion application
I created 2 drop down list boxes one that contains the months
and the second that contains the year. Right now my sql statement
is Select * from job where releaseDate=#imageDate#. Now this was
written in 2006 and I didn't know they were going to continue to
use the tool in 2007. So now I need a sql statement that if a user
selects Jan 2007 that all of jan 2007 will display. The format for
the datetime field in the database is Jan 2 2007 hh:mm:ss the first
box is named imageDate and the second is called StatusDateTake a look at the T-SQL datepart function.
Bryan Ashcraft (remove BRAIN to reply)
Web Application Developer
Wright Medical Technology, Inc.
Macromedia Certified Dreamweaver Developer
Adobe Community Expert (DW) ::
http://www.adobe.com/communities/experts/
"rere" <[email protected]> wrote in message
news:fjp4im$fqk$[email protected]..
>I created 2 drop down list boxes one that contains the
months and the
>second
> that contains the year. Right now my sql statement is
Select * from job
> where
> releaseDate=#imageDate#. Now this was written in 2006
and I didn't know
> they
> were going to continue to use the tool in 2007. So now I
need a sql
> statement
> that if a user selects Jan 2007 that all of jan 2007
will display. The
> format
> for the datetime field in the database is Jan 2 2007
hh:mm:ss the first
> box is
> named imageDate and the second is called StatusDate
> -
SQL Statements in ABAP and meaning
Hello Friends,
Please, can anybody provide me a documentation on the different ABAP SQL statements and there usage/meanings.
Thanks,
Shreekanthi,
goto abapdocu->abap Database access->open Sql you will get examples.
for documnetation got se38->specify the command and press F1.
SELECT:
Put the curson on that word and press F1 . You can see the whole documentation for select statements.
SELECT result
FROM source
INTO|APPENDING target
[[FOR ALL ENTRIES IN itab] WHERE sql_cond]
Effect
SELECT is an Open-SQL-statement for reading data from one or several database tables into data objects.
The select statement reads a result set (whose structure is determined in result ) from the database tables specified in source, and assigns the data from the result set to the data objects specified in target. You can restrict the result set using the WHERE addition. The addition GROUP BY compresses several database rows into a single row of the result set. The addition HAVING restricts the compressed rows. The addition ORDER BY sorts the result set.
The data objects specified in target must match the result set result. This means that the result set is either assigned to the data objects in one step, or by row, or by packets of rows. In the second and third case, the SELECT statement opens a loop, which which must be closed using ENDSELECT. For every loop pass, the SELECT-statement assigns a row or a packet of rows to the data objects specified in target. If the last row was assigned or if the result set is empty, then SELECT branches to ENDSELECT . A database cursor is opened implicitly to process a SELECT-loop, and is closed again when the loop is ended. You can end the loop using the statements from section leave loops.
Up to the INTO resp. APPENDING addition, the entries in the SELECTstatement define which data should be read by the database in which form. This requirement is translated in the database interface for the database system´s programming interface and is then passed to the database system. The data are read in packets by the database and are transported to the application server by the database server. On the application server, the data are transferred to the ABAP program´s data objects in accordance with the data specified in the INTO and APPENDING additions.
System Fields
The SELECT statement sets the values of the system fields sy-subrc and sy-dbcnt.
sy-subrc Relevance
0 The SELECT statement sets sy-subrc to 0 for every pass by value to an ABAP data object. The ENDSELECT statement sets sy-subrc to 0 if at least one row was transferred in the SELECT loop.
4 The SELECT statement sets sy-subrc to 4 if the result set is empty, that is, if no data was found in the database.
8 The SELECT statement sets sy-subrc to 8 if the FOR UPDATE addition is used in result, without the primary key being specified fully after WHERE.
After every value that is transferred to an ABAP data object, the SELECT statement sets sy-dbcnt to the number of rows that were transferred. If the result set is empty, sy-dbcnt is set to 0.
Notes
Outside classes, you do not need to specify the target area with INTO or APPENDING if a single database table or a single view is specified statically after FROM, and a table work area dbtab was declared with the TABLES statement for the corresponding database table or view. In this case, the system supplements the SELECT-statement implicitly with the addition INTO dbtab.
Although the WHERE-condition is optional, you should always specify it for performance reasons, and the result set should not be restricted on the application server.
SELECT-loops can be nested. For performance reasons, you should check whether a join or a sub-query would be more effective.
Within a SELECT-loop you cannot execute any statements that lead to a database commit and consequently cause the corresponding database cursor to close.
SELECT - result
Syntax
... lines columns ... .
Effect The data in result defines whether the resulting set consists of multiple rows (table-like structure) or a single row ( flat structure). It specifies the columns to be read and defines their names in the resulting set. Note that column names from the database table can be changed. For single columns, aggregate expressions can be used to specify aggregates. Identical rows in the resulting set can be excluded, and individual rows can be protected from parallel changes by another program.
The data in result consists of data for the rows lines and for the columns columns.
SELECT - lines
Syntax
... { SINGLE }
| { { } } ... .
Alternatives:
1. ... SINGLE
2. ... { }
Effect
The data in lines specifies that the resulting set has either multiple lines or a single line.
Alternative 1
... SINGLE
Effect
If SINGLE is specified, the resulting set has a single line. If the remaining additions to the SELECT command select more than one line from the database, the first line that is found is entered into the resulting set. The data objects specified after INTO may not be internal tables, and the APPENDING addition may not be used.
An exclusive lock can be set for this line using the FOR UPDATE addition when a single line is being read with SINGLE. The SELECT command is used in this case only if all primary key fields in logical expressions linked by AND are checked to make sure they are the same in the WHERE condition. Otherwise, the resulting set is empty and sy-subrc is set to 8. If the lock causes a deadlock, an exception occurs. If the FOR UPDATE addition is used, the SELECT command circumvents SAP buffering.
Note
When SINGLE is being specified, the lines to be read should be clearly specified in the WHERE condition, for the sake of efficiency. When the data is read from a database table, the system does this by specifying comparison values for the primary key.
Alternative 2
Effect
If SINGLE is not specified and if columns does not contain only aggregate expressions, the resulting set has multiple lines. All database lines that are selected by the remaining additions of the SELECT command are included in the resulting list. If the ORDER BY addition is not used, the order of the lines in the resulting list is not defined and, if the same SELECT command is executed multiple times, the order may be different each time. A data object specified after INTO can be an internal table and the APPENDING addition can be used. If no internal table is specified after INTO or APPENDING, the SELECT command triggers a loop that has to be closed using ENDSELECT.
If multiple lines are read without SINGLE, the DISTINCT addition can be used to exclude duplicate lines from the resulting list. If DISTINCT is used, the SELECT command circumvents SAP buffering. DISTINCT cannot be used in the following situations:
If a column specified in columns has the type STRING, RAWSTRING, LCHAR or LRAW
If the system tries to access pool or cluster tables and single columns are specified in columns.
Note
When specifying DISTINCT, note that you have to carry out sort operations in the database system for this.
SELECT - columns
Syntax
| { {col1|aggregate( col1 )}
{col2|aggregate( col2 )} ... }
| (column_syntax) ... .
Alternatives:
1. ... *
2. ... {col1|aggregate( col1 )}
{col2|aggregate( col2 )} ...
3. ... (column_syntax)
Effect
The input in columns determines which columns are used to build the resulting set.
Alternative 1
Effect
If * is specified, the resulting set is built based on all columns in the database tables or views specified after FROM, in the order given there. The columns in the resulting set take on the name and data type from the database tables or views. Only one data object can be specified after INTO.
Note
If multiple database tables are specified after FROM, you cannot prevent multiple columns from getting the same name when you specify *.
Alternative 2
... {col1|aggregate( col1 )}
{col2|aggregate( col2 )} ...
Effect
A list of column labels col1 col2 ... is specified in order to build the resulting list from individual columns. An individual column can be specified directly or as an argument of an aggregate function aggregate. The order in which the column labels are specified is up to you and defines the order of the columns in the resulting list. Only if a column of the type LCHAR or LRAW is listed does the corresponding length field also have to be specified directly before it. An individual column can be specified multiple times.
The addition AS can be used to define an alternative column name a1 a2 ... with a maximum of fourteen digits in the resulting set for every column label col1 col2 .... The system uses the alternative column name in the additions INTO|APPENDING CORRESPONDING FIELDS and ORDER BY. .
http://help.sap.com/saphelp_nw04/helpdata/en/62/10a423384746e8bf5f15ccdd36e8b1/content.htm -
Group by sql statement is not sorted.
execut sql statement include group by clause in a oci program, the result is not sorted.
I don't know why..
in SqlPlus, same sql statement return sorted data.
SELECT A.SHOP_ID,A.RESALE_TYPE,
SUM(A.DEAL_AMT,0) DEAL_AMT
FROM SHOP_ACC A, CD_TAB C
WHERE A.RESALE_TYPE = C.CD(+)
AND C.GB = 'AB'
AND A.ACC_M = :s_AccMonth
AND DEAL_GB='FOD'
GROUP BY A.SHOP_ID,A.RESALE_TYPE
But, RESALE_TYPE is outer join on CD_TAB..
if remove outer join between CD_TAB and SHOP_ACC,
sql statement is return sorted result.
and if modify the column RESALE_TYPE like
RESALE_TYPE||']' or NVL(RESALE_TYPE,'AAA')
return sorted result..
please help..
thanks for your kind.thank you.. for reply..
I knew that order by clause make to sort.
but, using group by clause alone in SQL statement, that return sorted results too.
I was found a fault that outer join table CD_TAB column of one is not symbloc "(+)" in SQL statement
SELECT A.SHOP_ID,A.RESALE_TYPE,
SUM(A.DEAL_AMT,0) DEAL_AMT
FROM SHOP_ACC A, CD_TAB C
WHERE A.RESALE_TYPE = C.CD(+)
AND C.GB = 'AB' <----------- AND C.GB(+) = 'AB'
AND A.ACC_M = :s_AccMonth
AND DEAL_GB='FOD'
GROUP BY A.SHOP_ID,A.RESALE_TYPE
I want to know that why in other application - such as SqlPlus or SqlGate and ..etc. - this fault was ignore.. but OCI application such as my application programs is not ignore.. and is not sorted..
thank you..
Maybe you are looking for
-
Building BI Publisher report with "BI Answers" data model
I've installed OBIEE 10.1.3.4.1 and try to create a BI Publisher report using BI Answers as data model. The catalog list of Answers comes up empty, and in the log files I find following error: - Exception: AxisFault faultCode: {http://schemas.xmlsoap
-
Reference of 103 mat.doc. in 105 doc. , when GR based IV is not selected
Hi, I required logic, to list out 103 material documents for which movt. 105 is not made , If GR based IV is not selected in PO. We know, each MIGO document has a reference document number. In case of 103 document, the reference document number is th
-
How to pass date range as filter in Go URL
Hi, I am trying to construct a Go Url which has two filters, date range & text. I have constructed the url as below but it keeps throwing an error. The url is not passing the max date and the application is throwing following error: Error: State: HY0
-
Toshiba display drvier vs other sources - Satellite P100
Hi, A couple of questions... I bought a P100-188 (pspa3e) a couple of weeks ago from PC World (don't hate me, they were cheapest that had it in stock!), it came with installed NVIDIA drivers 6.14.10.8400 - presumably based on Forceware 84 from NVIDIA
-
Re: Qosmio F30-125 - Where to find the drivers?
Hi there, I am trying to source my drivers for a format of my laptop (PQF30E) and cannot find any when I search on the download pages. Can some one please help me find them? I looked on www.csd.toshiba.com/cgi-bin/tais/support/jsp/home.jsp?nav=Downlo