Pls help me in select query......
My problem is...
I have to use a select query in such a manner that i can compare the last 8 characters or ignore the first one...
Hi Aarif,
Try this :
parameters :
p_field1(30) type c.
Data :
w_string(8) type c,
w_firstchar type c,
t_itab ......,
fs_itab like line of itab.
w_string = p_field1+22(8) " passing last 8 chars into w_string
w_firstchar = p_field1+0(1).
select *
from DataTab Name
into table IntTab Name
where <field name> eq w_string
or <field name> ne w_firstchar.
If you are accepting the value from user then first pass the last 8 characters into w_string and in your select query get the fields where the value is equal to w_string. And pass the first character into another field and to ignore write NE W_FIRSTCHAR.
There can be other methods also. This is one of the ways.
Regards,
Swapna.
Edited by: NagaSwapna Thota on Jul 19, 2008 9:23 AM
Similar Messages
-
Need some help with the Select query.
Need some help with the Select query.
I had created a Z table with the following fields :
ZADS :
MANDT
VKORG
ABGRU.
I had written a select query as below :
select single vkorg abgru from ZADS into it_rej.
IT_REJ is a Work area:
DATA : BEGIN OF IT_REJ,
VKORG TYPE VBAK-VKORG,
ABGRU TYPE VBAP-ABGRU,
END OF IT_REJ.
This is causing performance issue. They are asking me to include the where condition for this select query.
What should be my select query here?
Please suggest....
Any suggestion will be apprecaiated!
Regards,
DeveloperHello Everybody!
Thank you for all your response!
I had changes this work area into Internal table and changed the select query. PLease let me know if this causes any performance issues?
I had created a Z table with the following fields :
ZADS :
MANDT
VKORG
ABGRU.
I had written a select query as below :
I had removed the select single and insted of using the Structure it_rej, I had changed it into Internal table
select vkorg abgru from ZADS into it_rej.
Earlier :
IT_REJ is a Work area:
DATA : BEGIN OF IT_REJ,
VKORG TYPE VBAK-VKORG,
ABGRU TYPE VBAP-ABGRU,
END OF IT_REJ.
Now :
DATA : BEGIN OF IT_REJ occurs 0,
VKORG TYPE VBAK-VKORG,
ABGRU TYPE VBAP-ABGRU,
END OF IT_REJ.
I guess this will fix the issue correct?
PLease suggest!
Regards,
Developer. -
Hi, Please help on the Select Join query. I want to compare code_stat_system1/code_stat_system2 and code_date_system1 /code_date_system2 column from table #system1 and #system2 but there is 2 rule to get correct row from table #system1 and #system2.
Rule 1: We need to get max(code_date_system1) record from #system1 for every code_system1 for compare.
Rule 1: We need to get max(code_date_system2) record from #system2 BUT BEFORE THE RECORD OF 'DKNOW' OF code_stat_system2 for every code_system2 for compare.
drop table #system1,#system2
create table #system1
(Code_system1 varchar(10),code_stat_system1 varchar(10),code_date_system1 datetime)
Insert into #system1 values ('10','Dead','2013-01-01')
Insert into #system1 values ('10','Dead','2013-12-30')
Insert into #system1 values ('10','UnOpen','2014-10-01')
Insert into #system1 values ('10','Open','2014-11-01') --This record should max(code_stat_system1) for compare
Insert into #system1 values ('20','Dead','2013-12-01')
Insert into #system1 values ('20','Dead','2013-12-30')
Insert into #system1 values ('20','Open','2014-08-01')
Insert into #system1 values ('20','UnOpen','2014-09-01') --This record should max(code_stat_system1) for compare
create table #system2
(Code_system2 varchar(10),code_stat_system2 varchar(10),code_date_system2 datetime)
Insert into #system2 values ('10','Dead','2013-01-01')
Insert into #system2 values ('10','Dead','2013-12-30')
Insert into #system2 values ('10','Open','2014-10-01')
Insert into #system2 values ('10','UnOpen','2014-12-01') --This record should max(code_stat_system2) which is before 'DKNOW' for compare
Insert into #system2 values ('10','DKNOW','2015-01-01')
Insert into #system2 values ('10','DKNOW','2015-02-01')
Insert into #system2 values ('20','Dead','2013-12-01')
Insert into #system2 values ('20','Dead','2013-12-30')
Insert into #system2 values ('20','Open','2014-08-01')
Insert into #system2 values ('20','UnOpen','2014-09-01') --This record should max(code_stat_system2) which is before 'DKNOW' for compare
Insert into #system2 values ('20','DKNOW','2015-01-01')
Insert into #system2 values ('20','DKNOW','2015-02-01')
--Desired Output
Code_system1 code_stat_system1 code_date_system1 Code_system1 code_stat_system2 code_date_system1 Rrmk_code_stat Rrmk_code_date
10 Open 2014-11-01 10 UnOpen
2014-12-01 Codes not matching Dates not matching
20 UnOpen 2014-09-01 20 UnOpen
2014-09-01 Codes matching Dates matching
Thanks.drop table #system1,#system2
create table #system1
(Code_system1 varchar(10),code_stat_system1 varchar(10),code_date_system1 datetime)
Insert into #system1 values ('10','Dead','2013-01-01')
Insert into #system1 values ('10','Dead','2013-12-30')
Insert into #system1 values ('10','UnOpen','2014-10-01')
Insert into #system1 values ('10','Open','2014-11-01') --This record should max(code_stat_system1) for compare
Insert into #system1 values ('20','Dead','2013-12-01')
Insert into #system1 values ('20','Dead','2013-12-30')
Insert into #system1 values ('20','Open','2014-08-01')
Insert into #system1 values ('20','UnOpen','2014-09-01') --This record should max(code_stat_system1) for compare
create table #system2
(Code_system2 varchar(10),code_stat_system2 varchar(10),code_date_system2 datetime)
Insert into #system2 values ('10','Dead','2013-01-01')
Insert into #system2 values ('10','Dead','2013-12-30')
Insert into #system2 values ('10','Open','2014-10-01')
Insert into #system2 values ('10','UnOpen','2014-12-01') --This record should max(code_stat_system2) which is before 'DKNOW' for compare
Insert into #system2 values ('10','DKNOW','2015-01-01')
Insert into #system2 values ('10','DKNOW','2015-02-01')
Insert into #system2 values ('20','Dead','2013-12-01')
Insert into #system2 values ('20','Dead','2013-12-30')
Insert into #system2 values ('20','Open','2014-08-01')
Insert into #system2 values ('20','UnOpen','2014-09-01') --This record should max(code_stat_system2) which is before 'DKNOW' for compare
Insert into #system2 values ('20','DKNOW','2015-01-01')
Insert into #system2 values ('20','DKNOW','2015-02-01')
;with mycte1 as (select * ,row_number() Over (partition by Code_system1 Order by code_date_system1 Desc ) rn from #system1)
,mycte2 as (select *,row_number() Over (partition by Code_system2 Order by code_date_system2 Desc ) rn2 from #system2
where code_stat_system2<>'DKNOW')
Select m1.Code_system1, m1.code_stat_system1, m1.code_date_system1, Code_system2, code_stat_system2,code_date_system2 ,
case When code_date_system1=code_date_system2 then 'Dates matching' else 'Dates not matching' End as checkDate,
case When code_stat_system1=code_stat_system2 then 'Codes matching' else 'Codes not matching' End as checkStat
from mycte1 m1 inner join mycte2 m2 on m1.Code_system1= m2.Code_system2 and m1.rn=m2.rn2
Where m1.rn=1 -
I need help with a SELECT query - help!
Hello, I need help with a select statement.
I have a table with 2 fields as shown below
Name | Type
John | 1
John | 2
John | 3
Paul | 1
Paul | 2
Paul | 3
Mark | 1
Mark | 2
I need a query that returns everything where the name has type 1 or 2 but not type 3. So in the example above the qery should bring back all the "Mark" records.
Thanks,
IanOr, if the types are sequential from 1 upwards you could simply do:-
SQL> create table t as
2 select 'John' as name, 1 as type from dual union
3 select 'John',2 from dual union
4 select 'John',3 from dual union
5 select 'Paul',1 from dual union
6 select 'Paul',2 from dual union
7 select 'Paul',3 from dual union
8 select 'Paul',4 from dual union
9 select 'Mark',1 from dual union
10 select 'Mark',2 from dual;
Table created.
SQL> select name
2 from t
3 group by name
4 having count(*) <= 2;
NAME
Mark
SQL>Or another alternative if they aren't sequential:
SQL> ed
Wrote file afiedt.buf
1 select name from (
2 select name, max(type) t
3 from t
4 group by name
5 )
6* where t < 3
SQL> /
NAME
Mark
SQL>Message was edited by:
blushadow -
hi All,
I have one requirement.I wonder whether i can do it in a single SQL Statement or not.
I have tab1 with columns c1,c2,c3,c4,....,Logon_time
I have tab2 with columns C1,c2,c3,c4.....,Logoff_time
All the columns are same for two tables except that logon_time and logoff_time as mentioned above.
tab1 will have all the information of user who logon to database.
tab2 will have all the information of user who logoff from DB.
Now i i have to generate a report which shows all the user info and logon Duration.For that i can use logoff_time - logon_time.but the challenge here is logoff_time dont contain rows for the users who logon to database byt yet to logoff.
So for them logoff_time-logon_time showing -ve Duration.
So I want Duration as logoff_time-logon_time for all the rows.But for those users who yet to logoff i want duration as "YET to Logoff"
Is this possible with single Select Query.
Thanks
PramodHi, Pramod,
You need to join tab_1 to tab_2. Since not every row in tab_1 will have a matching row in tab_2, make it an outer join.
How do you know which row in tab_1 matches which row in tab_2?
I assume there's some column (let's say c1) that identifies a user. A user can have several sessions going at the same time, however.
The following query matches the n-th logon_time in tab_1 with the n-th logoff_time in tab_2 for the same user:
WITH numbered_tab_1 AS
SELECT c1, c2, c3, c4, ..., logon_time
, ROW_NUMBER () OVER ( PARTITION BY c1 -- or whatever identifies user
ORDER BY logon_time
) AS r_num
FROM tab_1
, numbered_tab_2 AS
SELECT c1, c2, c3, c4, ..., logon_time
, ROW_NUMBER () OVER ( PARTITION BY c1 -- or whatever identifies user
ORDER BY logoff_time
) AS r_num
FROM tab_2
SELECT t1.c1, t1.c2, t1.c3, t1.c4, ..., t1.logon_time -- or whatever you want
, t2.c1, t2.c2, t2.c3, t2.c4, ..., t2.logoff_time
, NVL ( TO_CHAR (24 * (t2.logff_time - t1.logon_time)) -- duration in hours
, 'Yet to Logoff'
) AS duration
FROM numbered_tab_1 t1
LEFT OUTER JOIN numbered_tab_2 t2 ON t1.c1 = t2.c1
AND t1.r_num = t2.r_num
;I can test this if you'll post some sample data and the results you want from that data.
The query above matches logons and logoffs only by user and time
For example, say I log on at 10:00.
At 10:45, I open another window and log on again, but log off at 10:50 after 5 minutes.
At 11:30 I log off the first session.
If you were interested in sessions that lasted over 1 hour, the query above would not be accurate. It would show one session starting at 10:00 and ending at 10:50, and another session starting at 10:45 and ending at 11:30. To know that the first session to end was the second sessiion in order of beginning, you would have to have another column, say a unique session id.
If you're only interested in the number of sessions, or the total time connected per user, then the query above will be good enough.
Edited by: Frank Kulash on Jul 6, 2009 12:07 PM -
Pls help : How To select fields and data from user_table for each tablename
Please help with the query to generate a output which selects the code,meaning,inuse for each table in the user_table that has "CODED" as a part of table name.
User table has some 800 table that contains CODED in the tablename.
Desc of the table:
DESCPTION:
Name Null? Type
SHORT_NAME NOT NULL VARCHAR2(20)
CODE NOT NULL VARCHAR2(4)
MEANING NOT NULL VARCHAR2(240)
IN_USE VARCHAR2(1)
NOTES VARCHAR2(2000
UNITS NOT NULL VARCHAR2(1)
AMOUNT NOT NULL VARCHAR2(3)
CONVERTED VARCHAR2(1)
RUN_NAME VARCHAR2(30)
But all the table have code, meaning,in_use fields.
O/P format :
TABLE_NAME CODE MEANING IN_USE
Help me pls.Not 100% sure what you want. If you want to see all the tables that have all three of those columns, then you could do something like:
SELECT table_name, 'CODE', 'MEANING', 'IN_USE'
FROM user_tab_columns
WHERE column_name = 'CODE' and
table_name like '%CODED%'
INTERSECT
SELECT table_name, 'CODE', 'MEANING', 'IN_USE'
FROM user_tab_columns
WHERE column_name = 'MEANING' and
table_name like '%CODED%'
INTERSECT
SELECT table_name, 'CODE', 'MEANING', 'IN_USE'
FROM user_tab_columns
WHERE column_name = 'INUSE' and
table_name like '%CODED%'If you want to select those three columns from each of the tables, then you could do something like this.
Create a command file called, for example, makesel.sql that looks like:
SET PAGES 0 lines 500 trimspool on feedback off;
spool sel.sql;
prompt spool selout.txt;
SELECT 'SELECT '''||table_name||''', code, meaning, in_use FROM '||
table_name||';'
FROM (SELECT table_name
FROM user_tab_columns
WHERE column_name = 'CODE' and
table_name like '%CODED%'
INTERSECT
SELECT table_name
FROM user_tab_columns
WHERE column_name = 'MEANING' and
table_name like '%CODED%'
INTERSECT
SELECT table_name
FROM user_tab_columns
WHERE column_name = 'INUSE' and
table_name like '%CODED%')
prompt 'spool off;'
spool off;
@sel.sqlAt the sqlplus prompt run the file using @makesel.sql. This will create another file called sel.sql containing the commands to select those three columns from each table that has all three columns, then after the new file is created, it runs the file (@sel.sql). The output will be spooled to a file called selout.txt.
HTH
John -
Hello,
Oracle:Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
OS: Windows XP SP-3
create table dws(coll_cd varchar2(6),tot float,dtcd varchar2(2),distname varchar2(20),schtype varchar2(1),year varchar2(4));
insert into dws values('01001',103,'01','DIST1','1','2008');
insert into dws values('01001',23,'01','DIST1','1','2007');
insert into dws values('01115',39,'02','DIST2','2','2008');
insert into dws values('01715',39,'02','DIST2','1','2007');
insert into dws values('01415',120,'02','DIST2','2','2008');
insert into dws values('01749',200,'01','DIST1','1','2006');
insert into dws values('01449',200,'01','DIST1','2','2006');
Year column will contain only 2006,2007 and 2008 and only 1,2 in schtype column.
Output required: (Count of records as per year and schtype group by dtcd)
2008 2007 2006
DTCD DISTNAME TYPE1 TYPE2 TOTAL TYPE1 TYPE2 TOTAL TYPE1 TYPE2 TOTAL
01 DIST1 1 0 1 1 0 1 1 1 2
02 DIST2 0 2 2 1 0 1 0 0 0I tried by following:
select dtcd,
sum(case when(year='2008' and schtype='1') then 1 else 0 end) A,
sum(case when(year='2008' and schtype='2') then 1 else 0 end) B,
sum(case when(year='2007' and schtype='1') then 1 else 0 end) C,
sum(case when(year='2007' and schtype='2') then 1 else 0 end) D,
sum(case when(year='2006' and schtype='1') then 1 else 0 end) E,
sum(case when(year='2006' and schtype='2') then 1 else 0 end) F
from dws group by dtcd,govtpvtn order by 1
but it is not which i want.
Please help me how to write the query to get the required output.
Thanks & Regards
Girish Sharma
Edited by: Girish Sharma on Dec 22, 2008 10:28 PMThere could be several ways to frame this query. One of the ways could be as follows:
SELECT
DTCD,
DISTNAME,
(SELECT COUNT(1) FROM DWS B WHERE A.DTCD = B.DTCD AND A.DISTNAME = B.DISTNAME AND B.YEAR = '2008' AND B.SCHTYPE = '1') TYPE1_2008,
(SELECT COUNT(1) FROM DWS B WHERE A.DTCD = B.DTCD AND A.DISTNAME = B.DISTNAME AND B.YEAR = '2008' AND B.SCHTYPE = '2') TYPE1_2008,
(SELECT COUNT(1) FROM DWS B WHERE A.DTCD = B.DTCD AND A.DISTNAME = B.DISTNAME AND B.YEAR = '2008') TOTAL_2008,
(SELECT COUNT(1) FROM DWS B WHERE A.DTCD = B.DTCD AND A.DISTNAME = B.DISTNAME AND B.YEAR = '2007' AND B.SCHTYPE = '1') TYPE1_2007,
(SELECT COUNT(1) FROM DWS B WHERE A.DTCD = B.DTCD AND A.DISTNAME = B.DISTNAME AND B.YEAR = '2007' AND B.SCHTYPE = '2') TYPE1_2007,
(SELECT COUNT(1) FROM DWS B WHERE A.DTCD = B.DTCD AND A.DISTNAME = B.DISTNAME AND B.YEAR = '2007') TOTAL_2007 ,
(SELECT COUNT(1) FROM DWS B WHERE A.DTCD = B.DTCD AND A.DISTNAME = B.DISTNAME AND B.YEAR = '2006' AND B.SCHTYPE = '1') TYPE1_2006,
(SELECT COUNT(1) FROM DWS B WHERE A.DTCD = B.DTCD AND A.DISTNAME = B.DISTNAME AND B.YEAR = '2006' AND B.SCHTYPE = '2') TYPE1_2006,
(SELECT COUNT(1) FROM DWS B WHERE A.DTCD = B.DTCD AND A.DISTNAME = B.DISTNAME AND B.YEAR = '2006') TOTAL_2006
FROM
DWS A
GROUP BY DTCD, DISTNAME
DT DISTNAME TYPE1_2008 TYPE1_2008 TOTAL_2008 TYPE1_2007 TYPE1_2007 TOTAL_2007 TYPE1_2006 TYPE1_2006 TOTAL_2006
01 DIST1 1 0 1 1 0 1 1 1 2
02 DIST2 0 2 2 1 0 1 0 0 0 -
Need help for SQL SELECT query to fetch XML records from Oracle tables having CLOB field
Hello,
I have a scenario wherein i need to fetch records from several oracle tables having CLOB fields(which is holding XML) and then merge them logically to form a hierarchy XML. All these tables are related with PK-FK relationship. This XML hierarchy is having 'OP' as top-most root node and ‘DE’ as it’s bottom-most node with One-To-Many relationship. Hence, Each OP can have multiple GM, Each GM can have multiple DM and so on.
Table structures are mentioned below:
OP:
Name Null Type
OP_NBR NOT NULL NUMBER(4) (Primary Key)
OP_DESC VARCHAR2(50)
OP_PAYLOD_XML CLOB
GM:
Name Null Type
GM_NBR NOT NULL NUMBER(4) (Primary Key)
GM_DESC VARCHAR2(40)
OP_NBR NOT NULL NUMBER(4) (Foreign Key)
GM_PAYLOD_XML CLOB
DM:
Name Null Type
DM_NBR NOT NULL NUMBER(4) (Primary Key)
DM_DESC VARCHAR2(40)
GM_NBR NOT NULL NUMBER(4) (Foreign Key)
DM_PAYLOD_XML CLOB
DE:
Name Null Type
DE_NBR NOT NULL NUMBER(4) (Primary Key)
DE_DESC NOT NULL VARCHAR2(40)
DM_NBR NOT NULL NUMBER(4) (Foreign Key)
DE_PAYLOD_XML CLOB
+++++++++++++++++++++++++++++++++++++++++++++++++++++
SELECT
j.op_nbr||'||'||j.op_desc||'||'||j.op_paylod_xml AS op_paylod_xml,
i.gm_nbr||'||'||i.gm_desc||'||'||i.gm_paylod_xml AS gm_paylod_xml,
h.dm_nbr||'||'||h.dm_desc||'||'||h.dm_paylod_xml AS dm_paylod_xml,
g.de_nbr||'||'||g.de_desc||'||'||g.de_paylod_xml AS de_paylod_xml,
FROM
DE g, DM h, GM i, OP j
WHERE
h.dm_nbr = g.dm_nbr(+) and
i.gm_nbr = h.gm_nbr(+) and
j.op_nbr = i.op_nbr(+)
+++++++++++++++++++++++++++++++++++++++++++++++++++++
I am using above SQL select statement for fetching the XML records and this gives me all related xmls for each entity in a single record(OP, GM, DM. DE). Output of this SQL query is as below:
Current O/P:
<resultSet>
<Record1>
<OP_PAYLOD_XML1>
<GM_PAYLOD_XML1>
<DM_PAYLOD_XML1>
<DE_PAYLOD_XML1>
</Record1>
<Record2>
<OP_PAYLOD_XML2>
<GM_PAYLOD_XML2>
<DM_PAYLOD_XML2>
<DE_PAYLOD_XML2>
</Record2>
<RecordN>
<OP_PAYLOD_XMLN>
<GM_PAYLOD_XMLN>
<DM_PAYLOD_XMLN>
<DE_PAYLOD_XMLN>
</RecordN>
</resultSet>
Now i want to change my SQL query so that i get following output structure:
<resultSet>
<Record>
<OP_PAYLOD_XML1>
<GM_PAYLOD_XML1>
<GM_PAYLOD_XML2> .......
<GM_PAYLOD_XMLN>
<DM_PAYLOD_XML1>
<DM_PAYLOD_XML2> .......
<DM_PAYLOD_XMLN>
<DE_PAYLOD_XML1>
<DE_PAYLOD_XML2> .......
<DE_PAYLOD_XMLN>
</Record>
<Record>
<OP_PAYLOD_XML2>
<GM_PAYLOD_XML1'>
<GM_PAYLOD_XML2'> .......
<GM_PAYLOD_XMLN'>
<DM_PAYLOD_XML1'>
<DM_PAYLOD_XML2'> .......
<DM_PAYLOD_XMLN'>
<DE_PAYLOD_XML1'>
<DE_PAYLOD_XML2'> .......
<DE_PAYLOD_XMLN'>
</Record>
<resultSet>
Appreciate your help in this regard!Hi,
A few questions :
How's your first query supposed to give you an XML output like you show ?
Is there something you're not telling us?
What's the content of, for example, <OP_PAYLOD_XML1> ?
I don't think it's a good idea to embed the node level in the tag name, it would make much sense to expose that as an attribute.
What's the db version BTW? -
Hi,
I need to select the max time for the transaction using the below query. I’m able to get the o/p. Here the problem is I need to fetch the corrletorid (primary key) as well. if try to get that I’m getting the o/p like case2.
I want the o/p to be like case 1 with the corrleator id . plz help me to get the o/p.
Case 1: select b.TransactionName, max(to_char(b.duration, 'mm/dd/yyyy hh24:mi:ss.ff')) as average from trandetails a,subtrandetails b where a.CORRELATORID=b.PCORRELATORID and b.PCORRELATORID='11' group by b.transactionname
TRANSACTIONNAME MAXTIME
FINT3 12/10/2007 19:53:09.042000
FINT 12/10/2007 19:31:07.042000
FINT2 12/10/2007 19:31:07.042000
SQL> /
Case 2: select b.TransactionName,b.correlatorid, max(to_char(b.duration, 'mm/dd/yyyy hh24:mi:ss.ff')) as average from trandetails a,subtrandetails b where a.CORRELATORID=b.PCORRELATORID and b.PCORRELATORID='11' group by b.transactionname,b.correlatorid
SQL> /
TRANSACTIONNAME CORRELATORID AVERAGE
FINT2 102 12/10/2007 19:31:07.042000
FINT3 108 12/10/2007 19:53:09.042000
FINT3 103 12/10/2007 19:31:07.042000
FINT 101 12/10/2007 19:31:07.042000
in the above output i should have only record(max time) for FINT3.
ThankSharma,
Please find the below sample data(insert stmt and create table):
======================================
create table trandetails(
correlatorid varchar2(20) CONSTRAINT correlatorid_FKey REFERENCES Subtrandetails(correlatorid),
username varchar2(25) NOT NULL,
applicationname varchar2(25) NOT NULL,CONSTRAINT composite1_pkey1 PRIMARY KEY(correlatorid ,applicationname));
create table Subtrandetails(
correlatorid varchar2(20) PRIMARY KEY,
PCORRELATORID varchar2(20),
TransactionName varchar2(25) NOT NULL,
Machinename varchar2(15) NOT NULL,
STARTDATE timestamp NOT NULL,
ENDDATE timestamp NOT NULL,
SourceName varchar2(25),
FunctionName varchar2(25),
LOC number(5),
CONTEXTPROPERTY1 varchar2(25),
CONTEXTPROPERTY2 varchar2(25),
CONTEXTPROPERTY3 varchar2(25),
TransactionStatus varchar2(25) NOT NULL CONSTRAINT Transaction1_Status_chk Check (TransactionStatus in ('Success', 'Failure', 'Abort')));
INSERT INTO trandetails VALUES ('11','FINAPP','ANUAPP1');
INSERT INTO trandetails VALUES ('13','FINTEST','ANUAPP2');
INSERT INTO
Subtrandetails(correlatorid,PCORRELATORID ,TransactionName,Machinename,STARTDATE,ENDDATE ,TransactionStatus )
VALUES ('10','1','ARM','blrkec95931d','10-DEC-07 03.24.07.042000 PM','10-DEC-07 03.31.07.042000 PM','Success');
INSERT INTO
Subtrandetails(correlatorid,PCORRELATORID ,TransactionName,Machinename,STARTDATE,ENDDATE ,TransactionStatus )
VALUES ('11','1','ARM1','blrkec95931d','10-DEC-07 04.24.07.042000 PM','10-DEC-07 04.31.07.042000 PM','Success');
INSERT INTO
Subtrandetails(correlatorid,PCORRELATORID ,TransactionName,Machinename,STARTDATE,ENDDATE ,TransactionStatus )
VALUES ('12','1','ARM2','blrkec95931d','10-DEC-07 05.24.07.042000 PM','10-DEC-07 05.31.07.042000 PM','Success');
INSERT INTO
Subtrandetails(correlatorid,PCORRELATORID ,TransactionName,Machinename,STARTDATE,ENDDATE ,TransactionStatus )
VALUES ('13','1','ARM3','blrkec95931d','10-DEC-07 06.24.07.042000 PM','10-DEC-07 06.31.07.042000 PM','Success');
INSERT INTO
Subtrandetails(correlatorid,PCORRELATORID ,TransactionName,Machinename,STARTDATE,ENDDATE ,TransactionStatus )
VALUES ('14','1','ARM4','blrkec95931d','10-DEC-07 07.24.07.042000 PM','10-DEC-07 07.31.07.042000 PM','Success');
INSERT INTO
Subtrandetails(correlatorid,PCORRELATORID ,TransactionName,Machinename,STARTDATE,ENDDATE ,TransactionStatus )
VALUES ('101','11','FINT','blrkec95931d','10-DEC-07 07.24.07.042000 PM','10-DEC-07 07.31.07.042000 PM','Success');
INSERT INTO
Subtrandetails(correlatorid,PCORRELATORID ,TransactionName,Machinename,STARTDATE,ENDDATE ,TransactionStatus )
VALUES ('102','11','FINT2','blrkec95931d','10-DEC-07 07.24.07.042000 PM','10-DEC-07 07.31.07.042000 PM','Success');
INSERT INTO
Subtrandetails(correlatorid,PCORRELATORID ,TransactionName,Machinename,STARTDATE,ENDDATE ,TransactionStatus )
VALUES ('103','11','FINT3','blrkec95931d','10-DEC-07 07.24.07.042000 PM','10-DEC-07 07.31.07.042000 PM','Success');
INSERT INTO
Subtrandetails(correlatorid,PCORRELATORID ,TransactionName,Machinename,STARTDATE,ENDDATE ,TransactionStatus )
VALUES ('104','13','SAP1','blrkec95931d','10-DEC-07 07.24.07.042000 PM','10-DEC-07 07.31.07.042000 PM','Success');
INSERT INTO
Subtrandetails(correlatorid,PCORRELATORID,TransactionName,Machinename,STARTDATE,ENDDATE ,TransactionStatus )
VALUES ('105','13','SAP2','blrkec95931d','10-DEC-07 07.24.07.042000 PM','10-DEC-07 07.31.07.042000 PM','Success');
INSERT INTO
Subtrandetails(correlatorid,PCORRELATORID ,TransactionName,Machinename,STARTDATE,ENDDATE ,TransactionStatus )
VALUES ('106','13','SAP3','blrkec95931d','10-DEC-07 07.24.07.042000 PM','10-DEC-07 07.31.07.042000 PM','Success');
INSERT INTO
Subtrandetails(correlatorid,PCORRELATORID ,TransactionName,Machinename,STARTDATE,ENDDATE ,TransactionStatus )
VALUES ('107','13','SAP2','blrkec95931d','10-DEC-07 07.2.10.042350 PM','10-DEC-07 07.50.10.042050 PM','Success');
INSERT INTO
Subtrandetails(correlatorid,PCORRELATORID ,TransactionName,Machinename,STARTDATE,ENDDATE ,TransactionStatus )
VALUES ('108','11',' FINT3 ','blrkec95931d','10-DEC-07 07.16.07.042000 PM','10-DEC-07 07.53.09.042000 PM','Success');
INSERT INTO
Subtrandetails(correlatorid,PCORRELATORID ,TransactionName,Machinename,STARTDATE,ENDDATE ,TransactionStatus )
VALUES ('109','108','FINT3','blrkec95931d','10-DEC-07 07.20.07.042000 PM','10-DEC-07 07.59.09.042000 PM','Success');
INSERT INTO
Subtrandetails(correlatorid,PCORRELATORID ,TransactionName,Machinename,STARTDATE,ENDDATE ,TransactionStatus )
VALUES ('110','108','FINT3','blrkec95931d','10-DEC-07 07.18.07.042000 PM','10-DEC-07 07.57.09.042000 PM','Success');
INSERT INTO
Subtrandetails(correlatorid,PCORRELATORID ,TransactionName,Machinename,STARTDATE,ENDDATE ,TransactionStatus )
VALUES ('111','108','FINT4','blrkec95931d','10-DEC-07 07.18.07.042000 PM','10-DEC-07 07.57.09.042000 PM','Success');
INSERT INTO
Subtrandetails(correlatorid,PCORRELATORID ,TransactionName,Machinename,STARTDATE,ENDDATE ,TransactionStatus )
VALUES ('112','108','FINT5','blrkec95931d','10-DEC-07 07.18.07.042000 PM','10-DEC-07 07.57.09.042000 PM','Success');
INSERT INTO
Subtrandetails(correlatorid,PCORRELATORID ,TransactionName,Machinename,STARTDATE,ENDDATE ,TransactionStatus )
VALUES ('113','108','FINT6','blrkec95931d','10-DEC-07 07.18.07.042000 PM','10-DEC-07 07.57.09.042000 PM','Success');
INSERT INTO
Subtrandetails(correlatorid,PCORRELATORID ,TransactionName,Machinename,STARTDATE,ENDDATE ,TransactionStatus )
VALUES ('114','108','FINT7','blrkec95931d','10-DEC-07 07.18.07.042000 PM','10-DEC-07 07.57.09.042000 PM','Success');
======================================
Thanks. -
Here is my code , i dont have any experience with writing the nested sql , i got the below code , which needs to be modified adding a case statement which will show util_rate for 2 conditions
1. given in where condition ( to_char(time_stamp,'HH24') >= '09' and to_char(time_stamp,'HH24') <= '19')
2.Apposite to the condition above (to_char(time_stamp,'HH24') < '09'and to_char(time_stamp,'HH24') > '19')
could anybody please help me in adding the 2nd condition to the below query , please share any documentation you have for learning how to write nested sql,
Thank you
select device,time_stamp,
sum(ActiveHRS)/sum(AvailHRS) as RATE
from
select device,time_stamp,
case when usage >0 then 1
else 0 end as ActiveHRS,
'1' as AvailHRS
from
select device,time_stamp,
sum(case
when state = 9 then 0
when state = 0 then 0
else 1 end) as usage
from A
where to_char(time_stamp,'HH24') >= '09'
and to_char(time_stamp,'HH24') <= '19'
and to_char(time_stamp, 'D') in (2,3,4,5,6)
group by device, time_stamp
group by device,time_stampHere is the DDL :
desc rumi_all
Name Null Type
RUMI_DEVICE VARCHAR2(20)
STATE NUMBER(38)
TIME_STAMP DATE
LOCATION VARCHAR2(50) Here is some sample data :
RUMI_DEVICE STATE TIME_STAMP LOCATION
10.45.28.86 0 15-JUN-10 WA-102
10.45.28.51 0 15-JUN-10 WA-102
10.45.28.63 0 15-JUN-10 WA-102
10.45.29.47 9 15-JUN-10 WA-120I used the below query to get the util for the hours 9am - 7pm
select rumi_device,time_stamp,
sum(ActiveHRS)/sum(AvailHRS) as RATE
from
select rumi_device,time_stamp,
case when usage >0 then 1
else 0 end as ActiveHRS,
'1' as AvailHRS
from
select rumi_device,time_stamp,
sum(case
when state = 9 then 0
when state = 0 then 0
else 1 end) as usage
from rumi_all
where to_char(time_stamp,'HH24') >= '09'
and to_char(time_stamp,'HH24') <= '19'
and to_char(time_stamp, 'D') in (2,3,4,5,6)
group by rumi_device, time_stamp
group by rumi_device,time_stamp
Acquired Out for the above query :
RUMI_DEVICE TIME_STAMP UTIL_RATE
10.45.29.47 15-JUN-10 0.234
10.45.28.63 15-JUN-10 0.123
10.45.29.47 15-JUN-10 0.987
10.45.29.47 16-JUN-10 0.23Desired output :I want 2 extra columns which shows util rate for the above condition i.e 9am - 7pm(core hours) and also opposite to that condition after 7pm - before 9am(say, non core hours)
Desired out put :
RUMI_DEVICE TIME_STAMP Core_Util_Rate Non_Core_UtilRate
10.45.29.4 15-JUN-10 0.234 0.003
10.45.28.63 15-JUN-10 0.123 0.001
10.45.29.47 15-JUN-10 0.987 0.023
10.45.29.47 16-JUN-10 0.23 0Hope this helps in answering my question , and also could you please share some document to learn writing nested sql's , i always had tough time in understanding this :-( -
Help reagrding the selection query
Hi All...
I have VBELN
LFART
VKORG
KUNNR
ERDAT
LFDAT
VSTEL
ROUTE in my selection-screen. All the fields are from LIKP.
Now I need to add one more field LAND1 from the table VBPA in the selection screen.
This is my logic to filter the previous requirement. Now how to validate the LAND1?
-> LIKP
select vbeln
into table i_likp
from likp
where vbeln in s_vbeln
and lfart in s_lfart
and vkorg in s_vkorg
and kunnr in s_kunnr
and erdat in s_erdat
and lfdat in s_lfdat
and vstel = p_vstel
and route in s_route.
if sy-subrc = 0.
-> LIPS
select vbeln posnr bwtar volum
into table i_lips
from lips
for all entries in i_likp
where vbeln = i_likp-vbeln.
Please help me in that. I will reward u with good points.
Reagrds
Arjun JainFor LAND1 validation do as below.
AT SELECTION-SCREEN ON s_land1.
SELECT land1 FROM t005
into t005-land1
where land1 IN s_land1.
if sy-subrc NE 0.
message e000 WITH 'Enter valid Land value'.
endif.
For the query u can use join
select a~vbeln b~posnr b~bwtar b~volum
from likp as a inner join lips as b
on a~vbeln =b~vbeln
into table i_tab
where a~vbeln in s_vbeln
and a~lfart in s_lfart
and a~vkorg in s_vkorg
and a~kunnr in s_kunnr
and a~erdat in s_erdat
and a~lfdat in s_lfdat
and a~vstel = p_vstel
and a~route in s_route.
This will solve ur problem.
U can reward for the helpful answers. -
Help needed in select query to take date
Hello,
I am using Oracle 11g.
I am using this query
select to_date(to_char(to_date((SOURCE_MONTH||'-'||SOURCE_YEAR),'MM-YYYY'),'Mon-YYYY'),'MON-YYYY') date_
from tab1 a,tab2 b
where b.col2=a.col1;
I have a table with 2 separate varchar columns month and year,
I want to insert the data into another table which has the col type as timestamp.
This query gives me the data as
01-NOV-06 but
i want the data as
01-NOV-2006
What should i do for that?
ThanksFirst, get rid of the extra conversions from date to char and back to date:
select to_date((SOURCE_MONTH||'-'||SOURCE_YEAR),'MM-YYYY'),'Mon-YYYY')
from tab1 a,tab2 b
where b.col2=a.col1;Now, your data is safely rendered as a DATE. It knows the full year (i.e.2006). You are just not seeing it formatted the way you like. You could
alter session set nls_date_format = 'mm/dd/yyyy hh24:mi:ss';or give the explicit format you want when you query it (with TO_CHAR).
Please read and understand about DATE datatypes....
http://download.oracle.com/docs/cd/B28359_01/server.111/b28286/sql_elements001.htm#i54330
In particular, search that page for: "DATE Datatype " -
Pls help to rewrite the query in another method .
Insert into bl_voyage_details (BVD_COMPANY,BVD_REFERENCE,BVD_SERIAL,BVD_CARRIER,BVD_VESSEL,BVD_VOY,BVD_LOCATION,BVD_TYPE,BVD_CRT_BY,BVD_CRT_ON,
BVD_UPD_BY,BVD_UPD_ON,BVD_STATUS,BVD_STATUS_DATE,BVD_STATUS_BY )
Values (Select bdl_company,bdl_reference,
*(select nvl(max(bvd_serial),0)+1 from bl_voyage_details)*
,bdl_carrier,bdl_vessel,bdl_voy,bdl_location,bdl_type,user,sysdate,user,'0',sysdate,sysdate from bl_details)
Insert into bl_voyage_details (BVD_COMPANY,BVD_REFERENCE,BVD_SERIAL,BVD_CARRIER,BVD_VESSEL,BVD_VOY,BVD_LOCATION,BVD_TYPE,BVD_CRT_BY,BVD_CRT_ON,
BVD_UPD_BY,BVD_UPD_ON,BVD_STATUS,BVD_STATUS_DATE,BVD_STATUS_BY )
Values (Select bdl_company,bdl_reference,
*(select nvl(max(bvd_serial),0)+1 from bl_voyage_details where (BVD_COMPANY,BVD_REFERENCE)in (bdl_company,bdl_reference)* )
,bdl_carrier,bdl_vessel,bdl_voy,bdl_location,bdl_type,user,sysdate,user,'0',sysdate,sysdate from bl_details)
Edited by: Rinz on Apr 27, 2010 3:57 PM
Edited by: Rinz on Apr 27, 2010 3:57 PMSeems related to your previous question ( Procedure creation )
Is there any reason why you couldn't just use a sequence:
insert into bl_voyage_details
(bvd_company,
bvd_reference,
bvd_serial,
bvd_carrier,
bvd_vessel,
bvd_voy,
bvd_location,
bvd_type,
bvd_crt_by,
bvd_crt_on,
bvd_upd_by,
bvd_upd_on,
bvd_status,
bvd_status_date,
bvd_status_by
select bdl_company,
bdl_reference,
some_sequence.nextval, --<< use a sequence
bdl_carrier,
bdl_vessel,
bdl_voy,
bdl_location,
bdl_type,
user,
sysdate,
user,
sysdate,
'0',
sysdate,
sysdate
from bl_details;Also:
To post formatted code, put the {noformat} {noformat}- tag before and after your examples.
When you post:
{noformat} select *
from dual;
{noformat}
it will appear as: select *
from dual;
on the forum.
The FAQ will tell you more: http://forums.oracle.com/forums/help.jspa -
Hi ,
I have a field(test) in ztable(zxxx) whose length is 12 char and while updating it
only 10 digits were updated and there are no zeros in front of the value in order to make it
12 digit.
Now i need this parameter to be included in another program selection screen.
Now i have given it as
parameter : test(12) type n.
it works fine when it has an entry , when it is blank i has to retrieve all records but in this case
i won't because it has a value of 000000000000
noe when i declare like this
paramter : test like zxxx-test.
when my input is 123456, it won't fetch me any value because it has to be 0000123456 because it has been updated like in the table.
There was a purpose in updating this way.
Now my code is like this
parameters : test(10) type n.
select-options : kostl for zxxx-kostl NO-EXTENSION NO INTERVALS,
p_uname for zxxx-uname NO-EXTENSION NO INTERVALS.
if test is initial.
select * from zxxx into table itab where kostl in kostl and uname in p_uname.
else.
select * from zxxx into table itab where aufnr = order and
kostl in kostl and uname in p_uname.
endif
PLEASE SUGGEST ME IF THERE IS AN ALTERNATE BETTER WAY.
or this is the best way
ThanksHi
as per my knowledge what you have done is right.
Thanks
KAJOL -
Hi Guys,
For example I have 2 tables:
I wish to list out the owner, table_name, total count of chain row of the table, num rows by joining the below 2 tables.
Can advise how can i do it?
Currently i'm doing it by executing this statement but very slow:
select a.owner_name, a.table_name, count(*), b.num_Rows
from system.chained_rows a, dba_tables b
where a.owner_name=b.owner
and a.table_name=b.table_name
and b.num_Rows>0
group by a.owner_name, a.table_name, b.num_Rows
having count(*)*100/b.num_Rows>10;
TABLE INFORMATION:
1. CHAINED_ROWS (one table name can have multiple chain row id records)
column:
1. owner
2. table_name
3. chain row id
2. DBA_TABLES (one table name only one record)
column:
1. owner
2. table_name
3. num_rows
thanksHi,
I think u mis-inteprete my question.
My question is more on how to formulate a sql to get the output i hope so.. and not how to get chain counts.
I wish to list out the owner, table_name, total count of chain row of the table, num rows by joining the below 2 tables.
Can advise how can i do it?
Currently i'm doing it by executing this statement but very slow:
select a.owner_name, a.table_name, count(*), b.num_Rows
from system.chained_rows a, dba_tables b
where a.owner_name=b.owner
and a.table_name=b.table_name
and b.num_Rows>0
group by a.owner_name, a.table_name, b.num_Rows
having count(*)*100/b.num_Rows>10;
TABLE INFORMATION:
1. CHAINED_ROWS (one table name can have multiple chain row id records)
column:
1. owner
2. table_name
3. chain row id
2. DBA_TABLES (one table name only one record)
column:
1. owner
2. table_name
3. num_rows
thanks
Maybe you are looking for
-
Acrobat Help | What's new in Acrobat XI
This question was posted in response to the following article: http://helpx.adobe.com/acrobat/using/whats-new-acrobat-xi.html
-
Hello XI Gurus, Thanks for all the help so far. Right now I am in the process of doing file to jdbc scenario. I am following this link: /people/sap.user72/blog/2005/06/01/file-to-jdbc-adapter-using-sap-xi-30 <b>I am getting the follwoing error i
-
UserID Doesn't exist error message
Hi, SUNONE directory gets synched with Adobe LC directory without any issues but still one of the long lived process gets stalled with the error message "User ID is either inactive or invalid". UserID is still active in the database and also availabl
-
The Oracle Membership Provider would not allow me to set the minRequiredNonAlphanumericCharacters via the web.config. When I tried to set the "minRequiredNonAlphanumericCharacters" property for the Oracle Membership file via web.config, I got the fol
-
Feature Request: Double Clicking should be slowed down for Browsing use.
I have a menu on my website that you need to click some what fast - but when I do a normal double click using Opera, FF, or IE it doesn't highlight the entire menu. When I try in Safari it does. It seems like the other browsers have set the double cl