SQL query clarification
Hi,
I have a table called inst_hst contains
institution_id modifiedate_time institution_status_code
3316 1/7/2009 AP
3316 9/13/2009 RE
3316 1/28/2010 SB
here i want to get the last modified date time record for example... the latest record here is
3316 1/28/2010 SB should be return... i dont want to retrieve other institution id...
can anyone please give me the query to retrieve the above value
user572087 wrote:
Hi,
Thanks for your reply.. But i have more than one institution id like this... for example
3316 1/1/2001 SB
3316 1/2/2001 RE
3316 1/3/2001 AP
3317 1/1/2001 SB
3317 1/2/2001 RE
3318 1/3/2001 AP
3318 1/4/2001 SB
Hi,
In your sample data code 'AP' and 'RE' has two records with same date. so the result will look like this.
PRAZY@solarc> with T as
2 (
3 select 3316 institution_id, '1/1/2001' modifiedate_time, 'SB' institution_status_code From dual
4 UNION
5 select 3316, '1/2/2001', 'RE' From dual
6 UNION
7 select 3316, '1/3/2001', 'AP' From dual
8 UNION
9 select 3317, '1/1/2001', 'SB' From dual
10 UNION
11 select 3317, '1/2/2001', 'RE' From dual
12 UNION
13 select 3318, '1/3/2001', 'AP' From dual
14 UNION
15 select 3318, '1/4/2001', 'SB' From dual
16 )
17 select *
18 from (select t1.*, Dense_rank() over
19 (partition by institution_status_code order by modifiedate_time Desc) NewRow from T t1)
20 where NewRow=1;
INSTITUTION_ID MODIFIED IN NEWROW
3316 1/3/2001 AP 1
3318 1/3/2001 AP 1
3316 1/2/2001 RE 1
3317 1/2/2001 RE 1
3318 1/4/2001 SB 1
Elapsed: 00:00:00.00or
IF you just want to retrieve 1st record alone you can go with row_number instead of dense_rank
PRAZY@solarc> with T as
2 (
3 select 3316 institution_id, '1/1/2001' modifiedate_time, 'SB' institution_status_code From dual
4 UNION
5 select 3316, '1/2/2001', 'RE' From dual
6 UNION
7 select 3316, '1/3/2001', 'AP' From dual
8 UNION
9 select 3317, '1/1/2001', 'SB' From dual
10 UNION
11 select 3317, '1/2/2001', 'RE' From dual
12 UNION
13 select 3318, '1/3/2001', 'AP' From dual
14 UNION
15 select 3318, '1/4/2001', 'SB' From dual
16 )
17 select *
18 from (select t1.*, row_number() over
19 (partition by institution_status_code order by modifiedate_time Desc) NewRow from T t1)
20 where NewRow=1;
INSTITUTION_ID MODIFIED IN NEWROW
3316 1/3/2001 AP 1
3316 1/2/2001 RE 1
3318 1/4/2001 SB 1or
Partition using institution_id if you want the result based on ID
PRAZY@solarc> with T as
2 (
3 select 3316 institution_id, '1/1/2001' modifiedate_time, 'SB' institution_status_code From dual
4 UNION
5 select 3316, '1/2/2001', 'RE' From dual
6 UNION
7 select 3316, '1/3/2001', 'AP' From dual
8 UNION
9 select 3317, '1/1/2001', 'SB' From dual
10 UNION
11 select 3317, '1/2/2001', 'RE' From dual
12 UNION
13 select 3318, '1/3/2001', 'AP' From dual
14 UNION
15 select 3318, '1/4/2001', 'SB' From dual
16 )
17 select *
18 from (select t1.*, row_number() over
19 (partition by institution_id order by modifiedate_time Desc) NewRow from T t1)
20 where NewRow=1
21 /
INSTITUTION_ID MODIFIED IN NEWROW
3316 1/3/2001 AP 1
3317 1/2/2001 RE 1
3318 1/4/2001 SB 1Regards,
Prazy
Similar Messages
-
Clarification on using function in where clause of oracle sql query
I have an issue in regarding function using where clause of sql query..
We are facing performance issue while executing query, so in what ways to improve the performance of the query which i have posted below.
select col ,case when my_function(parameter)
from tab1 a ,tab2 b,tabl3 c
where a.column1=b.column2
and b.column3 =c.column6
and my_function(parameter)>0
Regards
Dinesh
Edited by: wild fire on May 18, 2012 4:15 PMDinesh,
remind that when you use a function in the where clause it normally will get started for each record in the table.
So your answer is two-fold:
1. make the function only start when needed by adding a function based index on the table (this will make inserts and updates slower)
2. make the function faster by adding the DETERMINISTIC clause if possible. this will make Oracle "cache" the result of the function.
Regards,
Richard
blog: http://blog.warp11.nl
twitter: @rhjmartens
If this question is answered, please mark the thread as closed and assign points where earned.. -
Help needed in framing SQL query.
Hi,
I have table having following schema:
PRODUCT_ID INT
DATE DATETIME
ITEMS_SOLD INT
This table contains data for a week (sunday to saturday). I want to write an SQL query to get (filter out) PRODUCT_ID of products which has same no. of ITEMS_SOLD for all 7 days. Also for given PRODUCT_ID I need to find the longest period of successive days where the no. of ITEMS_SOLD is same for all days in this period. Eg.(PRODUCT_ID 23 was sold as following along the week in no. of units sold: 4,6,6,6,6,7,4 .So the longest period is *4 days* from Monday to Thursday.) The first condition is special case of second condition where no. of days is 7.
Any help to get the SQL query will be appreciated.
Thanks,
Akshay.PRODUCT_ID DATE ITEMS_SOLD
1 10/10/2011 3
1 11/10/2011 3
1 12/10/2011 3
1 13/10/2011 3
1 16/10/2011 5
2 10/10/2011 4
2 11/10/2011 4
2 12/10/2011 4
2 13/10/2011 4
2 14/10/2011 4
2 15/10/2011 4
2 16/10/2011 4
Output:
PRODUCT_ID ITEMS_SOLD NO_OF_DAYS
1 3 4
2 4 7
Explanation of results:
The table to be queried contains data for 1 week: from 10/10/2011(Sunday) to 16/10/2011(Saturday). Now, product with PRODUCT_ID '1' was sold on dates 10,11,12,13,16. Out of these 5 days 3 units were sold on 4 successive days (from 10-13). So output should be like :
PRODUCT_ID ITEMS_SOLD NO_OF_DAYS
1 3 4
as longest period of successive days is 4 where same no. of units were sold i.e 3 units (other period is of 1 day on 16th ).
For PRODUCT_ID 2 we have only one period of 7 days where 4 units were sold each day. So we output :
PRODUCT_ID ITEMS_SOLD NO_OF_DAYS
2 4 7
Other case where same PRODUCT_ID have different units sold on each day should be ignored.
I hope that clarifies the problem more. Let me know in case I have missed out anything which should have been mentioned.
-Akshay. -
Hello All,
I have one problem regarding sql query.
I have one internal table which contains equnr and bis as fields. There are two database tables egerr and eastl. The structure for tables are as follows:
Fields for egerr:
equnr, bis, logiknr in which first two fields form key.
Field for eastl:
anlage, bis, logiknr in which all fields form primary key.
I want to select records from internal table which does not have record in eastl.
For the reference we can extract logiknr from egerr by using intarnal table and then use this logiknr to check entry in table eastl. but i want those equnr which are in internal table but not mapped in eastl.
I want the most efficient solution for this as there are many records.
Thanks..... and if you have any queries then let me know.
Jignesh.hi,
as per ur statement, u want the field equnr which exists in the internal table but not in eastl. now for comparing with eastl u will need to check for all the three fields as they form the key...
get data from egerr for matching equnr and bis in your internal table
i.e. assuming ur table is itab and itab_logiknr contains a single field logiknr
select logiknr from egerr
into table itab_logiknr
for all entries in itab
where equnr eq itab-equnr
and bis eq itab-bis.
now from this data (itab_egerr), compare the data with that in eastl for matching (or non matching) values of logiknr
assuming data from eastl lies in itab_eastl
select anlage bis logiknr from eastl into itab_eastl
for all entries in itab_logiknr
where logiknr eq itab_logiknr-logiknr.
for non matching entries u can select data from eastl which is not present in itab_eastl now....
(but mind you....since all fields of eastl form the key, u might not be getting the correct data) so if possible study ur scenario again and see if u can search the eastl table comparing all fields in the primary key)
try this....get back in case of any clarifications
hope it gives u some pointers...
regards,
PJ -
Simplify SQL query - need suggestions
Hi,
I have a table "Product" in my Database , which i am using to create reports in OBIEE. The table has five cols : ID, Version, Date, ItemName, ItemRate . It is partitioned on Date col . The table has many rows and I want to hit Date partition to improve performance.I take Date as input from user by Date Prompt.
The primary key is ID+Version+ItemName
I want to get a table which contains Date, ItemName,ItemRate, ID for each ID with max(Version). This table I will join with another table in Oracle BI Answers to generate reports. If an ID has many versions, I get max version value and then return ID,ItemName,ItemRate,Date corresponding to that Verion value.
What is the best way to achieve this, should I define view in my physical layer which contains sql query for simplified table so that it will make my task of generating reports easier by having asimplified table in Oracle BI Answers ? ?
Please ask if any clarification is needed ....
ThanksThere are couple of ways to handle your requirements. Try this:
When table is partitioned we have to use fragmentation option using LTS->Proparties->Content tab specify the condition at
Fragmentation content:
and
Check 'This source should...'
For Max(version): Use repository variable for getting max(version) and filter using Where clause option in Content tab.
Let me know updates -
How to modify a SQL query?
Hi all,
I am using Crystal Reports version 10. I have a number of reports that have been written by a software vendor wherby the name of the database they were connected to when the report was written is coded into the FROM command of the reports SQL query, eg "GCUK_2" in the of the SQL snippet below.
SELECT "Clients"."NAME", "Quotes"."QUOTE_ID", "Quote_Items"."UPRICE", "Quote_Items"."QTY", "Quote_Items"."UOM", "Quote_Items"."QUSAGE_ID", "Report_Control"."QUSAGEID", "Quote_Items"."STANDARD", "Quote_Items"."SECT_FLAG", "Quote_Items"."DISPORDER", "Quotes"."DESCRIPT", "Report_Control"."SECT_NAME", "Quote_Items"."CNT", "Category_and_Type"."TYPEDESC", "Quote_Items"."DESCRIPT", "Report_Control"."DISP_SORT"
FROM ((("GCUK_2"."schedwin"."QTE_CTRL" "Report_Control" INNER JOIN "GCUK_2"."schedwin"."QUSAGE" "Quote_Items" ON "Report_Control"."QUSAGEID"="Quote_Items"."QUSAGE_ID") LEFT OUTER JOIN "GCUK_2"."schedwin"."QUOTES" "Quotes" ON
I have tried setting the Datasource Location, but it doesn't change the query at all. I have read on another forum that you can generate another SQL query using the Database Expert, Current Connections, then right click the Add Command for the database you want to create a SQL command. Is this the only way to update the database names in the query?
Thanks,
Scott.Hi Sourashree,
Thanks for that. All the reports were created by the vendor using tables as opposed to the command object. I would have thought that changing the datasource would automatically cause Crystal to rewrite the SQL query syntax, but this doesn't appear to be the case.
Yes, I've noticed that modifying the record selection will change the sql query. The only way I can see to change the database name in the query is to change to the desired databsource and then remove and re-insert the tables, which will then update the query with the correct name. However, this seems to be a convoluted way of changing the db name in the query. -
Discoverer Report showing Null VS Show SQL query showing results !!!
I created a simple Cross Tab Discoverer report from a custom SQL which has a calculation for balances. The output is giving all null values even though there are balances. The output doesn't seem right. So I copied the query from Tools-->Show SQL and ran the query in the TOAD where I'm showing balances for the report. I don't understand why it is not showing in the discoverer. Please help.
Thanks
Edited by: PA1B on Jan 27, 2010 11:40 AMSorry for late reply.
Below is the Show SQL query. I don't think the query is application dependent. C_1 is my calculation.
SELECT o279709.SEGMENT3 as E279727,
o279709.SEGMENT4 as E279728,
CASE WHEN o279709.CURRENCY_CODE = 'USD' AND o279709.TRANSLATED_FLAG <> 'Y' THEN SUM(o279709.ENDING_BAL) ELSE 0 END as C_1,
GROUPING_ID(o279709.CURRENCY_CODE,o279709.SEGMENT3,o279709.SEGMENT4,o279709.TRANSLATED_FLAG) as GID
FROM ( --Foriegn Entity USD Balances
SELECT B.SEGMENT1,
B.SEGMENT2,
B.SEGMENT3,
(select distinct substr(cat.COMPILED_VALUE_ATTRIBUTES,5,1) from apps.fnd_flex_values cat
where FLEX_VALUE_SET_ID = (select bat.FLEX_VALUE_SET_ID from apps.fnd_id_flex_structures_vl aat, apps.fnd_id_flex_segments_vl bat
where bat.id_flex_code = 'GL#' and
bat.id_flex_code = aat.id_flex_code and
aat.APPLICATION_ID = bat.APPLICATION_ID and
aat.APPLICATION_ID = 101 and
bat.SEGMENT_NAME = 'Prime Account' and
aat.id_flex_num = bat.id_flex_num
and bat.id_flex_num in (select distinct chart_of_accounts_id from apps.gl_code_combinations gat
where gat.code_combination_id = A.code_combination_id))
and cat.flex_value = b.segment3) ACCT_TYPE ,
B.SEGMENT4,
B.SEGMENT5,
B.SEGMENT6,
B.SEGMENT7,
B.SEGMENT8,
B.SEGMENT9,
B.SEGMENT10,
B.SEGMENT11,
B.SEGMENT12,
B.SEGMENT13,
C.NAME,
A.SET_OF_BOOKS_ID,
A.CURRENCY_CODE,A.TRANSLATED_FLAG,
SUM(NVL(A.BEGIN_BALANCE_DR,0) - NVL(A.BEGIN_BALANCE_CR,0)) BEG_BAL,
SUM(NVL(A.PERIOD_NET_DR,0)) DEBITS,
SUM( NVL(A.PERIOD_NET_CR,0)) CREDITS ,
A.PERIOD_NAME,
SUM(NVL(A.BEGIN_BALANCE_DR,0) - NVL(A.BEGIN_BALANCE_CR,0))+ SUM(NVL(A.PERIOD_NET_DR,0) - NVL(A.PERIOD_NET_CR,0)) ENDING_BAL
FROM APPS.GL_BALANCES A ,
APPS.GL_CODE_COMBINATIONS B,
APPS.GL_SETS_OF_BOOKS C
WHERE A.CODE_COMBINATION_ID = B.CODE_COMBINATION_ID
--AND A.PERIOD_NAME = 'SEP-09'
AND C.SET_OF_BOOKS_ID = A.SET_OF_BOOKS_ID
--AND A.TRANSLATED_FLAG <> 'Y'
--AND B.SEGMENT1 = '83101'
--AND B.SEGMENT3 = '14602'
--AND A.SET_OF_BOOKS_ID = 77
--AND A.CURRENCY_CODE = 'USD'
GROUP BY A.CODE_COMBINATION_ID,
B.SEGMENT1,
B.SEGMENT2,
B.SEGMENT3,
B.SEGMENT4,
B.SEGMENT5,
B.SEGMENT6,
B.SEGMENT7,
B.SEGMENT8,
B.SEGMENT9,
B.SEGMENT10,
B.SEGMENT11,
B.SEGMENT12,
B.SEGMENT13,
A.CURRENCY_CODE,
A.TRANSLATED_FLAG,
C.NAME,A.PERIOD_NAME,
A.SET_OF_BOOKS_ID
) o279709
WHERE (o279709.PERIOD_NAME = 'DEC-09')
AND (o279709.SET_OF_BOOKS_ID <> 72)
AND (o279709.SEGMENT12 = '000')
AND (o279709.SEGMENT3 IN ('10101','10301','10502','12001'))
AND (o279709.SEGMENT1 IN ('82901','82902','82903','83001','83003','83201'))
GROUP BY GROUPING SETS(( o279709.CURRENCY_CODE,o279709.SEGMENT3,o279709.SEGMENT4,o279709.TRANSLATED_FLAG ),( o279709.SEGMENT3,o279709.SEGMENT4 ),( o279709.SEGMENT3 ))
HAVING (GROUP_ID()=0)
ORDER BY GID DESC;
Thanks,
PA1
Edited by: PA1B on Jan 29, 2010 12:50 PM -
Error while executing a sql query for select
HI All,
ORA-01652: unable to extend temp segment by 128 in tablespace PSTEMP i'm getting this error while i'm executing the sql query for selecting the data.I am having 44GB of temp space, while executing the below query my temp space is getting full, Expert please let us know how the issue can be resolved..
1. I dont want to increase the temp space
2. I need to tune the query, please provide your recomendations.
insert /*+APPEND*/ into CST_DSA.HIERARCHY_MISMATCHES
(REPORT_NUM,REPORT_TYPE,REPORT_DESC,GAP,CARRIED_ITEMS,CARRIED_ITEM_TYPE,NO_OF_ROUTE_OF_CARRIED_ITEM,CARRIED_ITEM_ROUTE_NO,CARRIER_ITEMS,CARRIER_ITEM_TYPE,CARRIED_ITEM_PROTECTION_TYPE,SOURCE_SYSTEM)
select
REPORTNUMBER,REPORTTYPE,REPORTDESCRIPTION ,NULL,
carried_items,carried_item_type,no_of_route_of_carried_item,carried_item_route_no,carrier_items,
carrier_item_type,carried_item_protection_type,'PACS'
from
(select distinct
c.REPORTNUMBER,c.REPORTTYPE,c.REPORTDESCRIPTION ,NULL,
a.carried_items,a.carried_item_type,a.no_of_route_of_carried_item,a.carried_item_route_no,a.carrier_items,
a.carrier_item_type,a.carried_item_protection_type,'PACS'
from CST_ASIR.HIERARCHY_asir a,CST_DSA.M_PB_CIRCUIT_ROUTING b ,CST_DSA.REPORT_METADATA c
where a.carrier_item_type in('Connection') and a.carried_item_type in('Service')
AND a.carrier_items=b.mux
and c.REPORTNUMBER=(case
when a.carrier_item_type in ('ServicePackage','Service','Connection') then 10
else 20
end)
and a.carrier_items not in (select carried_items from CST_ASIR.HIERARCHY_asir where carried_item_type in('Connection') ))A
where not exists
(select *
from CST_DSA.HIERARCHY_MISMATCHES B where
A.REPORTNUMBER=B.REPORT_NUM and
A.REPORTTYPE=B.REPORT_TYPE and
A.REPORTDESCRIPTION=B.REPORT_DESC and
A.CARRIED_ITEMS=B.CARRIED_ITEMS and
A.CARRIED_ITEM_TYPE=B.CARRIED_ITEM_TYPE and
A.NO_OF_ROUTE_OF_CARRIED_ITEM=B.NO_OF_ROUTE_OF_CARRIED_ITEM and
A.CARRIED_ITEM_ROUTE_NO=B.CARRIED_ITEM_ROUTE_NO and
A.CARRIER_ITEMS=B.CARRIER_ITEMS and
A.CARRIER_ITEM_TYPE=B.CARRIER_ITEM_TYPE and
A.CARRIED_ITEM_PROTECTION_TYPE=B.CARRIED_ITEM_PROTECTION_TYPE
AND B.SOURCE_SYSTEM='PACS'
Explain Plan
==========
Plan
INSERT STATEMENT ALL_ROWSCost: 129 Bytes: 1,103 Cardinality: 1
20 LOAD AS SELECT CST_DSA.HIERARCHY_MISMATCHES
19 PX COORDINATOR
18 PX SEND QC (RANDOM) PARALLEL_TO_SERIAL SYS.:TQ10002 :Q1002Cost: 129 Bytes: 1,103 Cardinality: 1
17 NESTED LOOPS PARALLEL_COMBINED_WITH_PARENT :Q1002Cost: 129 Bytes: 1,103 Cardinality: 1
15 HASH JOIN RIGHT ANTI NA PARALLEL_COMBINED_WITH_PARENT :Q1002Cost: 129 Bytes: 1,098 Cardinality: 1
4 PX RECEIVE PARALLEL_COMBINED_WITH_PARENT :Q1002Cost: 63 Bytes: 359,283 Cardinality: 15,621
3 PX SEND BROADCAST PARALLEL_TO_PARALLEL SYS.:TQ10001 :Q1001Cost: 63 Bytes: 359,283 Cardinality: 15,621
2 PX BLOCK ITERATOR PARALLEL_COMBINED_WITH_CHILD :Q1001Cost: 63 Bytes: 359,283 Cardinality: 15,621
1 MAT_VIEW ACCESS FULL MAT_VIEW PARALLEL_COMBINED_WITH_PARENT CST_ASIR.HIERARCHY :Q1001Cost: 63 Bytes: 359,283 Cardinality: 15,621
14 NESTED LOOPS ANTI PARALLEL_COMBINED_WITH_PARENT :Q1002Cost: 65 Bytes: 40,256,600 Cardinality: 37,448
11 HASH JOIN PARALLEL_COMBINED_WITH_PARENT :Q1002Cost: 65 Bytes: 6,366,160 Cardinality: 37,448
8 BUFFER SORT PARALLEL_COMBINED_WITH_CHILD :Q1002
7 PX RECEIVE PARALLEL_COMBINED_WITH_PARENT :Q1002Cost: 1 Bytes: 214 Cardinality: 2
6 PX SEND BROADCAST PARALLEL_FROM_SERIAL SYS.:TQ10000 Cost: 1 Bytes: 214 Cardinality: 2
5 INDEX FULL SCAN INDEX CST_DSA.IDX$$_06EF0005 Cost: 1 Bytes: 214 Cardinality: 2
10 PX BLOCK ITERATOR PARALLEL_COMBINED_WITH_CHILD :Q1002Cost: 63 Bytes: 2,359,224 Cardinality: 37,448
9 MAT_VIEW ACCESS FULL MAT_VIEW PARALLEL_COMBINED_WITH_PARENT CST_ASIR.HIERARCHY :Q1002Cost: 63 Bytes: 2,359,224 Cardinality: 37,448
13 TABLE ACCESS BY INDEX ROWID TABLE PARALLEL_COMBINED_WITH_PARENT CST_DSA.HIERARCHY_MISMATCHES :Q1002Cost: 0 Bytes: 905 Cardinality: 1
12 INDEX RANGE SCAN INDEX PARALLEL_COMBINED_WITH_PARENT SYS.HIERARCHY_MISMATCHES_IDX3 :Q1002Cost: 0 Cardinality: 1
16 INDEX RANGE SCAN INDEX PARALLEL_COMBINED_WITH_PARENT CST_DSA.IDX$$_06EF0001 :Q1002Cost: 1 Bytes: 5 Cardinality: 1 -
Issue in creation of group in oim database through sql query.
hi guys,
i am trying to create a group in oim database through sql query:
insert into ugp(ugp_key,ugp_name,ugp_create,ugp_update,ugp_createby,ugp_updateby,)values(786,'dbrole','09-jul-12','09-jul-12',1,1);
it is inserting the group in ugp table but it is not showing in admin console.
After that i also tried with this query:
insert into gpp(ugp_key,gpp_ugp_key,gpp_write,gpp_delete,gpp_create,gpp_createby,gpp_update,gpp_updateby)values(786,1,1,1,'09-jul-12',1,'09-jul-12',1);
After that i tried with this query.but still no use.
and i also tried to assign a user to the group through query:
insert into usg(ugp_key,usr_key,usg_priority,usg_create,usg_update,usg_createby,usg_updateby)values(4,81,1,'09-jul-12','09-jul-12',1,1);
But still the same problem.it is inserting in db.but not listing in admin console.
thanks,
hanuman.Hanuman Thota wrote:
hi vladimir,
i didn't find this 'ugp_seq'.is this a table or column?where is it?
It is a sequence.
See here for details on oracle sequences:
http://www.techonthenet.com/oracle/sequences.php
Most of the OIM database schema is created with the following script, located in the RCU distribution:
$RCU_HOME/rcu/integration/oim/sql/xell.sql
there you'll find plenty of sequence creation directives like:
create sequence UGP_SEQ
increment by 1
start with 1
cache 20
to create a sequence, and
INSERT INTO UGP (UGP_KEY, UGP_NAME, UGP_UPDATEBY, UGP_UPDATE, UGP_CREATEBY, UGP_CREATE,UGP_ROWVER, UGP_DATA_LEVEL, UGP_ROLE_CATEGORY_KEY, UGP_ROLE_OWNER_KEY, UGP_DISPLAY_NAME, UGP_ROLENAME, UGP_DESCRIPTION, UGP_NAMESPACE)
VALUES (ugp_seq.nextval,'SYSTEM ADMINISTRATORS', sysadmUsrKey , SYSDATE,sysadmUsrKey , SYSDATE, hextoraw('0000000000000000'), 1, roleCategoryKey, sysadmUsrKey, 'SYSTEM ADMINISTRATORS', 'SYSTEM ADMINISTRATORS', 'System Administrator role for OIM', 'Default');
as a sequence usage example.
Regards,
Vladimir -
Using a SQL Query in an Alert and Matching a String
I've created an alert in 12.0.4 using a SQL Query and the field that I'm trying to match is a string. Originally the query returned multiple rows but when the alert still didn't fire, I modified the query WHERE clause to return only one row:
NAME RESPONSE
Are area lights working? No
My expression in the metric is RESPONSE. In the Monitor I'm matching a string equal to No. (Do I need double quotes around the matchvalue? Single quotes? No quotes?) The metric is in the 15min scan group, the role is xMII Developers and I'm in that role. The monitor alert string is ' = '. Both metric and monitor are active and I've subscribed to the monitor. Other alerts in the 15min scan group (all based on tag queries) are firing off properly.
Why is nothing showing up in the Alert Log?
David MacindoeDavid,
Did you figure out the answer? If not, I will try to find someone to address your question.
Mike -
Use realational operators in an SQL query??????
does any one knows how to use realational operators in an SQL query??????
i wud like to do something like
select decode(2<3,sysdate,sydate +1) from dual
but i know decode does not supports relational operators......
thanx and Regards
amytYou can use a CASE statement which does support relational operators, or if you must use DECODE, then you can use something like:
SELECT DECODE(SIGN(2 - 3),-1,sysdate,sysdate - 1)
FROM dual;The SIGN function returns -1 if the expression is < 0, 1 if the expression is > 0 and 0 if the expression is 0. This works for numeric comparisions. You can use the GREATEST or LEAST functions in a similar fashion for character comparisions.
TTFN
John -
How to return one ROW with Multiple value seperated by Colon in a SQL Query
Hi,
I have a SQL query as mentioned.
select deptno
from deptI want to mofidfy this query, so that this should return me department list with colon delimeted in one ROW.
10:20:30:40.......Thanks,
DeepakIn 10g:
select rtrim(xmlagg(xmlparse(content deptno || ':')).getstringval(), ':') data
from dept;
DATA
10:20:30:40with apologies for the abuse of XML... -
HELP! SQL Query: Other ways to reorder column display?
I have a SQL query report with a large number of columns (users can hide/show columns as desired). It would be great if the column display order could be changed by changing the order of the columns in the SELECT list in the Report Definition, but that doesn't work -- it puts changed or added columns at the end regardless of the order in the SELECT list of the query.
Is there some other way to reorder the columns displayed without using the Report Attributes page? It's extremely tedious to move columns around using the up/down arrows which redisplays the page each time. Am I missing a way to change display order, or does anyone have a "trick" to do this? It's so painful....
When defining forms you can reoder columns by specifying a sequence number for each column. Just curious as to why reports were not done the same way, and are there any plans to address this in a future release?
KarenYes, reordering columns is extremely painful.
It is supposed to be much improved in the next version.
See
Re: Re-ordering columns on reports
Moving columns up/down in Report Attributes
See my example at
http://htmldb.oracle.com/pls/otn/f?p=24317:141
Basically, let the users move columns around until they are blue in the face, provide a Save button to save the column order in a user preference and reorder the columns when the page reloads.
Or you can use Carl's PL/SQL shuttle as the widget to specify the columns shown and their order. The shuttle is at http://htmldb.oracle.com/pls/otn/f?p=11933:27
Hope this helps.
Message was edited by:
Vikas -
How to get resultset from procedure having dynamic select sql query ?
Hi,
I have created a procedure, in which there is dynamic select query. The procedure has one out put parameter which gives error code. When I compile that procedure it compiles successufully. When I run it it executes successfully and gives output error code. But I don't know how to get resultset of that dynamic select sql query. I need that.
This is the procedure:
create or replace
PROCEDURE uspGetProductDetailsMultiOrder
v_DefinitionDBName IN VARCHAR2,
v_CommonDBName IN VARCHAR2,
v_Filter_FilledStatus IN VARCHAR2,
v_Filter_Internal_Counterparty IN nvarchar2,
v_Filter_NoteType IN nvarchar2,
v_Filter_Exchange IN nvarchar2,
v_Filter_Issuer IN nvarchar2,
v_Filter_Product_Category IN VARCHAR2,
v_DateToFilter IN VARCHAR2,
v_Filter_FromDate IN VARCHAR2,
v_Filter_ToDate IN VARCHAR2,
v_Active_YN_Flag IN NVARCHAR2,
v_Entity_ID IN NVARCHAR2,
v_ErrorNumber OUT NUMBER
as
v_SelectSQL nvarchar2(32767);
v_Setting_Name nvarchar2(32767);
v_Default_Value nvarchar2(32767);
v_Config_Value nvarchar2(32767);
v_CCY_ID NUMBER(10,0);
v_CCY_Data nvarchar2(32767);
v_CCY_List nvarchar2(32767);
v_Seq_Id NUMBER(10,0);
SWV_Active_YN_Flag NVARCHAR2(1);
SWV_VarStr long;--varchar2(4000);
SWV_TRANCOUNT NUMBER(10,0);
SWV_fnc_SplitString_Id_var1 NUMBER(10,0);
SWV_fnc_SplitString_Id_var0 NUMBER(10,0);
CURSOR RestrictTermsheetVisibilityByC
IS select CS.Setting_Name,Default_Value,Config_Value
from Config_Settings CS LEFT OUTER JOIN Entity_Config EC ON EC.Setting_ID = CS.Setting_ID
where EC.Entity_ID = v_Entity_ID AND Setting_Level = 'ENTITY';
CURSOR Get_RestrictCCY_List_Cursor IS SELECT Id_1,Data_1 FROM table(fnc_SplitString(v_Config_Value,','));
--CURSOR Get_RestrictCCY_List_Cursor IS SELECT Id,Data FROM imp;
CURSOR GetRestrictTemplateListCursor
-- is select id,data from imp;
IS SELECT Id_1,Data_1 FROM table(fnc_SplitString(v_Config_Value,',')) ;
--Parikshit 18-Jul-2010, active YN flag param added in SP
BEGIN
SWV_Active_YN_Flag := v_Active_YN_Flag;
if SWV_Active_YN_Flag = ' ' then
SWV_Active_YN_Flag := 'Y';
end if;
v_SelectSQL := ' ';
v_SelectSQL := v_SelectSQL || ' Select ';
v_SelectSQL := v_SelectSQL || ' NM.Note_Master_Id, NM.Product_Name, NM.Template_ID, NM.Template_Sr_No, NM.Asset, NM.Exchange, NM.Type, NM.Currency';
--SET @SelectSQL = @SelectSQL + ' , NM.Trade_Date, NM.Value_Date, NM.Valuation_Date, NM.Maturity_Date, NM.Tenor, NM.Strike_Price_Percentage, (case when (NM.Type like '' ELN%'' or NM.Type like ''RELN%'') THEN NOP.Issue_Price Else NM.Customer_Price End) as Customer_Price, NM.Dealer_Price, (case when (NM.Type like '' ELN%'' or NM.Type like ''RELN%'') THEN NOP.Customer_Yield Else NM.Customer_Yield End) as Customer_Yield, NOP.Dealer_Cost_PA as Internal_Cost '
v_SelectSQL := v_SelectSQL || ' , NM.Trade_Date, NM.Value_Date, NM.Valuation_Date, NM.Maturity_Date, NM.Tenor, NM.Strike_Price_Percentage, (case when (NM.PriceList_YN = ''Y'') THEN NOP.Issue_Price Else NM.Customer_Price End) as Customer_Price, NM.Dealer_Price, (case when (NM.PriceList_YN = ''Y'') THEN NOP.Customer_Yield Else NM.Customer_Yield End) as Customer_Yield, NOP.Dealer_Cost_PA as Internal_Cost ';
v_SelectSQL := v_SelectSQL || ' , NM.Minimum_Issue_Size, NM.Maximum_Issue_Size, NM.Minimum_Tolerence_Amount, NM.Maximum_Tolerence_Amount, NM.Trigger_Amount_Warning, nvl(NM.PerUnit_Equivalent_Amount,1) as PerUnit_Equivalent_Amount, NM.Active_YN_Flag, NM.Verify_YN_Flag ';
v_SelectSQL := v_SelectSQL || ' , NM.Tranche_YN_Flag, NM.Launch_Date, NM.Open_Date, NM.Close_Date, NM.PreHedged_YN, NM.Created_By, NM.Created_At, NM.Verified_At, NM.Verified_By, NM.ISIN, NM.Issuer';
v_SelectSQL := v_SelectSQL || ' , NM.Product_Catagory as Product_Category, NM.Note_Issuer_Type as Issuer_Category, NM.Series_No as Series_No, NM.Minimum_Investment_Amount ';
--Added by Parikshit on 14-Jun-2011, to remove the unwinding amounts from the total issue size
--SET @SelectSQL = @SelectSQL + ' , NOP.LastTimeWhenProductModified,NOP.Nominal_Amount as Current_Issue_Size, NOP.Filled_Status, NM.Counterparty as Internal_Counterparty '
v_SelectSQL := v_SelectSQL || ' , NOP.LastTimeWhenProductModified,(NOP.Nominal_Amount - nvl(ND.Unwind_Amount,0) ) as Current_Issue_Size, NOP.Filled_Status, NM.Counterparty as Internal_Counterparty ';
--********************************************************END
v_SelectSQL := v_SelectSQL || ' ,T2.Confirmed_Amount, T2.Confirmed_Shares';
v_SelectSQL := v_SelectSQL || ' , T3.Live_Deals';
v_SelectSQL := v_SelectSQL || ' , BS.Net_Trade_Hedged, BS.Net_Trade_Outstanding, BS.Hedged_Nominal_BUY, BS.Hedged_Nominal_SELL, BS.Outstanding_Nominal_BUY, BS.Outstanding_Nominal_SELL ';
v_SelectSQL := v_SelectSQL || ' , ( case When UPPER(NM.PreHedged_YN) = ''Y'' Then ''Launched'' ';
v_SelectSQL := v_SelectSQL || ' When ((NM.Maturity_Date IS NOT NULL) AND to_date(NM.Maturity_Date) <= to_date(sysdate)) Then ''Matured''';
v_SelectSQL := v_SelectSQL || ' When (UPPER(NM.PreHedged_YN) = ''N'' AND NM.Launch_Date IS NOT NULL) Then ''Launched''';
--Ready to launch
v_SelectSQL := v_SelectSQL || ' When (UPPER(NM.PreHedged_YN) = ''N'' AND NM.Launch_Date IS NULL AND (T2.Confirmed_Amount >= NM.Minimum_Issue_Size) AND to_date(Close_Date) > to_date(sysdate) ) Then ''Ready To Launch''';
--Ready to launch
v_SelectSQL := v_SelectSQL || ' When (UPPER(NM.PreHedged_YN) = ''N'' AND NM.Launch_Date IS NULL AND (T2.Confirmed_Amount >= (NM.Minimum_Issue_Size - NM.Minimum_Tolerence_Amount)) AND to_date(Close_Date)= to_date(sysdate) ) Then ''Ready To Launch''';
v_SelectSQL := v_SelectSQL || ' When (UPPER(NM.PreHedged_YN) = ''N'' AND NM.Launch_Date IS NULL AND (T2.Confirmed_Amount >= (NM.Minimum_Issue_Size - NM.Minimum_Tolerence_Amount)) AND to_date(Close_Date)< to_date(sysdate) ) Then ''Ready To Launch''';
--Warning trigger reached
v_SelectSQL := v_SelectSQL || ' When (UPPER(NM.PreHedged_YN) = ''N'' AND NM.Launch_Date IS NOT NULL AND (T2.Confirmed_Amount >= NM.Trigger_Amount_Warning )) Then ''Warning Trigger Reached''';
v_SelectSQL := v_SelectSQL || ' Else ''Not Ready'' ';
v_SelectSQL := v_SelectSQL || ' End)Launch_Status';
v_SelectSQL := v_SelectSQL || ' , NI.Issuer_Code';
v_SelectSQL := v_SelectSQL || ' , (nvl(NOP.Nominal_Amount,0) - nvl(T2.Confirmed_Amount,0)) as Unconfirmed_Amount, NM.Upfront as Upfront, case when UPPER(NM.PreHedged_YN) = ''Y'' THEN 0 else (nvl(T2.Confirmed_Amount,0) - nvl(BS.Net_Trade_Hedged,0)) end as ReadyToHedge';
v_SelectSQL := v_SelectSQL || ' , NOP.Hard_Margin as Margin_Amount, NM.YearBasis as YearBasis, NM.Note_Product_Rating as Equity_Risk_Score, AD.Equity_Asset_Class ';
v_SelectSQL := v_SelectSQL || ' , NM.Note_Product_Rating as Product_Rating, NOP.PO_ID, AD.LotSize as Lot_Size, NM.Max_Orders_Per_Product as MAX_Orders, NOP.Order_Count as Current_Order_Count, nvl(NM.Denomination_Ccy,NM.Currency) as Denomination_Ccy, NM.Note_Scheme_Type as Underlying_Type, NM.Note_Asset_Class as Asset_Class, NULL as Product_Created_YN, NULL as Product_Created_ID, ( (case when NM.Note_Order_Type = '''' then N''Market'' else NM.Note_Order_Type end ) ) as Order_Type, NOP.Spot_Price, NM.Note_Price_Link, NOP.Strike_Price, NVL(NM.C_Fixing_Frequency,''Atmaturity'') as Fixing_Frequency, NM.Document_Uploaded_YN, NM.Document_Uploaded_At, NM.Document_Uploaded_By, NM.Document_File_Name, NM.Document_File_Extension, NM.Document_File_Path, NM.CutOff_Time, NM.Soft_Tenor, NM.NM_Sn_Code_All, NULL as Note_Price_Source, AD.LongName, NVL(NM.Pricelist_YN,''N'') as Pricelist_YN, AD.AlternateIdentifierAlias as Underlying, NM.Note_Issuer_Date_Offset, NM.Counterparty as Note_Counter_Party, NULL as
Note_Premium_PC ';
v_SelectSQL := v_SelectSQL || ' , NI.Issuer_Name, IP.Issuer_Id, IP.Broad_Cash, IP.Odd_Cash, IP.Account_Note, IP.Rounding, IP.Decimal_Truncate, IP.Misc1 as Recidual_YN, NM.Note_Issuer_Type, NM.Target_Coupon, C_Fixing_Frequency as C_Fixing_Frequency, NM.Callable_Frequency as Callable_Frequency, NM.Strike_Price_Percentage as C_Note_Strike_PC, NM.NM_Airbag_PC as Airbag_PC, C_Note_Barrier_PC as C_Note_Barrier_PC, TM.Template_Name, ''Product'' as Record_Type, NM.C_Settlement_Frequency, NM.Coupon_Frequency, NM.NM_Fixing_Source as Note_Fixing_Source, NM.Order_Entry_Type, (nvl(NM.Minimum_Issue_Size,0) - nvl(T2.Confirmed_Amount,0)) as Remaining_Launch_Amount, NM.C_Fixing_Start_Point, NM.C_Fixing_End_Point, NM.Order_Entry_Type, SC.Scheme_Alias, SC.Scheme_Name, CM.CM_ID, CM.CM_Name as Counterparty_Name, NM.NM_Other_Features as Other_Features, NM.Strike_Price_Percentage as Accrual_Strike, NM.NM_KnockIn as KnockIn, NM.NM_Airbag_Type, NM.NM_Put_strike as Put_Strike, NM.NM_Accrual_Strike,
NM.NM_Counterparty_Upfront, NM.Price_Updated_YN as Prices_Updated_YN, AD.Code as Asset_Name,NULL as KO_FREQ_TYPE, NM.Daily_Accumalation_Equities, NM.MaxNoAcc_days, NM.Guaranteed_Days, NM.Leverage_ratio, NM.NORM_IF, NM.NORM_PAIR, NM.NORM_FXRate ';
v_SelectSQL := v_SelectSQL || ' from ';
v_SelectSQL := v_SelectSQL || v_CommonDBName|| '.Note_Master NM ';
v_SelectSQL := v_SelectSQL || 'Left Outer Join ';
v_SelectSQL := v_SelectSQL || v_CommonDBName||'.Issuer_Master NI ';
v_SelectSQL := v_SelectSQL || ' On NM.Issuer = (case when ISNUMERIC(NM.Issuer) = 0 then cast (NI.Issuer_Name as nvarchar2(25)) else cast(NI.Issuer_Id as nvarchar2(25)) end )';
v_SelectSQL := v_SelectSQL || ' Left Outer Join ';
v_SelectSQL := v_SelectSQL || v_CommonDBName||'.Note_Order_Product NOP ';
v_SelectSQL := v_SelectSQL || ' On NOP.Note_Master_ID = NM.Note_Master_ID';
v_SelectSQL := v_SelectSQL || ' Left Outer Join ';
v_SelectSQL := v_SelectSQL || v_DefinitionDBName||'.AssetDef AD ';
v_SelectSQL := v_SelectSQL || ' On AD.Code = NM.Asset';
v_SelectSQL := v_SelectSQL || ' AND AD.TypeAsset = substr(NM.Note_Asset_Class,1,2) ';
v_SelectSQL := v_SelectSQL || ' Left Outer Join ';
v_SelectSQL := v_SelectSQL || v_CommonDBName||'.Issuer_Parameter IP ';
v_SelectSQL := v_SelectSQL || ' On NM.Issuer = (case when ISNUMERIC(NM.Issuer) = 0 then cast (IP.Issuer_Name as nvarchar2(25)) else cast(IP.Issuer_Id as nvarchar2(25)) end )';
v_SelectSQL := v_SelectSQL || ' Left Outer Join ';
v_SelectSQL := v_SelectSQL || v_CommonDBName||'.Template_Master TM ';
v_SelectSQL := v_SelectSQL || ' On TM.Template_Id = NM.Template_ID ';
v_SelectSQL := v_SelectSQL || ' Left Outer Join ';
v_SelectSQL := v_SelectSQL || v_CommonDBName||'.Scheme_Codes SC ';
v_SelectSQL := v_SelectSQL || ' On SC.Scheme_Alias = NM.Type';
v_SelectSQL := v_SelectSQL || ' Left Outer Join ';
v_SelectSQL := v_SelectSQL || v_CommonDBName||'.Counterparty_Master CM ';
v_SelectSQL := v_SelectSQL || ' On CM.CM_ID = NM.Counterparty';
v_SelectSQL := v_SelectSQL || ' Left Outer Join ';
v_SelectSQL := v_SelectSQL || ' ( ';
v_SelectSQL := v_SelectSQL || ' Select Note_master_ID, sum(Nominal_Amt) as Unwind_Amount from ';
v_SelectSQL := v_SelectSQL || v_CommonDBName||'.Note_Deals ';
v_SelectSQL := v_SelectSQL || ' where Prematurity_Date IS NOT NULL';
v_SelectSQL := v_SelectSQL || ' AND (UPPER(Deletion_Reason ) = ''PART REDEMPTION'' or UPPER(Deletion_Reason ) = ''FULL REDEMPTION'')';
v_SelectSQL := v_SelectSQL || ' Group by Note_master_ID ';
v_SelectSQL := v_SelectSQL || ' ) ND ';
v_SelectSQL := v_SelectSQL || ' On ND.Note_Master_ID = NM.Note_Master_ID';
if (v_Filter_FilledStatus = ' ' OR UPPER(v_Filter_FilledStatus) = 'ALL' ) then
v_SelectSQL := v_SelectSQL || ' ';
else
v_SelectSQL := v_SelectSQL || ' AND NOP.Filled_Status IN (' || v_Filter_FilledStatus || ')';
end if;
--AND NOP.Internal_Counterparty = 'DEFAULT''
if(SUBSTR(to_char(v_Filter_Internal_Counterparty),1,4000)= ' ') then
v_SelectSQL := v_SelectSQL || ' ';
else
v_SelectSQL := v_SelectSQL || ' AND NOP.Internal_Counterparty IN (' || v_Filter_Internal_Counterparty || ')';
end if;
--SET @SelectSQL = @SelectSQL + ' --Filter--'
v_SelectSQL := v_SelectSQL || ' LEFT OUTER JOIN ';
v_SelectSQL := v_SelectSQL || ' (';
v_SelectSQL := v_SelectSQL || ' select Note_Master_ID, sum(Nominal_Amount) As Confirmed_Amount, sum(No_Of_Shares) As Confirmed_Shares ';
v_SelectSQL := v_SelectSQL || ' from '||v_CommonDBName||'.Note_Order_RM ';
v_SelectSQL := v_SelectSQL || ' Where substr(UPPER(Order_Status_Flag),1,6) = ''YYYYYY'' AND substr(substr(UPPER(Order_Status_Flag),1,7),-1,1) = ''N'' ';
v_SelectSQL := v_SelectSQL || ' group by Note_Master_ID';
v_SelectSQL := v_SelectSQL || ' ) T2';
v_SelectSQL := v_SelectSQL || ' ON T2.Note_Master_ID = NM.Note_Master_ID';
v_SelectSQL := v_SelectSQL || ' LEFT OUTER JOIN';
v_SelectSQL := v_SelectSQL || ' (';
v_SelectSQL := v_SelectSQL || ' Select ND.Note_Master_ID, sum(ND.Nominal_Amt) As Live_Deals ';
v_SelectSQL := v_SelectSQL || ' from '||v_CommonDBName||'.Note_Deals ND ';
v_SelectSQL := v_SelectSQL || ' where ND.Active_YNFlag = ''Y'' ';
v_SelectSQL := v_SelectSQL || ' group by Note_Master_ID';
v_SelectSQL := v_SelectSQL || ' ) T3';
v_SelectSQL := v_SelectSQL || ' ON T3.Note_Master_ID = NM.Note_Master_ID';
v_SelectSQL := v_SelectSQL || ' LEFT OUTER JOIN';
v_SelectSQL := v_SelectSQL || ' (';
v_SelectSQL := v_SelectSQL || ' SELECT NH_Note_Master_ID,';
v_SelectSQL := v_SelectSQL || ' (CAST(SUM(Hedged_Nominal_Buy) AS BINARY_FLOAT) -CAST(SUM(Hedged_Nominal_Sell) AS BINARY_FLOAT)) Net_Trade_Hedged,';
v_SelectSQL := v_SelectSQL || ' (CAST(SUM(Outstanding_Nominal_BUY) AS BINARY_FLOAT) -CAST(SUM(Outstanding_Nominal_SELL) AS BINARY_FLOAT)) Net_Trade_Outstanding,';
v_SelectSQL := v_SelectSQL || ' SUM(Hedged_Nominal_BUY) AS Hedged_Nominal_BUY,';
v_SelectSQL := v_SelectSQL || ' SUM(Hedged_Nominal_SELL) AS Hedged_Nominal_SELL,';
v_SelectSQL := v_SelectSQL || ' SUM(Outstanding_Nominal_BUY) AS Outstanding_Nominal_BUY,';
v_SelectSQL := v_SelectSQL || ' SUM(Outstanding_Nominal_SELL) As Outstanding_Nominal_SELL';
v_SelectSQL := v_SelectSQL || ' From';
v_SelectSQL := v_SelectSQL || ' (';
v_SelectSQL := v_SelectSQL || ' SELECT NH_Note_Master_ID,';
v_SelectSQL := v_SelectSQL || ' SUM(NH_Hedged_Nominal) AS Hedged_Nominal_BUY, 0 AS Hedged_Nominal_SELL,';
v_SelectSQL := v_SelectSQL || ' SUM(NH_Outstanding_Nominal) AS Outstanding_Nominal_BUY, 0 AS Outstanding_Nominal_SELL';
v_SelectSQL := v_SelectSQL || ' FROM '||v_CommonDBName||'.Note_Hedge ';
v_SelectSQL := v_SelectSQL || ' WHERE NH_Direction = ''BUY'' ';
v_SelectSQL := v_SelectSQL || ' GROUP BY NH_Note_Master_ID';
v_SelectSQL := v_SelectSQL || ' Union';
v_SelectSQL := v_SelectSQL || ' SELECT NH_Note_Master_ID,';
v_SelectSQL := v_SelectSQL || ' 0 AS Hedged_Nominal_BUY, SUM(NH_Hedged_Nominal) AS Hedged_Nominal_SELL,';
v_SelectSQL := v_SelectSQL || ' 0 AS Outstanding_Nominal_BUY, SUM(NH_Outstanding_Nominal) AS Outstanding_Nominal_SELL';
v_SelectSQL := v_SelectSQL || ' FROM '||v_CommonDBName||'.Note_Hedge ';
v_SelectSQL := v_SelectSQL || ' WHERE NH_Direction = ''SELL'' ';
v_SelectSQL := v_SelectSQL || ' GROUP BY NH_Note_Master_ID';
v_SelectSQL := v_SelectSQL || ' ) ';
v_SelectSQL := v_SelectSQL || ' GROUP BY NH_Note_Master_ID';
v_SelectSQL := v_SelectSQL || ' ) BS';
v_SelectSQL := v_SelectSQL || ' ON BS.NH_Note_Master_ID = NM.Note_Master_ID';
v_SelectSQL := v_SelectSQL || ' Where NM.Verify_YN_Flag = ''Y'' ';
v_SelectSQL := v_SelectSQL || ' AND NM.Active_YN_Flag = ''' || SWV_Active_YN_Flag || '''';
if(SUBSTR(to_char(v_Filter_NoteType),1,4000) = ' ' OR UPPER(v_Filter_NoteType) = 'ALL' ) then
v_SelectSQL := v_SelectSQL || ' ';
else
v_SelectSQL := v_SelectSQL || ' AND NM.Type IN (' || v_Filter_NoteType || ')';
end if;
IF UPPER(v_Entity_ID) <> 'ALL' then
OPEN RestrictTermsheetVisibilityByC;
FETCH RestrictTermsheetVisibilityByC INTO v_Setting_Name,v_Default_Value,v_Config_Value;
WHILE RestrictTermsheetVisibilityByC%FOUND LOOP
--2) Convert comma separated ccy (CNY,HKD,USD) string to single quote ccy with comma separated Ccy ('CNY','HKD','USD') string
if (UPPER(v_Setting_Name) = 'RESTRICT_TERMSHEET_VISIBILITY_BY_CCY') then
if v_Config_Value is not null then
SELECT COUNT(Id_1) INTO SWV_fnc_SplitString_Id_var0 FROM TABLE(fnc_SplitString(v_Config_Value,',')) ;
IF (SWV_fnc_SplitString_Id_var0 > 0) then
--print 'Before Single quote separated ccy : ' + '''' + @Config_Value + ''''
v_Seq_Id := 0;
OPEN Get_RestrictCCY_List_Cursor;
FETCH Get_RestrictCCY_List_Cursor
INTO v_CCY_ID,v_CCY_Data;
WHILE Get_RestrictCCY_List_Cursor%FOUND LOOP
if v_Seq_Id = 0 then
v_CCY_List := '''' || v_CCY_Data || '''';
else
v_CCY_List := v_CCY_List || ',' || '''' || v_CCY_Data || '''';
end if;
v_Seq_Id := v_Seq_Id+1;
FETCH Get_RestrictCCY_List_Cursor INTO v_CCY_ID,v_CCY_Data;
END LOOP;
CLOSE Get_RestrictCCY_List_Cursor;
--print 'After Single quote ccy : ' + @CCY_List
v_SelectSQL := v_SelectSQL || ' AND nvl(NM.Denomination_Ccy,NM.Currency) NOT IN (' || v_CCY_List || ')';
end if;
end if;
end if;
--3) Convert comma separated template (ELN,BELN,BELN_B) string to single quote template code with comma separated template ('ELN','BELN','BELN_B') string
if (UPPER(v_Setting_Name) = 'RESTRICT_TERMSHEET_VISIBILITY_BY_SUBSCHEME') then
if v_Config_Value is not null then
SELECT COUNT(Id_1) INTO SWV_fnc_SplitString_Id_var1 FROM TABLE(fnc_SplitString(v_Config_Value,',')) ;
IF (SWV_fnc_SplitString_Id_var1 > 0) then
v_Seq_Id := 0;
OPEN GetRestrictTemplateListCursor;
FETCH GetRestrictTemplateListCursor
INTO v_CCY_ID,v_CCY_Data;
WHILE GetRestrictTemplateListCursor%FOUND
LOOP
if v_Seq_Id = 0 then
v_CCY_List := '''' || v_CCY_Data || '''';
else
v_CCY_List := v_CCY_List || ',' || '''' || v_CCY_Data || '''';
end if;
v_Seq_Id := v_Seq_Id+1;
FETCH GetRestrictTemplateListCursor INTO v_CCY_ID,v_CCY_Data;
END LOOP;
CLOSE GetRestrictTemplateListCursor;
--print 'After Single quote template code: ' + @CCY_List
v_SelectSQL := v_SelectSQL || ' AND TM.Template_Code NOT IN (' || v_CCY_List || ')';
end if;
end if;
end if;
FETCH RestrictTermsheetVisibilityByC INTO v_Setting_Name,v_Default_Value,v_Config_Value;
END LOOP;
CLOSE RestrictTermsheetVisibilityByC;
end if;
if (v_Filter_Exchange = ' ' OR UPPER(v_Filter_Exchange) = 'ALL') then
v_SelectSQL := v_SelectSQL || ' ';
else
v_SelectSQL := v_SelectSQL || ' AND NM.Exchange IN (' || v_Filter_Exchange || ')';
end if;
--SET @SelectSQL = @SelectSQL + ' --AND NM.Issuer = 4'
if (v_Filter_Issuer = ' ' OR UPPER(v_Filter_Issuer) = 'ALL') then
v_SelectSQL := v_SelectSQL || ' ';
else
v_SelectSQL := v_SelectSQL || ' AND NM.Issuer IN (' || v_Filter_Issuer || ')';
end if;
if v_Filter_Product_Category = ' ' then
v_SelectSQL := v_SelectSQL || ' ';
else
v_SelectSQL := v_SelectSQL || ' AND UPPER(NM.Note_Issuer_Type) IN (''' || v_Filter_Product_Category || ''')';
end if;
if UPPER(v_DateToFilter) = 'NA' then
v_SelectSQL := v_SelectSQL || ' ';
else
if UPPER(v_DateToFilter) = 'CLOSE_DATE' then
v_SelectSQL := v_SelectSQL || ' AND to_char( '|| v_DateToFilter || ') >= to_date(''' || v_Filter_ToDate || ''');
-- AND convert(smalldatetime,''' || v_Filter_ToDate || ''',106) ';
else
v_SelectSQL := v_SelectSQL || ' AND to_char(''' || v_DateToFilter || ''') BETWEEN to_date(''' || v_Filter_FromDate || ''') AND to_date(''' || v_Filter_ToDate || ''') ';
end if;
end if;
v_SelectSQL := v_SelectSQL || ' Order by NM.Product_Name';
SWV_VarStr := v_SelectSQL;
DBMS_OUTPUT.PUT_LINE(SWV_VarStr);
EXECUTE IMMEDIATE SWV_VarStr;
IF SQLCODE <> 0 then
GOTO ERROR_HANDLER;
end if;
IF SQL%rowcount > 0 then
COMMIT;
SWV_TRANCOUNT := SWV_TRANCOUNT -1;
end if; --Commit Transaction
v_ErrorNumber := SQLCODE;
RETURN;
<< ERROR_HANDLER >> v_ErrorNumber := SQLCODE;
ROLLBACK;
SWV_TRANCOUNT := 0; --Rollback Transaction
RETURN;
END;Please suggest something. Thanks
Edited by: BluShadow on 30-Nov-2011 11:00
added {noformat}{noformat} tags for formatting of code. Please read {message:id=9360002} to learn to do this yourself in future.Connecting to the database sample_adf_finiq_common.
Select NM.Note_Master_Id, NM.Product_Name, NM.Template_ID, NM.Template_Sr_No, NM.Asset, NM.Exchange, NM.Type, NM.Currency , NM.Trade_Date, NM.Value_Date, NM.Valuation_Date, NM.Maturity_Date, NM.Tenor, NM.Strike_Price_Percentage, (case when (NM.PriceList_YN = 'Y') THEN NOP.Issue_Price Else NM.Customer_Price End) as Customer_Price, NM.Dealer_Price, (case when (NM.PriceList_YN = 'Y') THEN NOP.Customer_Yield Else NM.Customer_Yield End) as Customer_Yield, NOP.Dealer_Cost_PA as Internal_Cost , NM.Minimum_Issue_Size, NM.Maximum_Issue_Size, NM.Minimum_Tolerence_Amount, NM.Maximum_Tolerence_Amount, NM.Trigger_Amount_Warning, nvl(NM.PerUnit_Equivalent_Amount,1) as PerUnit_Equivalent_Amount, NM.Active_YN_Flag, NM.Verify_YN_Flag , NM.Tranche_YN_Flag, NM.Launch_Date, NM.Open_Date, NM.Close_Date, NM.PreHedged_YN, NM.Created_By, NM.Created_At, NM.Verified_At, NM.Verified_By, NM.ISIN, NM.Issuer , NM.Product_Catagory as Product_Category, NM.Note_Issuer_Type as Issuer_Category, NM.Series_No as Series_No, NM.Minimum_Investment_Amount , NOP.LastTimeWhenProductModified,(NOP.Nominal_Amount - nvl(ND.Unwind_Amount,0) ) as Current_Issue_Size, NOP.Filled_Status, NM.Counterparty as Internal_Counterparty ,T2.Confirmed_Amount, T2.Confirmed_Shares , T3.Live_Deals , BS.Net_Trade_Hedged, BS.Net_Trade_Outstanding, BS.Hedged_Nominal_BUY, BS.Hedged_Nominal_SELL, BS.Outstanding_Nominal_BUY, BS.Outstanding_Nominal_SELL , ( case When UPPER(NM.PreHedged_YN) = 'Y' Then 'Launched' When ((NM.Maturity_Date IS NOT NULL) AND to_date(NM.Maturity_Date) <= to_date(sysdate)) Then 'Matured' When (UPPER(NM.PreHedged_YN) = 'N' AND NM.Launch_Date IS NOT NULL) Then 'Launched' When (UPPER(NM.PreHedged_YN) = 'N' AND NM.Launch_Date IS NULL AND (T2.Confirmed_Amount >= NM.Minimum_Issue_Size) AND to_date(Close_Date) > to_date(sysdate) ) Then 'Ready To Launch' When (UPPER(NM.PreHedged_YN) = 'N' AND NM.Launch_Date IS NULL AND (T2.Confirmed_Amount >= (NM.Minimum_Issue_Size - NM.Minimum_Tolerence_Amount)) AND to_date(Close_Date)= to_date(sysdate) ) Then 'Ready To Launch' When (UPPER(NM.PreHedged_YN) = 'N' AND NM.Launch_Date IS NULL AND (T2.Confirmed_Amount >= (NM.Minimum_Issue_Size - NM.Minimum_Tolerence_Amount)) AND to_date(Close_Date)< to_date(sysdate) ) Then 'Ready To Launch' When (UPPER(NM.PreHedged_YN) = 'N' AND NM.Launch_Date IS NOT NULL AND (T2.Confirmed_Amount >= NM.Trigger_Amount_Warning )) Then 'Warning Trigger Reached' Else 'Not Ready' End)Launch_Status , NI.Issuer_Code , (nvl(NOP.Nominal_Amount,0) - nvl(T2.Confirmed_Amount,0)) as Unconfirmed_Amount, NM.Upfront as Upfront, case when UPPER(NM.PreHedged_YN) = 'Y' THEN 0 else (nvl(T2.Confirmed_Amount,0) - nvl(BS.Net_Trade_Hedged,0)) end as ReadyToHedge , NOP.Hard_Margin as Margin_Amount, NM.YearBasis as YearBasis, NM.Note_Product_Rating as Equity_Risk_Score, AD.Equity_Asset_Class , NM.Note_Product_Rating as Product_Rating, NOP.PO_ID, AD.LotSize as Lot_Size, NM.Max_Orders_Per_Product as MAX_Orders, NOP.Order_Count as Current_Order_Count, nvl(NM.Denomination_Ccy,NM.Currency) as Denomination_Ccy, NM.Note_Scheme_Type as Underlying_Type, NM.Note_Asset_Class as Asset_Class, NULL as Product_Created_YN, NULL as Product_Created_ID, ( (case when NM.Note_Order_Type = '' then N'Market' else NM.Note_Order_Type end ) ) as Order_Type, NOP.Spot_Price, NM.Note_Price_Link, NOP.Strike_Price, NVL(NM.C_Fixing_Frequency,'Atmaturity') as Fixing_Frequency, NM.Document_Uploaded_YN, NM.Document_Uploaded_At, NM.Document_Uploaded_By, NM.Document_File_Name, NM.Document_File_Extension, NM.Document_File_Path, NM.CutOff_Time, NM.Soft_Tenor, NM.NM_Sn_Code_All, NULL as Note_Price_Source, AD.LongName, NVL(NM.Pricelist_YN,'N') as Pricelist_YN, AD.AlternateIdentifierAlias as Underlying, NM.Note_Issuer_Date_Offset, NM.Counterparty as Note_Counter_Party, NULL as
Note_Premium_PC , NI.Issuer_Name, IP.Issuer_Id, IP.Broad_Cash, IP.Odd_Cash, IP.Account_Note, IP.Rounding, IP.Decimal_Truncate, IP.Misc1 as Recidual_YN, NM.Note_Issuer_Type, NM.Target_Coupon, C_Fixing_Frequency as C_Fixing_Frequency, NM.Callable_Frequency as Callable_Frequency, NM.Strike_Price_Percentage as C_Note_Strike_PC, NM.NM_Airbag_PC as Airbag_PC, C_Note_Barrier_PC as C_Note_Barrier_PC, TM.Template_Name, 'Product' as Record_Type, NM.C_Settlement_Frequency, NM.Coupon_Frequency, NM.NM_Fixing_Source as Note_Fixing_Source, NM.Order_Entry_Type, (nvl(NM.Minimum_Issue_Size,0) - nvl(T2.Confirmed_Amount,0)) as Remaining_Launch_Amount, NM.C_Fixing_Start_Point, NM.C_Fixing_End_Point, NM.Order_Entry_Type, SC.Scheme_Alias, SC.Scheme_Name, CM.CM_ID, CM.CM_Name as Counterparty_Name, NM.NM_Other_Features as Other_Features, NM.Strike_Price_Percentage as Accrual_Strike, NM.NM_KnockIn as KnockIn, NM.NM_Airbag_Type, NM.NM_Put_strike as Put_Strike, NM.NM_Accrual_Strike,
NM.NM_Counterparty_Upfront, NM.Price_Updated_YN as Prices_Updated_YN, AD.Code as Asset_Name,NULL as KO_FREQ_TYPE, NM.Daily_Accumalation_Equities, NM.MaxNoAcc_days, NM.Guaranteed_Days, NM.Leverage_ratio, NM.NORM_IF, NM.NORM_PAIR, NM.NORM_FXRate from Sample_ADF_finiq_Common.Note_Master NM Left Outer Join Sample_ADF_finiq_Common.Issuer_Master NI On NM.Issuer = (case when ISNUMERIC(NM.Issuer) = 0 then cast (NI.Issuer_Name as nvarchar2(25)) else cast(NI.Issuer_Id as nvarchar2(25)) end ) Left Outer Join Sample_ADF_finiq_Common.Note_Order_Product NOP On NOP.Note_Master_ID = NM.Note_Master_ID Left Outer Join Sample_ADF_finiq_Common.AssetDef AD On AD.Code = NM.Asset AND AD.TypeAsset = substr(NM.Note_Asset_Class,1,2) Left Outer Join Sample_ADF_finiq_Common.Issuer_Parameter IP On NM.Issuer = (case when ISNUMERIC(NM.Issuer) = 0 then cast (IP.Issuer_Name as nvarchar2(25)) else cast(IP.Issuer_Id as nvarchar2(25)) end ) Left Outer Join Sample_ADF_finiq_Common.Template_Master TM On TM.Template_Id = NM.Template_ID Left Outer Join Sample_ADF_finiq_Common.Scheme_Codes SC On SC.Scheme_Alias = NM.Type Left Outer Join Sample_ADF_finiq_Common.Counterparty_Master CM On CM.CM_ID = NM.Counterparty Left Outer Join ( Select Note_master_ID, sum(Nominal_Amt) as Unwind_Amount from Sample_ADF_finiq_Common.Note_Deals where Prematurity_Date IS NOT NULL AND (UPPER(Deletion_Reason ) = 'PART REDEMPTION' or UPPER(Deletion_Reason ) = 'FULL REDEMPTION') Group by Note_master_ID ) ND On ND.Note_Master_ID = NM.Note_Master_ID AND NOP.Internal_Counterparty IN (1) LEFT OUTER JOIN ( select Note_Master_ID, sum(Nominal_Amount) As Confirmed_Amount, sum(No_Of_Shares) As Confirmed_Shares from Sample_ADF_finiq_Common.Note_Order_RM Where substr(UPPER(Order_Status_Flag),1,6) = 'YYYYYY' AND substr(substr(UPPER(Order_Status_Flag),1,7),-1,1) = 'N' group by Note_Master_ID ) T2 ON T2.Note_Master_ID = NM.Note_Master_ID LEFT OUTER JOIN ( Select ND.Note_Master_ID, sum(ND.Nominal_Amt) As Live_Deals from Sample_ADF_finiq_Common.Note_Deals ND where ND.Active_YNFlag = 'Y' group by Note_Master_ID ) T3 ON T3.Note_Master_ID = NM.Note_Master_ID LEFT OUTER JOIN ( SELECT NH_Note_Master_ID, (CAST(SUM(Hedged_Nominal_Buy) AS BINARY_FLOAT) -CAST(SUM(Hedged_Nominal_Sell) AS BINARY_FLOAT)) Net_Trade_Hedged, (CAST(SUM(Outstanding_Nominal_BUY) AS BINARY_FLOAT) -CAST(SUM(Outstanding_Nominal_SELL) AS BINARY_FLOAT)) Net_Trade_Outstanding, SUM(Hedged_Nominal_BUY) AS Hedged_Nominal_BUY, SUM(Hedged_Nominal_SELL) AS Hedged_Nominal_SELL, SUM(Outstanding_Nominal_BUY) AS Outstanding_Nominal_BUY, SUM(Outstanding_Nominal_SELL) As Outstanding_Nominal_SELL From ( SELECT NH_Note_Master_ID, SUM(NH_Hedged_Nominal) AS Hedged_Nominal_BUY, 0 AS Hedged_Nominal_SELL, SUM(NH_Outstanding_Nominal) AS Outstanding_Nominal_BUY, 0 AS Outstanding_Nominal_SELL FROM Sample_ADF_finiq_Common.Note_Hedge WHERE NH_Direction = 'BUY' GROUP BY NH_Note_Master_ID Union SELECT NH_Note_Master_ID, 0 AS Hedged_Nominal_BUY, SUM(NH_Hedged_Nominal) AS Hedged_Nominal_SELL, 0 AS Outstanding_Nominal_BUY, SUM(NH_Outstanding_Nominal) AS Outstanding_Nominal_SELL FROM Sample_ADF_finiq_Common.Note_Hedge WHERE NH_Direction = 'SELL' GROUP BY NH_Note_Master_ID ) GROUP BY NH_Note_Master_ID ) BS ON BS.NH_Note_Master_ID = NM.Note_Master_ID Where NM.Verify_YN_Flag = 'Y' AND NM.Active_YN_Flag = 'Y' AND UPPER(NM.Note_Issuer_Type) IN ('Internal') AND to_char('16-oct-11') BETWEEN to_date('15-oct-11') AND to_date('17-oct-11') Order by NM.Product_Name
V_ERRORNUMBER = 0
Process exited.
Disconnecting from the database sample_adf_finiq_common.
here v_errornumber=0 is the output when i run it in oracle sql developer. -
I'm having trouble with an SQL query. I've created a simple logon page wherein a user will enter their user name and password. The program will look in an Access database for the user name, sort it by Date/Time modified, and check to see if their password matches the most recent password. Unfortunately, the query returns no results. I'm absolutely certain that I'm doing the query correctly (I've imported it directly from my old VB6 code). Something simple is eluding me. Any help would be appreciated.
private void LogOn() {
//make sure that the user name/password is valid, then load the main menu
try {
//open the database connection
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:LawOffice2000", "", "");
Statement select = con.createStatement();
String strTemp = "Select * From EMPLOYEES Where INITIALS = '" + txtUserName.getText() + "' Order By DATE Desc, TIME Desc";
ResultSet result = select.executeQuery(strTemp);
while(result.next()) {
if (txtPassword.getPassword().toString() == result.getString("Password")) {
MenuMain.main();
else {
System.out.println("Password Bad");
System.out.println(txtUserName.getText());
System.out.println(result.getString("Password"));
break; //exit loop
//close the connection
con.close(); }
catch (Exception e) {
System.out.println("LawOfficeSuite_LogOn: " + e);
return; }
}The problem is here: "txtPassword.getPassword().toString() == result.getString("Password"))"
Don't confuse String's equals() method with the equality operator '=='. The == operator checks that two references refer to the same object. If you want to compare the contents of Strings (whether two strings contain the same characters), use equals(), e.g. if (str1.equals(str2))...
Example:String s1 = "foo";
String s2 = new String("foo");
System.out.println("s1 == s2: " + (s1 == s2)); // false
System.out.println("s1.equals(s2): " + (s1.equals(s2))); // trueFor more information, check out Comparison operators: equals() versus ==
Maybe you are looking for
-
Workflow PE_APPROVE01 is not triggering in PV7i .
Dear SAP Workflow Experts . Friends i found workFlow for Training & Event Mgmt , it is : PE_APPROVE01 . workflow event : WS01200151 . activated the object type : PDRELA_025 . After Activation it become green then i ran this workflow . But issue is re
-
How can I set up the HP photosmart d110a on a mac?
I own a macbook running lion(2010), setup on a wireless network run through a Linksys WRT110 wireless router. I also bought the HP Photosmart d110, and it sets up and works fine through my windows laptop, but on my mac, I can't get it set up to scan
-
I use the Microsoft intellimouse explorer 3.0 since many ears. Ever since i started using firefox i set the small thumb button to the action "close" in the mouse settings. This worked fine with firefox 3.x, it closed the tab i was reading. In firefox
-
Is there a background image option
In CS4 Properties Inspector? I am trying to figure out if I have a faulty install?
-
ACS 4.0 and RSA Token Server problem
Hi, We are having a problem trying to get ACS 4.0 for Windows to authenticate wireless users on an RSA Token server. Our Cisco 1200 series AP is configured for WPA2 and LEAP authentication. It points at the ACS server for RADIUS authentication. Now t