Need help in SQL strings
Team,
I have a requirement in my project where I need to take out a sub string from the main string and store in other column.
for example,
I have a table with 2 columns and table has more then 500 records.
1st column has the values like follows
'High Pressure 0.5 in'
'Wafer 0.3 in'
'Sanitary 3.0 in'
'8721 Hygienic 1.0 in'
My requirement is, I need to takeout inches part and store in 2nd column.
my 2nd column should contain values like 0.5, 0.3, 0.3, 1.0
Thanks in advance,
Rak
If you always have a decimal point and a fixed length for the inches:
SQL>
SQL> with t as (
2 select 'High Pressure 0.5 in' str from dual union
3 select 'Wafer 0.3 in' from dual union
4 select 'Sanitary 3.0 in' from dual union
5 select '8721 Hygienic 1.0 in' from dual
6 )
7 --
8 --
9 --
10 select str
11 , substr( str
12 , instr(str, '.' ,1 )-1
13 , instr(str, '.' ,1 )-instr(str, '.' ,1 )+3
14 ) inch
15 from t;
STR INCH
8721 Hygienic 1.0 in 1.0
High Pressure 0.5 in 0.5
Sanitary 3.0 in 3.0
Wafer 0.3 in 0.3
4 rows selected.
Similar Messages
-
Need help with SQL Query with Inline View + Group by
Hello Gurus,
I would really appreciate your time and effort regarding this query. I have the following data set.
Reference_No---Check_Number---Check_Date--------Description-------------------------------Invoice_Number----------Invoice_Type---Paid_Amount-----Vendor_Number
1234567----------11223-------------- 7/5/2008----------paid for cleaning----------------------44345563------------------I-----------------*20.00*-------------19
1234567----------11223--------------7/5/2008-----------Adjustment for bad quality---------44345563------------------A-----------------10.00------------19
7654321----------11223--------------7/5/2008-----------Adjustment from last billing cycle-----23543556-------------------A--------------------50.00--------------19
4653456----------11223--------------7/5/2008-----------paid for cleaning------------------------35654765--------------------I---------------------30.00-------------19
Please Ignore '----', added it for clarity
I am trying to write a query to aggregate paid_amount based on Reference_No, Check_Number, Payment_Date, Invoice_Number, Invoice_Type, Vendor_Number and display description with Invoice_type 'I' when there are multiple records with the same Reference_No, Check_Number, Payment_Date, Invoice_Number, Invoice_Type, Vendor_Number. When there are no multiple records I want to display the respective Description.
The query should return the following data set
Reference_No---Check_Number---Check_Date--------Description-------------------------------Invoice_Number----------Invoice_Type---Paid_Amount-----Vendor_Number
1234567----------11223-------------- 7/5/2008----------paid for cleaning----------------------44345563------------------I-----------------*10.00*------------19
7654321----------11223--------------7/5/2008-----------Adjustment from last billing cycle-----23543556-------------------A--------------------50.00--------------19
4653456----------11223--------------7/5/2008-----------paid for cleaning------------------------35654765-------------------I---------------------30.00--------------19
The following is my query. I am kind of lost.
select B.Description, A.sequence_id,A.check_date, A.check_number, A.invoice_number, A.amount, A.vendor_number
from (
select sequence_id,check_date, check_number, invoice_number, sum(paid_amount) amount, vendor_number
from INVOICE
group by sequence_id,check_date, check_number, invoice_number, vendor_number
) A, INVOICE B
where A.sequence_id = B.sequence_id
Thanks,
NickIt looks like it is a duplicate thread - correct me if i'm wrong in this case ->
Need help with SQL Query with Inline View + Group by
Regards.
Satyaki De. -
Need help in SQL (DENSE_RANK) function
Hello All,
I need the help in SQL.
We have a table called status and the column are
status_id number
account_id number
status_cd varchar2(10)
created_id varchar2(10)
created_by date
and data is as follows
insert into status values (1,101,'ENTER','ABC',to_date('21-JAN-2007 11:15:14','DD-MON-YYYY HH:MI:SS'));
insert into status values (2,101,'REVIEW','DEF',to_date('21-JAN-2007 11:30:25','DD-MON-YYYY HH:MI:SS'));
insert into status values (3,101,'APPROVE','GHI',to_date('21-JAN-2007 11:30:25','DD-MON-YYYY HH:MI:SS'));
insert into status values (4,102,'ENTER','ABC',to_date('21-JAN-2007 11:18:14','DD-MON-YYYY HH:MI:SS'));
insert into status values (5,102,'REVIEW','DEF',to_date('21-JAN-2007 11:33:25','DD-MON-YYYY HH:MI:SS'));
insert into status values (6,102,'CANCEL','GHI',to_date('21-JAN-2007 11:33:25','DD-MON-YYYY HH:MI:SS'));
insert into status values (7,103,'ENTER','ABC',to_date('21-JAN-2007 11:21:14','DD-MON-YYYY HH:MI:SS'));We have different status as follows
1. ENTER
2. REVIEW
3. APPROVE
4. CANCEL
5. REJECT
My requirement ..
I need the max of created_id column for the status in ('APPROVE','CANCEL') and if there is no status in ('APPROVE','REVIEW') than it should be NULL.
I wrote an SQL as
select account_id,max(created_id) keep (dense_rank first order by decode(status_cd,'APPROVE',created_dt,'REVIEW',created_dt,NULL) DESC NULLS LAST,
decode(status_cd,'APPROVE',status_id,'REVIEW',status_id,NULL) DESC NULLS LAST) last_app_rev_user
from status
group by account_id and gives me the output like
ACCOUNT_ID LAST_APP_R
101 GHI
102 DEF
103 ABCBut I want the Output like
ACCOUNT_ID LAST_APP_R
101 GHI
102 DEF
103 NULLAs the account 103 has no status called 'REVIEW' and 'APPROVE'
My DB Version in 10.2.0.3.0.
Hope I explain it properly. And if you have any other option without dense_rank still i will be happy.
Thanks in advance for your help.
AB
null
Message was edited by:
ABinstead of max(created_id) keep... use
smth like max(case when status_cd in ('APPROVE','REVIEW') then created_id end) keep... -
NEED HELP IN SQL HOMEWORK PROBLEMS
I NEED HELP IN MY SQL HOMEWORK PROBLEMS....
I CAN SEND IT VIA EMAIL ATTACHMENT IN MSWORD....Try this:
SELECT SUBSTR( TN,
DECODE(LEVEL, 1, 1, INSTR(TN, '#', 1, LEVEL-1) + 1),
DECODE( INSTR(TN, '#', 1, LEVEL) , 0 ,
LENGTH(TN) + 1, INSTR(TN, '#', 1, LEVEL) )
- DECODE(LEVEL, 1, 1, INSTR(TN, '#', 1, LEVEL-1 ) + 1)
) xxx
FROM (
SELECT '234123#1254343#909823#908232#12345' TN FROM DUAL
CONNECT BY LEVEL <= LENGTH(TN) - LENGTH(REPLACE(TN,'#')) + 1
XXX
234123
1254343
909823
908232
12345
SELECT regexp_substr(tn, '[^#]+', 1, level) xx
FROM (
SELECT '234123#1254343#909823#908232#12345' TN FROM DUAL
CONNECT BY LEVEL <= LENGTH(TN) - LENGTH(REPLACE(TN,'#')) + 1
XX
234123
1254343
909823
908232
12345 -
Need help in the String Format method
really need help in string.Format method. I would like to show the s in two digit numbers.
for example:
if s is below 10 then display *0s*
the expecting result is 01,02,03.. 09,10,11....
I tried this method, somehow i got the errors msg. pls advise. thx.
public void setDisplay(String s) {
String tmpSS=String.format("%02d",s);
this.ss.setText(tmpSS);
Edited by: bluesailormoon on May 19, 2008 10:30 AMApparently, you expect the string to consist of one or two digits. If that's true, you could do this:String tmpSS = (s.length() == 1) ? ("0" + s) : s; or this: String tmpSS = String.format("%02d", Integer.parseInt(s));
-
Need help in handling string of characters
Hi,
I am trying to scan string and separate different text based on business logic. For example:
String = 'My bus comes at 999 F Street at 8 am'
Now I need to scan the string and break the sentence into multiple words like:
- First occurrence of number which is 999 goes into var1 variable.
- Last occurrence of number which is 8 goes into var2 variable.
I am wondering if this can be achieve with regular expression of any oracle internal function.
Thanks,
Edited by: skas on Jun 6, 2013 10:34 PMnkvkashyap wrote:
or you can even try like this...
with data(str) as
(select 'My bus comes at 999 F Street at 8 am' from dual),
data1 as
(select regexp_replace(str, '[^[:digit:]]+', ' ') a from data)
select regexp_substr(a,'[^ ]+',1,1) var1,regexp_substr(a,'[^ ]+',1,2) var2 from data1;
Output:
var1 var2
999 8
No need to make this complicated ;)
SQL> with data(str) as
2 (
3 select 'My bus comes at 999 F Street at 8 am'
4 from dual
5 )
6 select regexp_sUBsTR(str, '\d+') VAR1,
7 regexp_sUBSTR(str, '\d+',1,2) VAR2
8 from data;
VAR V
999 8Edited by: jeneesh on Jun 7, 2013 11:11 AM
Missed David's post.. This is the same as his post.. -
Need help pl/sql function body returning SQL query - Reports
I need help with Grouping by on a report that I developed in my application.
I have posted my Code in
Apex.oracle.com
workspace : c a s e _ m a n a g e m e n t
User Id : public
Password : public
I need help on Page 38 Reports.
I get blank lines when I do break by first , second and third columns on the reports attribute.
So I think I have to write "group by " or Distinct in side the SQL query. But not sure how to do it there.
Thank youIs this an APEX question, then try here:
Oracle Application Express (APEX)
Is this an Oracle Reports question, then try here:
Reports
Is this an SQL question:
Please provide sample data and expected output. Also please show what you have tried already. -
I am using Sybase as my back end database. I need help on my SQL statement regarding datetime. The datetime is store as a 9 digit integer in the database (...I believe it is a Decimal(30,6) format, let me know if I am wrong).
If I do this, "select * from mytable;" It works out fine (except I don't know what the date means e.g. 998919534)
If I do this, "select * from mytable where datetime_col < '9/5/2002' ; I got an error. I even tried '9/5/02 11:00 000 am' but it didn't help.
How do I specify a date or datetime in my query?
Thanks in advance.I execute the sql statement
select * from mytable where datetim_col < convert(datetime, '3/4/2002', 101) ;
I got mix result. I got an error message "cannot convert 10375584 to a date.
Yet, he statistics window of the I-sql says
"estimated 493 rows in query (I/O estimate 87)
PLan> mytable (seq)"
It looks like I my the SQL statement is correct and then the system can't display it in the Data window.
Any thought ? -
Hi,
Need help to write sql statement.
create table t_dt ( dt_start date, dt_end date, amount number);
insert into t_dt values('1-Jan-10','10-Feb-10',12);
insert into t_dt values('11-Feb-10','10-Mar-10',10);
insert into t_dt values('11-Mar-10','20-Apr-10',8);
insert into t_dt values('21-Apr-10','28-Jun-10',10);
insert into t_dt values('29-Jun-10','20-Sep-10',10);
insert into t_dt values('21-Sep-10','10-Oct-10',10);
insert into t_dt values('11-Oct-10','31-Dec-10',8);
insert into t_dt values('1-Jan-11','10-Feb-11',8);
insert into t_dt values('11-Feb-11','10-Mar-11',7);
insert into t_dt values('11-Mar-11','20-Apr-11',6);
insert into t_dt values('21-Apr-11','28-Jun-11',6);
insert into t_dt values('29-Jun-11','20-Sep-11',6);
insert into t_dt values('21-Sep-11','10-Oct-11',4);
insert into t_dt values('11-Oct-11','31-Dec-11',8);
Result should be like below..
dt_start dt_end Amount
1-Jan-10 10-Feb-10 12
11-Feb-10 10-Mar-10 10
11-Mar-10 20-Apr-10 8
21-Apr-10 10-Oct-10 10
11-Oct-10 10-Feb-11 8
11-Feb-11 10-Mar-11 7
11-Mar-11 20-Sep-11 6
21-Sep-11 10-Oct-11 4
11-Oct-11 31-Dec-11 8
Just to explain the example, take a row with start date as 21-Apr-10 in the above insert statements, since it has the same amount for next two rows (i.e. with start date '29-Jun-10' and '21-Sep-10') these 3 rows should be converted to represent only 1 row in the result and the start date and end date should be changed per the result shown above.
Thanks.Hello
I think this gives yuo what you need....
SELECT
MIN(dt_start),
MAX(dt_end),
amount
FROM
( SELECT
dt_start,
dt_end,
MAX(marker) OVER(ORDER BY dt_start) marker,
amount
FROM
Select
dt_start,
dt_end,
amount,
CASE
WHEN LAG(amount) OVER(ORDER BY dt_start) <> amount THEN
ROW_NUMBER() OVER(ORDER BY dt_start)
END marker
from t_dt
GROUP BY
amount,
marker
order by
MIN(dt_start)
MIN(DT_START) MAX(DT_END) AMOUNT
01-JAN-2010 00:00:00 10-FEB-2010 00:00:00 12
11-FEB-2010 00:00:00 10-MAR-2010 00:00:00 10
11-MAR-2010 00:00:00 20-APR-2010 00:00:00 8
21-APR-2010 00:00:00 10-OCT-2010 00:00:00 10
11-OCT-2010 00:00:00 10-FEB-2011 00:00:00 8
11-FEB-2011 00:00:00 10-MAR-2011 00:00:00 7
11-MAR-2011 00:00:00 20-SEP-2011 00:00:00 6
21-SEP-2011 00:00:00 10-OCT-2011 00:00:00 4
11-OCT-2011 00:00:00 31-DEC-2011 00:00:00 8
9 rows selected.HTH
David
Edited by: Bravid on Feb 23, 2012 12:08 PM
Beaten to it by Frank! :-) -
Need help on SQL Statement for UDF
Hi,
as I am not so familiar with SQL statements on currently selected values, I urgently need help.
The scenario looks as follows:
I have defined two UDFs named Subgroup1 and Subgroup2 which represent the subgroups dependent on my article groups. So for example: When the user selects article group "pianos", he only sees the specific subgroups like "new pianos" and "used pianos" in field "Subgroup1". After he has selected one of these specific values, he sees only the specific sub-subgroups in field "Subgroup2", like "used grand pianos".
I have defined UDTs for both UDFs. The UDT for field "Subgroup1" has a UDF called "ArticleGroup" which represents the relation to the article group codes. The UDT for field "Subgroup2" has a UDF called "Subgroup1" which represents the relation to the subgroups one level higher.
The SQL statement for the formatted search in field "Subgroup1" looks as follows:
SELECT T0.[Name] FROM [dbo].[@B_SUBGROUP1] T0 WHERE T0.[U_ArticleGroup] = (SELECT $[OITM.ItmsGrpCod])
It works fine.
However, I cannot find the right statement for the formatted search in field "Subgroup2".
Unfortunately this does NOT WORK:
SELECT T0.[Name] FROM [dbo].[@B_SUBGROUP2] T0 WHERE T0.[U_Subgroup1] = (SELECT $[OITM.U_Subgroup1])
I tried a lot of others that didn't work either.
Then I tried the following one:
SELECT T0.[Name] FROM [dbo].[@B_SUBGROUP2] T0 WHERE T0.[U_Subgroup1] = (SELECT T1.[Code] FROM [dbo].[@B_SUBGROUP1] T1 WHERE T1.[U_ArticleGroup] = (SELECT $[OITM.ItmsGrpCod]))
Unfortunately that only works as long as there is only one specific subgroup1 for the selected article group.
I would be sooooo happy if there is anyone who can tell me the correct statement for my second UDF!
Thanks so much in advance!!!!
Edited by: Corinna Hochheim on Jan 18, 2010 10:16 PM
Please ignore the "http://" in the above statements - it is certainly not part of my SQL.
Please also ignore the strikes.Hello Dear,
Use the below queries to get the values:
Item Sub Group on the basis of Item Group
SELECT T0.[Name] FROM [dbo].[@SUBGROUP] T0 WHERE T0.[U_GroupCod] =$[OITM.ItmsGrpCod]
Item Sub Group 1 on the basis of item sub group
SELECT T0.[Name] FROM [dbo].[@SUBGROUP1] T0 WHERE T0.[U_SubGrpCod]=(SELECT T0.[Code] FROM [dbo].[@SUBGROUP] T0 WHERE T0.[Name] =$[OITM.U_ItmsSubgrp])
Sub group 2 on the basis of sub group 1
SELECT T0.[Name] FROM [dbo].[@SUBGROUP2] T0 WHERE T0.[U_SubGrpCod1]=(SELECT T0.[Code] FROM [dbo].[@SUBGROUP1] T0 WHERE T0.[Name] =$[OITM.U_ItmsSubgrp1])
this will help you.
regards,
Neetu -
hii All
I need help for pl/sql function.
I build a function for monthly attendance all employees.
but now i want to show all Sundays with 'S' and others respectively 'P' and 'A'.
Currently Sunday also shows 'A'
So please help
SQL queries ... like
SELECT DISTINCT AL.USERNAME,
CASE WHEN DAY1 =1 THEN 'P' ELSE 'A' END DAY1,
CASE WHEN DAY2 =1 THEN 'P' ELSE 'A' END DAY2,
CASE WHEN DAY3 =1 THEN 'P' ELSE 'A' END DAY3,
CASE WHEN DAY31 =1 THEN 'P' ELSE 'A' END DAY31
FROM
SELECT DISTINCT USERNAME, SUM(CASE WHEN
fromdt=TRUNC(L.LOGIN_DATE) THEN
1
ELSE
0
END) DAY1
,SUM(CASE WHEN
fromdt +1=TRUNC(L.LOGIN_DATE) THEN
1
ELSE
0
END) DAY2,
SUM(CASE WHEN
fromdt+30=TRUNC(L.LOGIN_DATE) THEN
1
ELSE
0
END) DAY31
FROM ( SELECT DISTINCT TRUNC(LOGIN_DATE)LOGIN_DATE ,USERNAME FROM FCDM_AUDIT_TRAIL_NEW WHERE
TRUNC(LOGIN_DATE) BETWEEN fromdt AND todt
-- to_date( login_date, 'dd-mom-yyyy') between to_date( fromdt, 'dd-mom-yyyy') and to_date( todt, 'dd-mom-yyyy')
) L
GROUP BY USERNAME
) AL;
how can i show matched Sundays and show with 'SUN' or 'S'
Regards
vij..Try this way:
SELECT USERNAME,
MAX(CASE WHEN to_char(fromdt,'d')='1' and fromdt=TRUNC(L.LOGIN_DATE) THEN 'S'
WHEN to_char(fromdt,'d')!='1' and fromdt=TRUNC(L.LOGIN_DATE) THEN 'P'
ELSE 'A') DAY1,
MAX(CASE WHEN to_char(fromdt+1,'d')='1' and fromdt+1=TRUNC(L.LOGIN_DATE) THEN 'S'
WHEN to_char(fromdt+1,'d')!='1' and fromdt+1=TRUNC(L.LOGIN_DATE) THEN 'P'
ELSE 'A') DAY2,
MAX(CASE WHEN to_char(fromdt+30,'d')='1' and fromdt+30=TRUNC(L.LOGIN_DATE) THEN 'S'
WHEN to_char(fromdt+30,'d')!='1' and fromdt+30=TRUNC(L.LOGIN_DATE) THEN 'P'
ELSE 'A') DAY31
FROM
(SELECT DISTINCT TRUNC(LOGIN_DATE) LOGIN_DATE,
USERNAME
FROM FCDM_AUDIT_TRAIL_NEW
WHERE TRUNC(LOGIN_DATE) BETWEEN fromdt AND todt
) L
Group by USERNAME
;Max
http://oracleitalia.wordpress.com -
Re: [(forte-users) Need help w/SQL to Informix using anarray in WHERE c
Bob.
That syntax isn't know Forte, used Dynamic SQL and coding
it dynamically. And the SQL statement exceed 255 bytes, divide in 2 or more
sentences (NameListCity1, NameListCity2, NalmeListCountry1, ...)
Try with:
NameListCity = 'city1','city2','city3'...
NalmeListCountry = 'country1','country2','country3',...
WHERE
city in (:NameListCity) and
country_code in (:NameListCountry)
Bye.
"Briggs, Bob" <Bob.Briggsmarriott.com> wrote:
I'm trying to invoke a query to Informix to select rows that match any of
the city / country pairs that exist in an array that is passed into the
method. The SQL itself seems to be OK however it appears that Forte is
having a problem in parsing the Select statement when it gets to the WHERE
clause. The resulting exception shows the SQL string formatted properly up
to the WHERE clause which ends like "WHERE city". Does anyone know of a way
to make this type of query work in a single invocation? I'm trying not to
issue multiple queries as would be the case if I used Dynamic SQL and coding
it dynamically with multiple OR statements is not really an option since the
overall length of the SQL statement cannot exceed 256 bytes. I have included
an example of the code below, any insight would be greatly appreciated.
SQL SELECT address1 tnAddress, city tnCity, state tnState, zipcode
tnZipcode,
hotel_code tnHotel_Code, name tnHotelName, product_code
tnProduct_code, loc_type tnLoc_Type,
phone tnPhone, country_code tnCountry
INTO
:po_aboLocator
FROM
Hotel
WHERE
city in :pi_aboNickNameList[*].sCityName and
country_code in :pi_aboNickNameList[*].sCountryCode
ON SESSION getDBSession();
Thank you very much,
Bob
For the archives, go to: http://lists.xpedior.com/forte-users and use
the login: forte and the password: archive. To unsubscribe, send in a new
email the word: 'Unsubscribe' to: forte-users-requestlists.xpedior.comBob.
That syntax isn't know Forte, used Dynamic SQL and coding
it dynamically. And the SQL statement exceed 255 bytes, divide in 2 or more
sentences (NameListCity1, NameListCity2, NalmeListCountry1, ...)
Try with:
NameListCity = 'city1','city2','city3'...
NalmeListCountry = 'country1','country2','country3',...
WHERE
city in (:NameListCity) and
country_code in (:NameListCountry)
Bye.
"Briggs, Bob" <Bob.Briggsmarriott.com> wrote:
I'm trying to invoke a query to Informix to select rows that match any of
the city / country pairs that exist in an array that is passed into the
method. The SQL itself seems to be OK however it appears that Forte is
having a problem in parsing the Select statement when it gets to the WHERE
clause. The resulting exception shows the SQL string formatted properly up
to the WHERE clause which ends like "WHERE city". Does anyone know of a way
to make this type of query work in a single invocation? I'm trying not to
issue multiple queries as would be the case if I used Dynamic SQL and coding
it dynamically with multiple OR statements is not really an option since the
overall length of the SQL statement cannot exceed 256 bytes. I have included
an example of the code below, any insight would be greatly appreciated.
SQL SELECT address1 tnAddress, city tnCity, state tnState, zipcode
tnZipcode,
hotel_code tnHotel_Code, name tnHotelName, product_code
tnProduct_code, loc_type tnLoc_Type,
phone tnPhone, country_code tnCountry
INTO
:po_aboLocator
FROM
Hotel
WHERE
city in :pi_aboNickNameList[*].sCityName and
country_code in :pi_aboNickNameList[*].sCountryCode
ON SESSION getDBSession();
Thank you very much,
Bob
For the archives, go to: http://lists.xpedior.com/forte-users and use
the login: forte and the password: archive. To unsubscribe, send in a new
email the word: 'Unsubscribe' to: forte-users-requestlists.xpedior.com -
Need help with SQL retrieval for previous month till current date
Hi ,
Need help generating statistics from previous month from date of enquiry till current date of enquiry.
and have to display it according to date.
Date of enquiry : 03/02/2012
Application Type| 01/01/2012 | 02/01/2012 | 03/01/2012 |...... | 31/01/2012 | 01/02/2012 | 02/02/2012 | 03/02/2012 |
sample1 20 30 40
sample 2 40 40 50
sample 3 50 30 30
Hope you guys can help me with this.
RegardsHi,
932472 wrote:
Scenario
1)If i run the query at 12 pm on 03/2/2012. the result i will have to display till the current day.
2)displaying the count of the application made based on the date.
Application type 01012012 | 02012012 | 03012012 | ..... 01022012| 02022012|03022012
sample 1 30 40 50 44 30
sample 2 35 45 55
sample 3 36 45 55Explain how you get those results from the sample data you posted.
It would help a lot if you posted the results in \ tags, as described in the forum FAQ. {message{id=9360002}
SELECT application_type as Application_type
, COUNT (CASE WHEN created_dt = sysdate-3 THEN 1 END) AS 01012012 (should be getting dynamically)
, COUNT (CASE WHEN created_dt = sysdate-4 THEN 1 END) AS 02022012
, COUNT (CASE WHEN created_dt = sysdate-5 THEN 1 END) AS 03022012
, COUNT (CASE WHEN created_dt = sysdate-6 THEN 1 END) AS 04022012
FROM table_1
GROUP BY application_type
ORDER BY application_typeThat's the bais idea.
You can simplify it a little by factoring out the date differences:WITH got_d AS
SELECT qty
, TRUNC ( dt
- ADD_MONTHS ( TRUNC (SYSDATE, 'MON')
, -1
) AS d
FROM table1
WHERE dt >= ADD_MONTHS ( TRUNC (SYSDATE, 'MON')
, -1
AND dt < TRUNC (SYSDATE) + 1
SELECT SUM (CASE WHEN d = 1 THEN qty END) AS day_1
, SUM (CASE WHEN d = 2 THEN qty END) AS day_2
, SUM (CASE WHEN d = 62 THEN qty END) AS day_62
FROM got_d
See the links I mentioned earlier for getting exactly the right number of columns, and dynamic column aliases. -
Needed help regarding converting string to java.sql.Date format
I have a a function which returns a calendar object. The date must be inserted to Oracle DB using java.sql.Date format.
So i have converted the Calendar object to java.sql.Date format using the following code
java.sql.Date publicationDate = new java.sql.Date(book.getPublicationDate().getTime().getTime());But while getting inserted into the DB it was in mm/dd/yyyy format whereas i wanted dd/mm/yyyy format
Can any body please help out how to store the date in dd/mm/yyyy format ?Can u please explain this a bit
This is my code
public int addBook(List<Book> BookList) throws SQLException, ParseException{
System.out.println("Hi there");
Book book = new Book();
BookDB bookDb = new BookDB();
//listLength = BookList.length;
String bookId = null;
try{
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
con = DriverManager.getConnection("jdbc:oracle:thin:@10.123.79.195:1521:findb01","e115314", "e115314");
addBook = con.prepareStatement("insert into ABC_Book values(?,?,?,?,?,?,?)");
Iterator<Book> iterator = BookList.iterator();
while(iterator.hasNext()){
book = (Book)iterator.next();
System.out.println(book.getBookId());
addBook.setString(1,book.getBookId());
addBook.setString(2,book.getTitle());
addBook.setString(3,book.getAuthor());
addBook.setString(4,book.getPublisher());
System.out.println(book.getPublicationDate());
System.out.println("Before Date");
System.out.println("book.getPublicationDate().getTime()"+book.getPublicationDate().getTime());
java.sql.Date publicationDate = new java.sql.Date(book.getPublicationDate().getTime().getTime());
SimpleDateFormat formatter = new SimpleDateFormat("dd/mm/yyyy");
dateString = formatter.format(publicationDate);
System.out.println("Today is"+dateString);
java.sql.Date date = (java.sql.Date)formatter.parse(dateString);
System.out.println("date"+date);
//java.sql.Date publicationDate = (Date)book.getPublicationDate().getTime();
//System.out.println("Value of date is"+publicationDate);
System.out.println("After Date");
addBook.setDate(5,publicationDate);
addBook.setString(6,book.getCountry());
addBook.setString(7,book.getLanguage());
rs = addBook.executeQuery();
//con.commit();
rowCount = rowCount + rs.getRow();
return rowCount;
catch(SQLException se){
se.printStackTrace();
finally{
con.close();
System.out.println("After adding ");
return 0;
} -
Hi,
I have a table with named as cust_pkg_tbl and data contains as below.scrcdall column contain comma separated strings.
id name memstatus mobileno srccdall
1001 kaushik 8 9876549032 cde1,cde2,cde3
1002 ram 4 8845670982 cde1,cde2
1003 raj 2 8823578432 cde1,cde2,cde3,cde4
1004 kumar 8 9630987654 cde1,cde2
Based on the above data client wants to insert as 3/4/2 separate records into the side/lookup table(src_cde_pkg_tbl) as below.
client wants the data looks like in the below table as src_cde_pkg_tbl.
id srt_num srccdall
1001 1 cde1
1001 2 cde2
1001 3 cde3
1002 1 cde1
1002 2 cde2
1003 1 cde1
1003 2 cde2
1003 3 cde3
1003 4 cde4
1004 1 cde1
1004 2 cde2
could you please help me to achieve the requirement.
thx in advanceYou've posted enough times to know you need to provide your 4 digit Oracle version.
>
Based on the above data client wants to insert as 3/4/2 separate records into the side/lookup table(src_cde_pkg_tbl) as below.
>
That similar question has been answered many times on the forum.
See the faq about converting rows to columns
SQL and PL/SQL FAQ
And search the forum for columns to rows.
Maybe you are looking for
-
Error while log in to amconsole
please tell a solution of the following error while log in to amconsole A serious error has occured in the Desktop. This may have been caused by a mis-configuration on the server. Please report this problem to your administrator. Possible cause: * Yo
-
Hi All, We are using Oracle 11g R2 and we would like to implement Virtual Private Database. We have an application connected to LDAP with serveral users. The users are also created in Weblogic. The Application is using only with Oracle schema with ma
-
Iphoto to photoshop cs6? Picture is distorted
I am trying to edit a photo in photoshop cs6 from iphoto. When I bring the photo into photoshop the picture is distorted and looks like a collage of parts of my picture. I also see that gray and checked background. I don't know what's happening
-
Hi I am not getting GUI Title Bar in SAP screen and my SAP screen also looking differently as a white back ground. Please help me where these setting available? Regards sudha
-
How to turn off ticking tempo on garage band?
Hello, I am new to garage band. I want to hear my music but I cannot hear because there is a ticking sound and I cannot hear the song good because of it? Can someone please let me know how to tr it off. Where do I go to silence that tempo tick?