Oracle SQL query for getting specific special characters from a table
Hi all,
This is my table
Table Name- Table1
S.no Name
1 aaaaaaaa
2 a1234sgjghb
3 a@3$%jkhkjn
4 abcd-dfghjik
5 bbvxzckvbzxcv&^%#
6 ashgweqfg/gfjwgefj////
7 sdsaf$([]:'
8 <-fdsjgbdfsg
9 dfgfdgfd"uodf
10 aaaa bbbbz#$
11 cccc dddd-/mnm
The output has to be
S.no Name
3 a@3$%jkhkjn
5 bbvxzckvbzxcv&^%#
7 sdsaf$([]:'
8 <-fdsjgbdfsg
10 aaaa bbbbz#$
It has to return "Name" column which is having special characters,whereas some special chars like -, / ," and space are acceptable.
The Oracle query has to print columns having special characters excluding -,/," and space
Can anyone help me to get a SQL query for the above.
Thanks in advance.
You can achieve it in multiple ways. Here are few.
SQL> with t
2 as
3 (
4 select 1 id, 'aaaaaaaa' name from dual union all
5 select 2 id, 'a1234sgjghb' name from dual union all
6 select 3 id, 'a@3$%jkhkjn' name from dual union all
7 select 4 id, 'abcd-dfghjik' name from dual union all
8 select 5 id, 'bbvxzckvbzxcv&^%#' name from dual union all
9 select 6 id, 'ashgweqfg/gfjwgefj////' name from dual union all
10 select 7 id, 'sdsaf$([]:''' name from dual union all
11 select 8 id, '<-fdsjgbdfsg' name from dual union all
12 select 9 id, 'dfgfdgfd"uodf' name from dual union all
13 select 10 id, 'aaaa bbbbz#$' name from dual union all
14 select 11 id, 'cccc dddd-/mnm' name from dual
15 )
16 select *
17 from t
18 where regexp_like(translate(name,'a-/" ','a'), '[^[:alnum:]]');
ID NAME
3 a@3$%jkhkjn
5 bbvxzckvbzxcv&^%#
7 sdsaf$([]:'
8 <-fdsjgbdfsg
10 aaaa bbbbz#$
SQL> with t
2 as
3 (
4 select 1 id, 'aaaaaaaa' name from dual union all
5 select 2 id, 'a1234sgjghb' name from dual union all
6 select 3 id, 'a@3$%jkhkjn' name from dual union all
7 select 4 id, 'abcd-dfghjik' name from dual union all
8 select 5 id, 'bbvxzckvbzxcv&^%#' name from dual union all
9 select 6 id, 'ashgweqfg/gfjwgefj////' name from dual union all
10 select 7 id, 'sdsaf$([]:''' name from dual union all
11 select 8 id, '<-fdsjgbdfsg' name from dual union all
12 select 9 id, 'dfgfdgfd"uodf' name from dual union all
13 select 10 id, 'aaaa bbbbz#$' name from dual union all
14 select 11 id, 'cccc dddd-/mnm' name from dual
15 )
16 select *
17 from t
18 where translate
19 (
20 lower(translate(name,'a-/" ','a'))
21 , '.0123456789abcdefghijklmnopqrstuvwxyz'
22 , '.'
23 ) is not null;
ID NAME
3 a@3$%jkhkjn
5 bbvxzckvbzxcv&^%#
7 sdsaf$([]:'
8 <-fdsjgbdfsg
10 aaaa bbbbz#$
SQL>
Similar Messages
-
SQL query to get last 10 records in the table?
Hi,
Can anyone tell me the SQL query to get last 10 records in the table?
Thanks!!
MCPPlease, define what "last" means. Sets are unordered by definition, so if you want to retrieve rows from a table in a specific order you need to specify what that order is - e.g. by maintaining a value in a column (or a combination of columns) that you can use in the ORDER BY clause of the SELECT statement.
If, for instance, you kept the time when the row was inserted in a special column (InsertedTime), you could use this in your query like this:
select top (10)
<column list>
from <table or view>
where <restriction(s)>
order by InsertedTime desc;
ML
Matija Lah, SQL Server MVP
http://milambda.blogspot.com -
OIM sql Query for getting the status of the task which got failed
Hi Everyone,
We have a requirement like we need to get the status of a particular task(say Create User in OID resource - Completed\Rejected status) for the particular user.We are able to get the status of the resource provisioed to the user but not the status of the particular task getting trigerred for the user.can someone put some light on this.We need to get the SQL query for this.
Thanks in Advance.
Regards,
MKNHi
Use this sample query to get the task status, also check the cooments
SELECT USR.USR_LOGIN, OSI.SCH_KEY,SCH.SCH_STATUS,STA.STA_BUCKET FROM
OSI,SCH,STA,MIL,TOS,PKG,OIU,USR,OBJ,OST
WHERE OSI.MIL_KEY=MIL.MIL_KEY
AND SCH.SCH_KEY=OSI.SCH_KEY
AND STA.STA_STATUS=SCH.SCH_STATUS
AND TOS.PKG_KEY=PKG.PKG_KEY
AND MIL.TOS_KEY=TOS.TOS_KEY
AND OIU.USR_KEY=USR.USR_KEY
AND OIU.OST_KEY=OST.OST_KEY
AND OST.OBJ_KEY=OBJ.OBJ_KEY
AND OSI.ORC_KEY=OIU.ORC_KEY
AND OBJ.OBJ_NAME='AD User'
AND OST.OST_STATUS = 'Provisioning' -- filter accordinglly
AND STA.STA_BUCKET = 'Pending' -- filter accordinglly
AND PKG.PKG_NAME='AD User' -- filter accordinglly
AND MIL.MIL_NAME='System Validation' ---- filter accordinglly
Thanks,
Kuldeep -
HOW TO CHANGE SQL QUERY TO GET SPECIFIC RESULT
I HAVE FOLLOWING QUERY AND ITS FUNCTIONING BUT I WANT ALL THOSE RECORD SHOULD BE DISPLADE WICH HAVE NO TRANSACTION IN SALES ANS SALES RETURN WHILE RETREVING DATA FROM DATABASE.
I TRIED TO USE + OPERATOR BUT I DON'T KNOW HOW TO CHANGE THE QUERY TO GET THE RESULT
MAIN TABLE IS BEING USED TO FETCH RECORD
SALES_HEADER,SALES_DETAIL
SALES_HEADERR,SALES_DETAILR
STOCK_REG
AND THE QUERY IS
select s.item_code,S.DESCR,s.GRAND_TOTAL,
sum(decode(d.dayno,01,NVL(S.QTY,0),0)) DAY1,
sum(decode(d.dayno,02,NVL(S.QTY,0),0)) DAY2,
sum(decode(d.dayno,03,NVL(S.QTY,0),0)) DAY3,
sum(decode(d.dayno,04,NVL(S.QTY,0),0)) DAY4,
sum(decode(d.dayno,05,NVL(S.QTY,0),0)) DAY5,
sum(decode(d.dayno,06,NVL(S.QTY,0),0)) DAY6,
sum(decode(d.dayno,07,NVL(S.QTY,0),0)) DAY7,
sum(decode(d.dayno,08,NVL(S.QTY,0),0)) DAY8,
sum(decode(d.dayno,09,NVL(S.QTY,0),0)) DAY9,
sum(decode(d.dayno,10,NVL(S.QTY,0),0)) DAY10,
sum(decode(d.dayno,11,NVL(S.QTY,0),0)) DAY11,
sum(decode(d.dayno,12,NVL(S.QTY,0),0)) DAY12,
sum(decode(d.dayno,13,NVL(S.QTY,0),0)) DAY13,
sum(decode(d.dayno,14,NVL(S.QTY,0),0)) DAY14,
sum(decode(d.dayno,15,NVL(S.QTY,0),0)) DAY15,
sum(decode(d.dayno,16,NVL(S.QTY,0),0)) DAY16,
sum(decode(d.dayno,17,NVL(S.QTY,0),0)) DAY17,
sum(decode(d.dayno,18,NVL(S.QTY,0),0)) DAY18,
sum(decode(d.dayno,19,NVL(S.QTY,0),0)) DAY19,
sum(decode(d.dayno,20,NVL(S.QTY,0),0)) DAY20,
sum(decode(d.dayno,21,NVL(S.QTY,0),0)) DAY21,
sum(decode(d.dayno,22,NVL(S.QTY,0),0)) DAY22,
sum(decode(d.dayno,23,NVL(S.QTY,0),0)) DAY23,
sum(decode(d.dayno,24,NVL(S.QTY,0),0)) DAY24,
sum(decode(d.dayno,25,NVL(S.QTY,0),0)) DAY25,
sum(decode(d.dayno,26,NVL(S.QTY,0),0)) DAY26,
sum(decode(d.dayno,27,NVL(S.QTY,0),0)) DAY27,
sum(decode(d.dayno,28,NVL(S.QTY,0),0)) DAY28,
sum(decode(d.dayno,29,NVL(S.QTY,0),0)) DAY29,
sum(decode(d.dayno,30,NVL(S.QTY,0),0)) DAY30,
sum(decode(d.dayno,31,NVL(S.QTY,0),0)) DAY31,
sum(S.qty) TU
FROM
(select nvl(sales_detail.qty+sales_detail.bonus,0) as qty,
sales_detail.item_code AS ITEM_CODE,
stock_reg.descr AS descr,
s_date as sale_date,stock_reg.GRAND_TOTAL AS GRAND_TOTAL FROM
SALES_DETAIL,SALES_HEADER,STOCK_REG
WHERE SALES_DETAIL.S_ID = SALES_HEADER.S_ID AND
SALES_DETAIL.ITEM_CODE = STOCK_REG.ITEM_CODE(+) AND
STOCK_REG.COMCODE='C1'
UNION all
select -1*nvl(sales_detailR.qty+sales_detailR.bonus,0) as qty,
sales_detailR.item_code AS ITEM_CODE,
stock_reg.descr AS descr,
RETURN_date as sale_date,stock_reg.GRAND_TOTAL AS GRAND_TOTAL FROM
SALES_DETAILR,SALES_HEADERR,STOCK_REG
WHERE SALES_DETAILR.SR_ID = SALES_HEADERR.SR_ID AND
SALES_DETAILR.ITEM_CODE = STOCK_REG.ITEM_CODE(+) AND
STOCK_REG.COMCODE='C1') S,
(select level as dayno
from dual
connect by level <= 31) d
where d.dayno = to_char(s.sALE_date, 'DD') AND TO_DATE(S.SALE_DATE) BETWEEN '&FROMDATE' AND '&TODATE'
GROUP BY S.ITEM_CODE,S.DESCR,S.GRAND_TOTALwell my query running successfully just the quesion was that i wanted to bring some changes in the query to retrieve the complete record which has no transaction in sales
for exmple
if i write the quey
select dept.deptno,sum(sal) from emp,dept
where dept.deptno = emp.deptno
group by dept.deptno
the recult comes as
DEPTNO SUM(SAL)
10 8750
20 10875
30 9400
though there is another deptno which is deptno no 40
have no sal
and when i use this query
select dept.deptno,sum(sal) from emp,dept
where dept.deptno = emp.deptno(+)
group by dept.deptno
it shows the dept no 40 also
DEPTNO SUM(SAL)
10 8750
20 10875
30 9400
40
so to get this i posted query which was to long to understand easily.
i accept that i sholud post short query to make other understand
so check out this
select STOCK_rEG.item_code AS ITEM_CODE,SUM(qty) as qty
FROM
SALES_DETAILR,SALES_HEADERR,STOCK_REG
WHERE SALES_DETAILR.SR_ID = SALES_HEADERR.SR_ID AND
SALES_DETAILR.STOCKCODE = STOCK_REG.STOCKCODE
AND RETURN_DATE = '01-APR-08'
GROUP BY STOCK_rEG.item_code
ORDER BY TO_NUMBER(ITEM_CODE) ASC
when i execute this query i get the following result
ITEM_CODE QTY
84 2
102 3
108 3
116 6
166 3
170 3
thoug there is other items are aalso available in stock which transaction
yet not been done or not been sold out/
so when i use the outer join i get the same result
select STOCK_rEG.item_code AS ITEM_CODE,SUM(qty) as qty
FROM
SALES_DETAILR,SALES_HEADERR,STOCK_REG
WHERE SALES_DETAILR.SR_ID = SALES_HEADERR.SR_ID AND
SALES_DETAILR.STOCKCODE(+) = STOCK_REG.STOCKCODE
AND RETURN_DATE = '01-APR-08'
GROUP BY STOCK_rEG.item_code
ORDER BY TO_NUMBER(ITEM_CODE) ASC
ITEM_CODE QTY
84 2
102 3
108 3
116 6
166 3
170 3
hope i tried to make u understand on better way -
Handling sql query in jsp while extracing records from 3 tables
hi to one and all,
i want to implement the sql query given below in jsp in execute query statement . the query is working in sql but not when implemented using jsp. please help me in resolving this.
Query
SELECT e.Department , e.ETitle , s.basic , s.da, c.address1 , c.address2 from Employee e , Salary s , Contactdetails1 c where e.id = s.id and e.id =c.idIt would help if you gave us a little more info to go on like;
a) post your code
b) post the error message the compiler is giving you -
SQL Query to get first four characters of an address
Hi Gurus,
Can you please help me with the below quries on how to achieve this. Could be really helpful if you could provide a sample sql from your side.
Req:
I have a requriement where I should display the first four non-space characters of an address eg: ROOM becomes R, FLAT becomes F etc. Passing in an address of ROOM A FLAT 1 STARFORD AVENUE would therefore result ‘RAF1’, whereas an address of 23 CORNER STREET would become ‘23CO’.
Words like c/o, co, rear of should be ignored if any.
Thanks in Advance.
Regards,
AashHi, Ashwanth,
Sorry, I don't have the time to do everything for you.
Here's an example of a package body that does standardization. If you can't use this exactly as it is, then at least it will give you some ideas:
CREATE OR REPLACE PACKAGE BODY pk_stnd
AS
-- pk_stnd provides functions useful for standardizing names.
-- ** s t a n d a r d i z e **
-- Return standardized spelling of given text.
FUNCTION standardize
in_text IN VARCHAR2,
in_grp_name IN VARCHAR2,
in_option_text IN VARCHAR2 DEFAULT ''
RETURN VARCHAR2
IS
CURSOR pair_csr (target_grp_name VARCHAR2)
IS
SELECT
st.bad_text,
st.good_text
FROM
stnd_text st,
stnd_text_grp stg
WHERE
stg.grp_name = target_grp_name AND
stg.stnd_text_id = st.stnd_text_id
ORDER BY
stg.order_val;
max_len_val INTEGER := 4000; -- Longest string to be returned
rtn_text VARCHAR2 (4000); -- Standardized text to return
BEGIN
rtn_text := UPPER (SUBSTR (' ' || in_text || ' ', 1, max_len_val));
rtn_text := REPLACE (rtn_text, ',', ', ');
FOR pair_rec IN pair_csr (in_grp_name)
LOOP
rtn_text := REPLACE
rtn_text,
' ' || pair_rec.bad_text || ' ',
' ' || pair_rec.good_text || ' '
END LOOP;
rtn_text := TRIM (rtn_text);
RETURN rtn_text;
END standardize;
END pk_stnd;
SHOW ERRORS
This uses a table called stnd_text, that looks like this:
CREATE TABLE stnd_text
stnd_text_id NUMBER (6) PRIMARY KEY,
bad_text VARCHAR2 (100) NOT NULL,
good_text VARCHAR2 (100),
cmnt_text VARCHAR2 (100)
COMMENT ON TABLE stnd_text IS
'Non-standard texts and their standard replacements';
COMMENT ON COLUMN stnd_text.stnd_text_id IS
'Arbitrary ID for primary key';
COMMENT ON COLUMN stnd_text.bad_text IS
'Non-standard text to be replaced';
COMMENT ON COLUMN stnd_text.good_text IS
'Standard text to replace non-standard (may be NULL if bad_text is to be deleted)';
COMMENT ON COLUMN stnd_text.cmnt_text IS
'Ad-hoc remarks on this entry';
You may not want to use the other table, but if you do:
CREATE TABLE stnd_text_grp
stnd_text_grp_id NUMBER (6) PRIMARY KEY,
stnd_text_id NUMBER (6),
grp_name VARCHAR2 (50) NOT NULL,
order_val NUMBER NOT NULL,
cmnt_text VARCHAR2 (100)
If you have problems writing your own function, post your best attempt, along with CREATE TABLE and INSERT statements for any tables needed, code that shows how you're calling the function, and a specific question. -
Sql Query for getting data between two dates
Dear Sir,
I have one problem, i have date stored in varchar datatype of (X) table in mysql as it was not supporting the date format of (dd/mm/yyyy) so know the problem is,
When i going to get the data between the the two dates it is giving the un reliable answers such that
when i am asking the query as data between 1st April to 31st December 2009 it is showing the data from the 2008 .
is there any way to solve this problem,please help this is an urgent requirement, your replay will be helpful to me.
With Regards
Ramakrishna YYou either have a SQL problem and this is the incorrect place to ask.
Or you have a Java problem in code we cannot see. When posting code use the code tags. Click the CODE button and paste your code between the tags that appear. -
SQL Query for getting Row No for each group
Dear Oracle Gurus,
I want to allocate Rownum to each group. How we can do this with single SQL. Help me on this.
Thanksselect deptno, ename, row_number() over (partition by deptno order by ename) from emp order by 1,3;
-
Guidance for getting material master data from database table
Hi,
I need guidance to fetch following Material master data from the system data base.Please guide me for the same.
BASIC DATA1
BASIC DATA2
MRP1,2,3,4
WORK SCHEDULING
QUALITY MANAGEMENT
ACCOUNTING1
ACCOUNTING2
COSTING1,2
PURCHASING
PURCHASE ORDER TEXTSALES ORG1,2
SALES GENERAL/PLANT
PLANT DATA/STOR.1,2
WAREHOUSE MGMNT1,2
Also please tell me in general what is the reason for error while uploading the data into system using BAPi(AM talking about return message error).
Thank you.
Edited by: sanu debu on Feb 24, 2009 12:41 PM
Edited by: sanu debu on Feb 24, 2009 12:42 PMUse BAPI's
BAPI_MATERIAL_GET_DETAIL
BAPI_MATERIAL_GETALL
BAPI_MATERIAL_GET_ALL -
Need help in SQL query to get only distinct records
Hi all.
I am new to oracle SQL and i want to write a query to get only distinct values from 2 tables.
for example i hade 2 tables table1(employee_id,employee_no,grade) and another table2 with same structure.
for example data in table1 is
Employeeid employeeno Grade
1 101 A
1 101 B
1 101 E
1 101 D
and data in table 2 is
Employeeid employeeno Grade
1 101 A
1 101 B
1 101 E
i want to display only the fourth row like the data that doesnt exist in table2 i,e (1 101 D)
I had too much records in both tables and i jst want to see the records that is in table 1 not in table 2 only.
employeeid and employeeno are the same in both tables
I hope u understand my query. I user left outer join and right outer join bt it displays all the results that and matching and unmatching. I want jst unmatched records.
Any help is highly Appreciated.
Thanx in Advance.
I am using oracle 10G on windowsTry MINUS:
http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/queries004.htm#i2054381
SQL> -- generating sample data:
SQL> with t1 as (
2 select 1 employeeid, 101 employeeno, 'A' grade from dual union
3 select 1, 101, 'B' from dual union
4 select 1, 101, 'E' from dual union
5 select 1, 101, 'D' from dual
6 )
7 , t2 as (
8 select 1 employeeid, 101 employeeno, 'A' grade from dual union
9 select 1, 101, 'B' from dual union
10 select 1, 101, 'E' from dual
11 )
12 --
13 -- actual query:
14 --
15 select employeeid
16 , employeeno
17 , grade
18 from t1
19 minus
20 select employeeid
21 , employeeno
22 , grade
23 from t2;
EMPLOYEEID EMPLOYEENO G
1 101 D
1 row selected. -
I want sql query for this output
hi guys
could u tell how can i write sql query for this out put
i have one table like this
ID ACCOUTID TAX
1 1 A
2 1 B
3 2 C
4 2 D
5 3 E
7 NULL F
8 NULL G
MY OUT PUT MUST BE LIKE THIS
ID AID TAX
2 1 A
4 2 D
7 NULL F
8 NULL G
HERE IN THIS OUTPUT I SHOULD HAVE
MAXIMAM ID VALUE FOR A REPEATED AID VALUES
AND
THE ROWS AID VALUES IS NULL ALSO MUST PAPULATED IN THE OUTPUT.
I KNOW ONE SOLUTION LIKE THIS
SELECT MAX(ID),AID,TAX
FROM TABLE T
GROUP BY AID,TAX
UNION ALL
SELECT ID, AIC,TAX
FROM TABLE T
WHERE AID IS NULL;
BUT I WANT SAME RESULT WITH OUT USING LOGICAL OPERATORS.
COULD U PLZ TELL A SOL.Will this help:
SQL> with t as
2 (
3 select 1 ID, 1 ACCOUTID, 'A' TAX from dual union all
4 select 2, 1, 'B' from dual union all
5 select 3, 2, 'C' from dual union all
6 select 4, 2, 'D' from dual union all
7 select 5, 3, 'E' from dual union all
8 select 7, NULL, 'F' from dual union all
9 select 8, NULL, 'G' from dual
10 )
11 --
12 select id, ACCOUTID AID, Tax
13 from
14 (
15 select t.*
16 ,count(1) over (partition by t.ACCOUTID) cn
17 ,row_number() over (partition by t.ACCOUTID order by id desc) rn
18 from t
19 )
20 where cn > 1
21 and (rn = 1 or ACCOUTID is null)
22 /
ID AID T
2 1 B
4 2 D
8 G
7 F
-- If I leave out the OR condition then you'll get this:
SQL> ed
Wrote file afiedt.buf
1 with t as
2 (
3 select 1 ID, 1 ACCOUTID, 'A' TAX from dual union all
4 select 2, 1, 'B' from dual union all
5 select 3, 2, 'C' from dual union all
6 select 4, 2, 'D' from dual union all
7 select 5, 3, 'E' from dual union all
8 select 7, NULL, 'F' from dual union all
9 select 8, NULL, 'G' from dual
10 )
11 --
12 select id, ACCOUTID AID, Tax
13 from
14 (
15 select t.*
16 ,count(1) over (partition by t.ACCOUTID) cn
17 ,row_number() over (partition by t.ACCOUTID order by id desc) rn
18 from t
19 )
20 where cn > 1
21* and rn = 1
SQL> /
ID AID T
2 1 B
4 2 D
8 G
--which follows the description you've given, but not the output -
Query for Getting previous date in oracle in specifc scenario
I have the below data in a table A which i need to insert into table B along with one compute column.
TABLE A:
Account_No | Balance | As_on_date
1001 |-100 | 1-Jan-2013
1001 |-150 | 2-Jan-2013
1001 | 200 | 3-Jan-2013
1001 |-250 | 4-Jan-2013
1001 |-300 | 5-Jan-2013
1001 |-310 | 6-Jan-2013
Table B:
In table B,there should be no of days to be shown when balance is negative and the date one which it has gone into negative.
So,for 6-Jan-2013,this table should show below data:
Account_No | Balance | As_on_date | Days_passed | Start_date
1001 | -310 | 6-Jan-2013 | 3 | 4-Jan-2013
Here,no of days should be the days when the balance has gone negative in recent time and not from the old entry.
I need to write a sql query to get the no of days passed and the start date from when the balance has gone negative.
I tried to formulate a query using Lag analytical function,but i am not getting how should i check the first instance of negative balance by traversing back using LAG function. Even the first_value function was given a try but not getting how to partition in it based on negative value.
Any help or direction on this will be really helpful.
ThanksI think you can apply the Tabibitoshan method here. The query is more complex but performs better than other methods. For an explanation, see Tabibitosan method tutorial by Aketi Jyuuzou
The idea behind the method is to identify "continuous" records without gaps. Here I identify records that are "continuous" because they contain an uninterrupted series of negative balances.
drop table t;
CREATE TABLE t (Account_No , Balance , As_on_date) AS SELECT
1001 ,-100 , to_date('1-Jan-13', 'DD-MON-YY') FROM dual UNION ALL SELECT
1001 ,-150 , to_date('2-Jan-13', 'DD-MON-YY') FROM dual UNION ALL SELECT
1001 , 200 , to_date('3-Jan-13', 'DD-MON-YY') FROM dual UNION ALL SELECT
1001 ,-250 , to_date('4-Jan-13', 'DD-MON-YY') FROM dual UNION ALL SELECT
1001 ,-300 , to_date('5-Jan-13', 'DD-MON-YY') FROM dual UNION ALL SELECT
1001 ,-310 , to_date('6-Jan-13', 'DD-MON-YY') FROM dual;
SELECT Account_No, Balance, to_char(As_on_date, 'DD-MON-YYYY') as_on_date,
CASE
WHEN balance < 0
THEN row_number() OVER(PARTITION BY account_no, grp ORDER BY as_on_date)
END days_passed,
CASE
WHEN balance < 0
THEN to_char(
first_value(as_on_date) OVER(PARTITION BY account_no, grp ORDER BY as_on_date),
'DD-MON-YYYY'
end start_date
from (
SELECT Account_No, Balance, As_on_date,
CASE WHEN balance >= 0 THEN NULL ELSE
row_number() OVER(PARTITION BY account_no ORDER BY as_on_date) -
sum(CASE WHEN balance < 0 THEN 1 ELSE 0 END) OVER(PARTITION BY account_no ORDER BY as_on_date)
end grp
FROM t
order by account_no, As_on_date;
ACCOUNT_NO
BALANCE
AS_ON_DATE
DAYS_PASSED
START_DATE
1001
-100
01-JAN-2013
1
01-JAN-2013
1001
-150
02-JAN-2013
2
01-JAN-2013
1001
200
03-JAN-2013
1001
-250
04-JAN-2013
1
04-JAN-2013
1001
-300
05-JAN-2013
2
04-JAN-2013
1001
-310
06-JAN-2013
3
04-JAN-2013 -
SQL query to get the without SCCM agent for a Server
Hello every one,
Can I get the SQL query for a server without a SCCM agent .Here you go!!
Add the version for windows 2012 server if you have them as well in your environment
v_R_System.Netbios_Name0
,v_R_System.Full_Domain_Name0
,v_R_System.User_Name0
,case
When v_R_System.Operating_System_Name_and0 LIKE N'%Server 6.1'THEN 'Windows Server 2008 R2'
When v_R_System.Operating_System_Name_and0 LIKE N'%Server 6.0'THEN 'Windows Server 2008'
When v_R_System.Operating_System_Name_and0 LIKE N'%Server 5.2'THEN 'Windows Server 2003 R2'
ELSE 'Unknown Version' END AS 'OS version'
FROM
v_R_System
WHERE
v_R_System.Operating_System_Name_and0 LIKE N'%server%' and v_R_System.Client0 is null
Kindly mark as answer/Vote as helpful if a reply from anybody helped you in this forum. Delphin -
SQL query to get DDL for Adding PK.
Guys,
I'm looking for SQL query that gets me the "ALTER TABLE <TABLE_NAME> ADD CONSTRAINT <constraint_name> PRIMARY KEY (X,Y,...);" statments of all tables in my schema containing Primary Keys.
Could someone help me with the query please?
Regards,
BhagatYou need this
SELECT 'ALTER TABLE '||table_name||' ADD CONSTRAINT '||constraint_name||' PRIMARY KEY ('||column_name||');'
FROM ( SELECT uc.table_name
,uc.constraint_name
,RTRIM (XMLAGG (XMLELEMENT (ucc, column_name || ',')).extract ('//text()'), ',') column_name
FROM user_constraints uc
,user_cons_columns ucc
WHERE uc.constraint_type = 'P'
AND uc.constraint_name = ucc.constraint_name
GROUP BY uc.table_name
,uc.constraint_name
ORDER BY table_name; Regards
Arun -
Why does Oracle SQL query returning a date field without the time component
Hi,
I'm a novice SQL user & hv just installed Oracle SQL developer (Version 3.0.04, Build MAIN-04.34).
I made the same SQL query using "Oracle SQL developer" & "TOAD for Oracle 9.0.1" but I got 2 different format on the same date field:
On TOAD, I get the date field extracted as *04/26/2011 23:12:58*
On Oracle, I get the date field extracted as *26/APR/11*
Why is the Oracle result in a different format & missing the time component?
Is there any option/preference that I need to set in Oracle SQL developer to get the full date/time format displayed?
I've tried to set my the date format to DD/MON/RR HH12:MI:SSXFF AM under the preference -> database NLS but I still get the same format!
Plse help!hokim wrote:
Hi,
I'm a novice SQL user & hv just installed Oracle SQL developer (Version 3.0.04, Build MAIN-04.34).
I made the same SQL query using "Oracle SQL developer" & "TOAD for Oracle 9.0.1" but I got 2 different format on the same date field:
On TOAD, I get the date field extracted as *04/26/2011 23:12:58*
On Oracle, I get the date field extracted as *26/APR/11*
Why is the Oracle result in a different format & missing the time component?
Is there any option/preference that I need to set in Oracle SQL developer to get the full date/time format displayed?
I've tried to set my the date format to DD/MON/RR HH12:MI:SSXFF AM under the preference -> database NLS but I still get the same format!
Plse help!http://edstevensdba.wordpress.com/category/nls_date_format/
Maybe you are looking for
-
User Exits or BADI for Tcode ME51N
Hi All, My requirement is i need to check available quantity at the time of Purchase req creation. If PR quantity is available in stock then it should not allow to create new PR. Is there any user exit or Badi for this requirement. Kindly send me. Re
-
Is there anything I can do about MS Powerpoint regularly crashing since upgrading to Lion? I am using Office for Mac 2008. Is there any benefit from upgrading to OfM 2011, which also seems to have had lots of problems from what I've heard?
-
How to convert 2 or more Excel files as tables in One Application
Hi I have created one application according to apex demo using excel spreedsheet in which copying data is converted to table then when run application form and reports are produced. Now i created file in a similar way but it is taking only one sheet
-
Anytime I perform an action, iWeb dies and produces error log for apple..... this is on save, publish... whatever! Any reason for this? System: iMac 2.66 Intel C2D OS X v. 10.8.2 iWeb 08 Log: (sorry for the size) Process: iWeb [2109] Path:
-
Can't connect iPod Touch to Airport Extreme using "Add Wireless Clients"
I am unable to connect my iPod Touch to the local wireless network (Airport Utility v5.4.2) using "Add Wireless Clients..." in the Base Station menu. My Powerbook G4 connects OK (with the PIN - as requested) I can find no information in Apple's manua