Dynamic PL/SQL code into ODI Procedure
Hi guys:
I have a PL/SQL code to execute into a ODI proc that changes because of a loop.
I have to update N tables that have the same prefix and its sufix is the dynamic part of my PL/SQL. Also I have to set the DT_ETL (I already have a variable in my package with the sysdate) and the limit of a rownum.
These are my variables:
vGET_CD_BASE*
vQTD_REG_UPDATE*
vETL_DATE*
The PL/SQL is described below (with the dynamic parts of it as ODI variables #vXXXXX):
DECLARE
CURSOR v_Cur IS
SELECT ROWID KEY_ROW FROM GG_DATA.WRK_SN_DET_ITEM_EXTR_PARC_*#vGET_CD_BASE* WHERE DT_ETL = TO_DATE('01/01/1900','DD/MM/YYYY') and rownum < *#vQTD_REG_UPDATE*;
TYPE t_Tabela IS TABLE OF ROWID INDEX BY BINARY_INTEGER;
r_Reg t_Tabela;
BEGIN
OPEN v_Cur;
LOOP
FETCH v_Cur BULK COLLECT INTO r_Reg LIMIT 100000;
FORALL i IN 1..r_Reg.COUNT
UPDATE GG_DATA.WRK_SN_DET_ITEM_EXTR_PARC_*#vGET_CD_BASE*
SET DT_ETL = TO_DATE('*#vETL_DATE*','DD/MM/YYYY HH24:MI:SS')
WHERE ROWID = r_Reg(i);
EXIT WHEN v_Cur%NOTFOUND;
COMMIT;
END LOOP;
CLOSE v_Cur;
COMMIT;
END;
What do I have to change to make this PL/SQL works in ODI Procedure?
Regards.
Luiz Araujo
Luiz,
One way you could do is by using the "Command on Source" and "Command on Target" feature of an ODI procedure:
In Command on Source, you can write query like:
>
select vGET_CD_BASE, vQTD_REG_UPDATE, vETL_DATE from some_configuration_table_containing_n_rows
>
In Command on Target, you can write:
>
DECLARE
CURSOR v_Cur IS
SELECT ROWID KEY_ROW FROM GG_DATA.WRK_SN_DET_ITEM_EXTR_PARC_#vGET_CD_BASE WHERE DT_ETL = TO_DATE('01/01/1900','DD/MM/YYYY') and rownum < #vQTD_REG_UPDATE;
TYPE t_Tabela IS TABLE OF ROWID INDEX BY BINARY_INTEGER;
r_Reg t_Tabela;
BEGIN
OPEN v_Cur;
LOOP
FETCH v_Cur BULK COLLECT INTO r_Reg LIMIT 100000;
FORALL i IN 1..r_Reg.COUNT
UPDATE GG_DATA.WRK_SN_DET_ITEM_EXTR_PARC_#vGET_CD_BASE
SET DT_ETL = TO_DATE('*#vETL_DATE*','DD/MM/YYYY HH24:MI:SS')
WHERE ROWID = r_Reg(i);
EXIT WHEN v_Cur%NOTFOUND;
COMMIT;
END LOOP;
CLOSE v_Cur;
COMMIT;
END;
>
So, for "n" records that are returned by the source query, your PL/SQL package will run "n" times, each time substituting the values of vGET_CD_BASE, vQTD_REG_UPDATE, vETL_DATE respectively.
Similar Messages
-
How to run dynamic SQL from an ODI procedure step
I am on ODI 11.1.1.6.4. From within an ODI IKM step I have no problem running a procedure step like the following which calls a pl/sql procedure to get SQL text then later runs that code. Is there anyway to do the same from within an ODI procedure? I've tried a couple of variations and can not seem to get the parsing levels to resolve within a procedure like they resolve from within a KM step.
<@
/* Setup Java variables */
String out_SQL = "";
try
java.sql.Connection sourceConnection = odiRef.getJDBCConnection("SRC");
String sqltxt = "{call set_sql(?)}";
java.sql.CallableStatement pstmt = sourceConnection.prepareCall(sqltxt);
try
pstmt.registerOutParameter( 1, java.sql.Types.VARCHAR);
pstmt.execute();
out_SQL = pstmt.getString(1);
catch(java.sql.SQLException ex)
errMessage = ex.getMessage();
errMessage = errMessage.replace("'","");
finally
pstmt.close();
catch(java.lang.Exception e)
errMessage = e.getMessage();
errMessage = errMessage.replace("'","");
@>
BEGIN
-- The SQL that I want to run
<@
out.println(out_SQL);
@>
-- Error handling
<@ if ( out_SQL.length() ==0 ) { @>
raise_application_error(-20101, '<@=errMessage@>');
<@ } else { @>
dbms_output.put_line('Successful.');
<@ } @>
END;
------Please understand that I know that I can do this all within PL/SQL -- I am explicitly doing it the way I have outlined because I want to better understand the parsing levels/behavior within ODI procedures and I want to understand why KMs steps behave differently.
Another observation -- putting this all within a pl/sql block prevents ODI from properly capturing insert/update/delete row counts like it would if it were running a SQL statement.
So the question remains -- is there a way to run a dynamic SQL statement in an ODI procedure where the SQL statement is generated from within an Oracle procedure call and then run as SQL within an ODI procedure step? Best would be if there is an example of how this can be done. -
How to call PL/SQL code from ODI
Hello friends,
Can you please let me the steps for calling a pl/sql code in ODI?
Regards
UlhasThis should give you an idea - http://odiexperts.com/?p=666
-
How to use pl/sql code as ODI user defined function
Hi All,
i have a pl/sql code and i want to create ODI user defined function using this code .
please find the pl/sql code below:
============================
declare
v_no_of_duplicate_rec number := 0;
begin
select count(*)
into v_no_of_duplicate_rec
from ( select 1
from temp_pre_selections
group by svb_number, selection_id
having count(*) > 1);
if v_no_of_duplicate_rec = 0 then
return 'N';
else
return 'Y';
end if;
end if;
==========================
please help me how to achieve the same .
Thanks
Vinod2 ways:
a. implement logic in odi function directly: getCount, Oracle implementation:
select case count(1) when 0 then 'N' else 'Y' end
from hr.employees
when you use this function to refresh a variable, the refresh statement should only be getCount, you shoueld not write select getCount from dual, otherwise it will become
select select .... from ... from dual
b. if your logic is complex, I suggest to write function directly in your database, then call this function in your ODI function
eg:
CREATE OR REPLACE FUNCTION hr.test RETURN varchar2 IS
tmpVar NUMBER;
BEGIN
select count(1) into tmpVar from hr.employees;
if tmpVar=0 then
return 'N';
else
return 'Y';
end if;
END test;
then create a ODI function, Oracle implementation is
hr.test
in your variable refresh statement, you can write select getCount from dual
if you use the odi function in other locations expect for refreshing variable, the idea is similar -
Using PL/SQL code in ODI User Functions
Is it possible to write PL/SQL code (with multiple in params and one out param) in ODI User Function ?
Actually I need to use this user functions in my interface mapping.
I know it can be done using ODI Procedures but Procedures cannot be used within interfaces when mapping columns.Hi Anurag Ambasta,
You can use the ODI user functions and choose the Linked technology as 'Oracle' where you can implement and use oracle syntax .
And the user functions can receive the multiple parameters and it returns the single value to the function cal, which use are expecting right?
Thanks,
Yellanki -
Passing parameters into ODI procedure step which has an OS command
Folks,
I have an ODI procedure step which does a directory listing for a specific directory. The command I am using is
cmd /C dir d:\local_dir /b > D:\dir_list.txt
I have put on the 'Command on Target' tab. This works fine
I want to remove the hardcoding for the directory references. I have tried the command
cmd /C dir '#src_dir' /b > D:\dir_list.txt
but when this executes it generates an ODI error 'Wrong process return code'
any suggestions?I've figured it out. The issue was with using quotes in the value being passed into the variable. Once removed, it worked fine. Thanks for the assistance.
Regards.
Edited by: user810644 on 17-May-2010 01:59 -
Executing Java Code in ODI Procedure
Hi All,
I have following java code which i need to write on ODI procedure but i am not sure which technology to chose (Jython,Sunopsis API or Java BeanShell).
I tried to execute the procedure Jyhton with <% "Java code"%> but getting the error.Any boddy can suggest where i doing wrong.
<%
import javax.naming.Context;
import javax.naming.NamingEnumeration;
import javax.naming.directory.*;
import java.util.Hashtable;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
String userName = "HXXXXXX";
String CN1=null;
String Dis_Name=null;
String Mem_of=null;
String Mail=null;
String SGID=null;
File file = new File("C:/Project/ODI/LDAPID.txt");
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "LDAP://XX.if.YYYY.net:389/OU=XYZ,DC=ZZ,DC=if,DC=XYZ,DC=COM");
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, new String("" + "\\" + userName));
env.put(Context.SECURITY_CREDENTIALS, "");
DirContext ctx = null;
NamingEnumeration results = null;
ctx = new InitialDirContext(env);
SearchControls controls = new SearchControls();
controls.setSearchScope(SearchControls.SUBTREE_SCOPE);
results = ctx.search("", "(objectclass=person)", controls);
FileWriter fw = new FileWriter(file.getAbsoluteFile());
BufferedWriter bw = new BufferedWriter(fw);
while (results.hasMore())
SearchResult searchResult = (SearchResult) results.next();
Attributes attributes = searchResult.getAttributes();
Attribute attr = attributes.get("cn");
String cn = (String) attr.get();
CN1=(String.valueOf(attributes.get("cn")));
Dis_Name=(String.valueOf(attributes.get("displayName")));
SGID=(String.valueOf(attributes.get("userPrincipalName")));
Mem_of=(String.valueOf(attributes.get("memberOf")));
Mail=(String.valueOf(attributes.get("mail")));
bw.write(CN1 + " || " + Dis_Name + " || " + SGID + " || " + Mail);
bw.newLine();
bw.close();
results.close();
ctx.close();
%>
I am getting following error.
The application script threw an exception: java.lang.NullPointerException BSF info: CODE_JAVA at line: 0 column: columnNo
Please suggest what went wrong with the code.
Thanks
RegardsIn Jython you don not need to declare the type so String userName = "HXXXXXX"; should simply read userName = "HXXXXXX" . Lots of your code need to be rewritten to work with Jython if you choose that as your technology.
-
How to convert pl/sql code into java/j2ee
Hi,
We have a PL/SQL Oracle App server application that we will support if we can convert in j2ee/java. But when i did take a look at the code, these pl/sql contains all HTML and java code inside the stored procedures.
And iam looking to explore some tools and mechanisms that can convert these pl/sql in a JAVA application so that i can deploy this new app into my BEA81 environment.
Does any body has any idea:
a) How to convert from pl/sql > java ?
b) Any plugins or tools of BEA that can run these pl/sql (the way thay are currently...i.e w/o converting) in BEA 81 container ?
thanks, sangitathese pl/sql contains all HTML and java code insideJava or JavaScript. They are not the same. I wouldn't expect to see Java inside html, whereas JavaScript would be intermixed. On the other hand you might have a java stored proc (Oracle 9/10) which is generating HTML.
>
Does any body has any idea:Refactor.
I doubt it just has html and JavaScript/Java. So what you have is a mess that mixes several things that should have been seperate in the first place. -
Hi! I am a newbie in PL/SQL..
Can somebody teach me on how to make this SQL QUERY into a PROCEDURE?
TABLE 1: LOGS
TABLE 2: MASTER LIST
Logs = records the logs
Master list = list of all registered name.
select * from table1
where not exists
select host, user, name
from table2
where table2.host = table1.host and
table2.user = table1.user and
table2.name = table1.name
TABLE 1
HOST | USER | NAME
==============
1 | A | A1
1 | A | A1
1 | A | A1
1 | A | D1
TABLE 2
HOST | USER | NAME
=============
1 | A | A1
1 | A | B1
1 | A | C1
Result:
HOST | USER | NAME
===============
1 | A | D1
Thanks. :)QKWS wrote:
Hi! I am a newbie in PL/SQL..
Can somebody teach me on how to make this SQL QUERY into a PROCEDURE?
TABLE 1: LOGS
TABLE 2: MASTER LIST
Logs = records the logs
Master list = list of all registered name.
select * from table1
where not exists
select host, user, name
from table2
where table2.host = table1.host and
table2.user = table1.user and
table2.name = table1.name
TABLE 1
HOST | USER | NAME
==============
1 | A | A1
1 | A | A1
1 | A | A1
1 | A | D1
TABLE 2
HOST | USER | NAME
=============
1 | A | A1
1 | A | B1
1 | A | C1
Result:
HOST | USER | NAME
===============
1 | A | D1
Thanks. :)Hi,
Question is not clear, really.
Do you want that, I don't sure?
CREATE TABLE t1 ( CHOST NUMBER, CUSER VARCHAR2(10), CNAME VARCHAR2(10));
INSERT INTO t1 VALUES(1,'A','A1');
INSERT INTO t1 VALUES(1,'A','A1');
INSERT INTO t1 VALUES(1,'A','A1');
INSERT INTO t1 VALUES(1,'A','D1');
Commit;
CREATE TABLE t2 AS SELECT * FROM t1;
INSERT INTO t2 VALUES(1,'A','A1');
INSERT INTO t2 VALUES(1,'A','B1');
INSERT INTO t2 VALUES(1,'A','C1');
commit;
select * from t1 table1
WHERE NOT EXISTS
( SELECT 1 FROM t2 table2
WHERE table2.chost = table1.chost
AND table2.cuser = table1.cUSER
AND table2.cNAME = table1.cNAME
DECLARE
P_HOST T1.CHOST%TYPE;
P_USER T1.CUSER%TYPE;
P_NAME T1.CNAME%TYPE;
BEGIN
select CHOST, CUSER,CNAME INTO P_HOST,P_USER, P_NAME
from t1 table1
WHERE NOT EXISTS
( SELECT 1 FROM t2 table2
WHERE table2.chost = table1.chost
AND table2.cuser = table1.cUSER
AND table2.cNAME = table1.cNAME
dbms_output.put_line('HOST | USER | NAME : '|| TO_CHAR(P_HOST)||' | '||P_USER||' | '||P_NAME);
END;
/Regards
Mahir M. Quluzade -
Hello,
My requirement is to create procedures on the fly and call the created procedures. The pl/sql code for the procedures are stored in the tables. I was able to create the procedure on the fly. But it ended being an invalid object. I got this error
ORA-24344: success with compilation error
Following is my code snippet
DECLARE
proc_str VARCHAR2(20000) := NULL;
v_err_code VARCHAR2 (256) := NULL;
v_err_msg VARCHAR2 (256) := NULL;
BEGIN
FOR cur_pi_proc IN (SELECT sql_query, procedure_name
FROM mas_pi_rules
WHERE ID = 7)
LOOP
proc_str := cur_pi_proc.sql_query ;
EXECUTE IMMEDIATE ''|| proc_str || '';
EXECUTE IMMEDIATE 'ALTER PROCEDURE '|| cur_pi_proc.procedure_name ||' COMPILE';
EXECUTE IMMEDIATE 'CALL "'
|| cur_pi_proc.procedure_name
|| '" ( :p_mode)'
USING 'BATCH';
COMMIT;
END LOOP;
EXCEPTION
WHEN OTHERS
THEN
v_err_msg := SUBSTR (SQLCODE || ':-' || SQLERRM, 1, 200);
INSERT INTO stored_proc_err
(error_origin, error_msg, error_date
VALUES ('test_dynproc', v_err_msg, SYSDATE
COMMIT;
END;
Any help in creating procedures dynamically is greatly appreciated.
regards,
Ravi
Message was edited by:
user611440-- EXECUTE IMMEDIATE '' || proc_str || ''; -- Comment ThisUmm, you've missed the whole and entire point of this thread, which is that the procedure to be run is created dynamically from the source in the table.
The OP's problem (well, their specific problem rather than the more philosophical one) is the way they were running the create statement. Fix that and everything else falls into place...
SQL> create table MAS_PI_RULES ( SQL_QUERY varchar2(4000), PROCEDURE_NAME varchar2(30), ID number)
2 /
Table created.
SQL>
SQL> insert into MAS_PI_RULES
2 values ('CREATE OR REPLACE PROCEDURE REVERSE_STRING (I_STRING IN OUT VARCHAR2) IS L_STRING VARC
HAR2 (400); BEGIN SELECT REVERSE (I_STRING) INTO I_STRING FROM DUAL; END;', 'REVERSE_STRING', 7)
3 /
1 row created.
SQL>
SQL> DECLARE
2 proc_str VARCHAR2 (20000) := NULL;
3 v_err_code VARCHAR2 (256) := NULL;
4 v_err_msg VARCHAR2 (256) := NULL;
5 v_ouput VARCHAR2 (256) := 'ZLLIKS DAM SAH CPA';
6 BEGIN
7 FOR cur_pi_proc IN (SELECT sql_query
8 ,procedure_name
9 FROM mas_pi_rules
10 WHERE ID = 7) LOOP
11 proc_str := cur_pi_proc.sql_query;
12
13 EXECUTE IMMEDIATE proc_str ;
14 EXECUTE IMMEDIATE 'ALTER PROCEDURE ' || cur_pi_proc.procedure_name || ' COMPILE';
15
16 EXECUTE IMMEDIATE 'begin ' || cur_pi_proc.procedure_name || '(:p_mode); end;'
17 USING IN OUT v_ouput;
18
19 COMMIT;
20 END LOOP;
21
22 DBMS_OUTPUT.put_line ('The output is ' || v_ouput);
23 EXCEPTION
24 WHEN OTHERS THEN
25 v_err_msg := SUBSTR (SQLCODE || ':-' || SQLERRM, 1, 200);
26 DBMS_OUTPUT.put_line (v_err_msg);
27 END;
28 /
The output is APC HAS MAD SKILLZ
PL/SQL procedure successfully completed.
SQL> Cheers, APC
Blog : http://radiofreetooting.blogspot.com/ -
Hi All,
I am using Oracle 8i. I have created a dynamic PL/SQL table in my procedure. Now i need to select rows and sort the data in that PL/SQL table. How do i do it? I
I appreciate any help on this.
Thanks,
VijiSQL> select count(1) from emp;
COUNT(1)
14
SQL> create or replace type emp_row is OBJECT
2 (
3 EMPNO NUMBER(4),
4 ENAME VARCHAR2(10),
5 JOB VARCHAR2(9),
6 MGR NUMBER(4),
7 HIREDATE DATE,
8 SAL NUMBER(7,2),
9 COMM NUMBER(7,2),
10 DEPTNO NUMBER(2)
11* )
SQL> /
Type created.
SQL> set serveroutput on
SQL> declare type emp_table is table of emp_row index by binary_integer;
2 plsql_tab emp_table;
3 rec_num number;
4 begin
5 select emp_row(EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO)
6 BULK COLLECT into plsql_tab
7 from scott.emp;
8 select count(1) into rec_num
9 from scott.emp;
10 DBMS_OUTPUT.PUT_LINE(rec_num||' records in SCOTT.EMP');
11 DBMS_OUTPUT.PUT_LINE(plsql_tab.count||' records in plsql_table');
12 end;
13 /
14 records in SCOTT.EMP
14 records in plsql_table
PL/SQL procedure successfully completed. -
How to read I$ table using ODI procedure
Hi
Can any one help me how to drop a I$ table from out sie of interface.
I have tried below approches but no luck
I have created ODI procedure with technology oracle and target logical schema (I$ tables are creating on target DB) with and with out begin and end;
Approch 1:
Given below code in ODi procedure
drop table <%=odiRef.getTable("L", "INT_NAME", "W")%> <% if (new Integer(odiRef.getOption( "COMPATIBLE" )).intValue() >= 10 ) { out.print( "purge" ); }; %>
Approch 2:
drop table I$_<%=odiRef.getTable("L", "TARG_NAME", "A") %>;
Approch 3:
drop table <%=odiRef.getTable("L", "INT_NAME", "W")%> (but it is fetching target dtabase schema anme not I$ table)
Please help me any other alternative way to drop a I$ table, more over this code should be unique for all interface
Regards,
PhanikanthThanks bhabani,
Actaul my requirement is some time my scenario is stoping due some issue at Merge Rows Step (I am using IKM Oracle Incremental Update(Merge) KM) when the next iteration starts it is thwoing and error at create flow table I$ step and error is table name is already exists, so i am doing is if the interface went failed I am storing those information in one table using ODI procedure (INF--ko-->ODI procedure) in same ODI procedure I want to call a I$ table to drop.
Can you please provide the steps so it will very useful for me using Java variable.
I have gievn a step as below on create I$ table step (after create I$ statement)
<@ java.lang.String Idollertable = <%=odiRef.getTable("L", "INT_NAME", "W")%> ; @>
I am calling Idollertable variable in ODI procedure which is ko>* of INF as <@=Idollertable@>
Note: I have followed below approch
ODI Procedure Code:
drop table <@=Idollertable@>; --> *2nd approch*
begin
insert into ODI_EXECUTION_ERROR_DETAILS
(SESSION_NO,
SCENARIO_NAME,
CONTEXT_NAME,
ERR_MESSAGE,
INSERT_COUNT,
ERROR_COUNT)
values
<%=snpRef.getSession("SESS_NO")%>,
'<%=odiRef.getPrevStepLog("STEP_NAME")%>',
'<%=odiRef.getContext( "CTX_NAME" )%>',
'<%=odiRef.getPrevStepLog("MESSAGE")%>',
'<%=odiRef.getPrevStepLog("INSERT_COUNT")%>',
'<%=odiRef.getPrevStepLog("ERROR_COUNT")%>'
commit;
drop table <@=Idollertable@>; --> * first approch *
end;
Please help me
Regards,
Phanikanth
Edited by: Phanikanth on Mar 3, 2013 9:52 PM
Edited by: Phanikanth on Mar 3, 2013 9:52 PM -
PL/SQL Code not working without debug statements
Hi Guys,
I have a pl/sql code in a procedure, logic iterates through almost 40K records, conditional delete and update.
When I execute this code, I dont see the deletes and updates happening, though procedure executes for 8 minutes and exits wihtout any error, execption.
In same procedure when I write some debug statements like dbms_output, then everything seems to be working fine.
I know this scenario happens in Oracle Forms, wehre we use SYNCHRONIZE.
But this is plain pl/sql procedure.
any thoughts on this?
Av.COMMIT ?
Aside from that, no idea what your procedure looks like, what it does, what version of Oracle you are using, how you are determining "I dont see the deletes and updates happening". etc...
You'd need to provide a slew of information for anyone to give you any meaningful help.
I can only assure you that DBMS_OUTPUT doesn't do magic :) -
Hi,
I have made one simple jython code in odi procedure which will read the script file from one location and if there is some error in the script then that error will be displayed in the odi operator.
This work has been done in place of using ODI os command which can call the script from a particular location but cannot revert back with the error in ODI operator.It only shows odi os command return 1.
here is the code:
Step 1 in odi procedure--
import os
from subprocess import Popen
from subprocess import PIPE
ScriptFile = '<%=odiRef.getOption("ScriptFile")%>'.strip()
if (ScriptFile == "") or (os.path.isfile(ScriptFile) == 0):
raise IOError("The script file " + ScriptFile + " does not exist.")
Step 2:
args = [ScriptFile]
#raise IOError(args)
process = Popen(args, stdout=PIPE, stderr=PIPE)
output, oerr = process.communicate()
if (process.returncode != 0):
stdOutString = str(output)
stdErrorString = str(oerr)
raise IOError([stdOutString,stdErrorString])
else:
pass
Here the ScriptFile is the option set in procedure where i am passing the script file location.Yes it was done through that.
One more question is to how we can pass the parameters to this script ?
I need to pass some parameters which will be internally used in the script. -
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.
Maybe you are looking for
-
COPA based Dashboard taking too much time...
Dear All, I have created two DataSources for COPA (1st. 1_CO_PA1001000 Fields: 307 2nd. 1_CO_PA600210913 Fields: 139) and I have four years of historical Data and my Data Flow is like: DataSource ---> DSO ---> InfoCube. Following is the Transforma
-
Itunes will not sync photos to ipad 3 properly
Problems I've had since ipad 3: I download and install latest itunes i tell it to restore from backup of my ipad 2 - it fails, it simply does not give me the choice to pick my ipad 2 restore, so i end up doing new setup. i tell itunes to slectively b
-
Siebel new LDAP adapter integration with BI Publisher
Hi All!! We have configured our Siebel (8.1.1.3) security adapter with LDAP. BI Publisher is using Siebel security model. We had to clone our AOM (fins_esn which is using the security adapter LDAP) to finsxx_esn because we are migrating the AD 2000 t
-
Quicktime mov files aren't playing on Client's computer
Hi. My computer opens & can read the Quicktime movie files that are created through Final Cut Pro from P2 cards. My client's computer cannot. Is that because she doesn't have Quicktime Pro?..or something else? TIA, Heather
-
ATI Radeon 9600 XT & SyncMaster 305T - problems
Hi everyone - I just purchased a 30" Samsung SyncMaster 305T and have been trying to get it to run properly. I have a Dual 1.8 GHz G5 with the ATI Radeon 9600 XT card. The largest resolution it's allowing me to set on the monitor preferences window i