Dynamic PL/SQL binding problem
Hi all,
i have some proble with my pl/sql code. Thisi is the code
DECLARE
Lancio_T VARCHAR2( 1) := 'N';
Rec_Cam VARCHAR2(100) := 'ALL';
BEGIN
str_Sql := ' CREATE TABLE SIEBEL.TEMP_1074_SERVIZI '||
' AS SELECT /*+INDEX (temp IDX_CAROW01)*/ '||
' SA.ROW_ID , '||
' SA.INTEGRATION_ID, '||
' SA.STATUS_CD, '||
' TEMP.* '||
' FROM APP_MASTER_ACCOUNT_NO_CODFISC TEMP, '||
' S_ASSET SA '||
' WHERE 1 = 1 '||
' AND TEMP.STATO = ''OK'' '||
' AND SA.OWNER_ACCNT_ID(+) = TEMP.ROW_ID_CA '||
' AND :1 = ''N'' '||
' AND ROWNUM <= DECODE(:2, ''ALL'', rownum, to_number(:3))';
EXECUTE IMMEDIATE str_Sql USING IN Lancio_T, IN Rec_Cam,IN Rec_Cam;
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.put_line('SqlCode : ' || SQLCODE || ' - DescrError: ' || SUBSTR (SQLERRM, 1, 2000));
END;
When i launch this code in anonymous block, i have this Oracle error: ORA-01027: bind variables not allowed for data definition operations.
Someone can help me pls?
Thanks a lot
Bind variables are allowed only in DMLs.
SQL> create view vdual as select * from dual where dummy=:1;
create view vdual as select * from dual where dummy=:1
ERROR at line 1:
ORA-01027: bind variables not allowed for data definition operationsTry to do some work around without USING clause. May be some thing like
ROWNUM <= DECODE('||Rec_Cam||', ''ALL'', rownum, to_number('||Rec_Cam||'))';
Similar Messages
-
Dynamic Table checkbox binding problem
I have a dynamically created table bound to a objectArrayDataProvider where all the columns have a check box. The thing is when I read the values in the objectArray it has the values as I loaded it. If a checkbox is changed in the table the objectArray dosn't get the change. How can I make this happen?
Thanks in advace.
Azeroth.Hi There,
This should be of help to you
http://developers.sun.com/jscreator/reference/techart/2/checkbox_component.html
Thanks
K -
A challenging dynamic SQL query problem
hi All,
I have a very interesting problem at work:
We have this particular table defined as follows :
CREATE TABLE sales_data (
sales_id NUMBER,
sales_m01 NUMBER,
sales_m02 NUMBER,
sales_m03 NUMBER,
sales_m04 NUMBER,
sales_m05 NUMBER,
sales_m06 NUMBER,
sales_m07 NUMBER,
sales_m08 NUMBER,
sales_m09 NUMBER,
sales_m10 NUMBER,
sales_m11 NUMBER,
sales_m12 NUMBER,
sales_prior_yr NUMBER );
The columns 'sales_m01 ..... sales_m12' represents aggregated monthly sales, in which 'sales_m01' translates to 'sales for the month of january, january being the first month, 'sales_m02' sales for the month of february, and so on.
The problem I face is that we have a project which requires that a parameter be passed to a stored procedure which stands for the month number which is then used to build a SQL query with the following required field aggregations, which depends on the parameter passed :
Sample 1 : parameter input: 4
Dynamically-built SQL query should be :
SELECT
SUM(sales_m04) as CURRENT_SALES,
SUM(sales_m01+sales_m02+sales_m03+sales_m04) SALES_YTD
FROM
sales_data
WHERE
sales_id = '0599768';
Sample 2 : parameter input: 8
Dynamically-built SQL query should be :
SELECT
SUM(sales_m08) as CURRENT_SALES,
SUM(sales_m01+sales_m02+sales_m03+sales_m04+
sales_m05+sales_m06+sales_m07+sales_m08) SALES_YTD
FROM
sales_data
WHERE
sales_id = '0599768';
So in a sense, the contents of SUM(sales_m01 ....n) would vary depending on the parameter passed, which should be a number between 1 .. 12 which corresponds to a month, which in turn corresponds to an actual field range on the table itself. The resulting dynamic query should only aggregate those columns/fields in the table which falls within the range given by the input parameter and disregards all the remaining columns/fields.
Any solution is greatly appreciated.
Thanks.Hi another simpler approach is using decode
try like this
SQL> CREATE TABLE sales_data (
2 sales_id NUMBER,
3 sales_m01 NUMBER,
4 sales_m02 NUMBER,
5 sales_m03 NUMBER,
6 sales_m04 NUMBER,
7 sales_m05 NUMBER,
8 sales_m06 NUMBER,
9 sales_m07 NUMBER,
10 sales_m08 NUMBER,
11 sales_m09 NUMBER,
12 sales_m10 NUMBER,
13 sales_m11 NUMBER,
14 sales_m12 NUMBER,
15 sales_prior_yr NUMBER );
Table created.
SQL> select * from sales_data;
SALES_ID SALES_M01 SALES_M02 SALES_M03 SALES_M04 SALES_M05 SALES_M06 SALES_M07 SALES_M08 SALES_M09 SALES_M10 SALES_M11 SALES_M12 SALES_PRIOR_YR
1 124 123 145 146 124 126 178 189 456 235 234 789 19878
2 124 123 145 146 124 126 178 189 456 235 234 789 19878
1 100 200 300 400 500 150 250 350 450 550 600 700 10000
1 101 201 301 401 501 151 251 351 451 551 601 701 10000----now for your requirement. see below query if there is some problem then tell.
SQL> SELECT sum(sales_m&input_data), DECODE (&input_data,
2 1, SUM (sales_m01),
3 2, SUM (sales_m01 + sales_m02),
4 3, SUM (sales_m01 + sales_m02 + sales_m03),
5 4, SUM (sales_m01 + sales_m02 + sales_m03 + sales_m04),
6 5, SUM (sales_m01 + sales_m02 + sales_m03 + sales_m04 + sales_m05),
7 6, SUM (sales_m01 + sales_m02 + sales_m03 + sales_m04+sales_m05+sales_m06),
8 7, SUM (sales_m01 + sales_m02 + sales_m03 + sales_m04+sales_m05+sales_m06+sales_m07),
9 8, SUM (sales_m01 + sales_m02 + sales_m03 + sales_m04+sales_m05+sales_m06+sales_m07+sales_m08),
10 9, SUM (sales_m01 + sales_m02 + sales_m03 + sales_m04+sales_m05+sales_m06+sales_m07+sales_m08+sales_m09),
11 10,SUM (sales_m01 + sales_m02 + sales_m03 + sales_m04+sales_m05+sales_m06+sales_m07+sales_m08+sales_m09+sales_m10),
12 11,SUM (sales_m01 + sales_m02 + sales_m03 + sales_m04+sales_m05+sales_m06+sales_m07+sales_m08+sales_m09+sales_m10+sales_m11),
13 12,SUM (sales_m01 + sales_m02 + sales_m03 + sales_m04+sales_m05+sales_m06+sales_m07+sales_m08+sales_m09+sales_m10+sales_m11+sales_m12)
14 ) total
15 FROM sales_data
16 WHERE sales_id = 1;
Enter value for input_data: 08
Enter value for input_data: 08
old 1: SELECT sum(sales_m&input_data), DECODE (&input_data,
new 1: SELECT sum(sales_m08), DECODE (08,
SUM(SALES_M08) TOTAL
890 5663 -
How to write dynamic pl/sql in oracle8.0.5
In oracle8.0.5
I write the following dynamic pl/sql:
PROCEDURE "DELETESOMEYEARALLRECORDS" (tablename IN VARCHAR2,someyear IN VARCHAR2,commitcount IN INTEGER) IS
stmt VARCHAR2(500);
mid_stmt VARCHAR2(200);
end_stmt VARCHAR2(200);
count1 INTEGER:=0;
cursor_handle INTEGER;
BEGIN
/* Create a cursor to use for the dynamic SQL */
cursor_handle := DBMS_SQL.OPEN_CURSOR;
stmt:='SELECT COUNT(*) INTO count1 FROM ';
IF UPPER(tablename)='EOP_PRICE_REPORT' OR UPPER(tablename)='EOP_MCTO'
OR UPPER(tablename)='EOP_EXCHANGERATE' THEN
end_stmt:=' WHERE year =:v1 ';
ELSE
end_stmt:=' WHERE opyear =:v1 ';
END IF;
stmt:=stmt||UPPER(tablename)||end_stmt;
-- EXECUTE IMMEDIATE stmt INTO count1 USING someyear;
DBMS_SQL.PARSE(cursor_handle,stmt,DBMS_SQL.NATIVE);
-- DBMS_SQL.BIND_VARIABLE(cursor_handle, 'v0', tablename);
DBMS_SQL.BIND_VARIABLE(cursor_handle, 'v1', someyear);
DBMS_SQL.EXECUTE(cursor_handle);
The message is :
Error at line** ,column**
PLS-00221:'EXECUTE' is not a procedure or is undefined
How to solve this problem,
Anyone helps me ,ThanksPROCEDURE "DELETESOMEYEARALLRECORDS"
(tablename IN VARCHAR2,
someyear IN VARCHAR2,
commitcount IN INTEGER) IS
stmt VARCHAR2(500);
mid_stmt VARCHAR2(200);
end_stmt VARCHAR2(200);
count1 INTEGER:=0;
-- how I would define and open the cursor
Cursor_Handle integer default dbms_sql.open_cursor;
BEGIN
/* Create a cursor to use for the dynamic SQL */
-- You do NOT select INTO when using dynamic Sql
stmt:='SELECT COUNT(*) FROM ' || TableName ;
IF UPPER(tablename)='EOP_PRICE_REPORT'
OR UPPER(tablename)='EOP_MCTO'
OR UPPER(tablename)='EOP_EXCHANGERATE' THEN
end_stmt:=' WHERE year =:v1 ';
ELSE
end_stmt:=' WHERE opyear =:v1 ';
END IF;
stmt:=stmt || end_stmt;
DBMS_SQL.PARSE(Cursor_Handle,stmt,DBMS_SQL.NATIVE);
-- BIND to exactly the same variable
DBMS_SQL.BIND_VARIABLE(Cursor_Handle, ':v1', someyear);
-- you need to define the into column
dbms_sql.define_column( Cursor_Handle, 1, Count1 );
DBMS_SQL.EXECUTE(Cursor_Handle);
-- after executing you need to fetch the row
-- and do not forget to close the cursor
if ( dbms_sql.fetch_rows(Cursor_Handle) > 0 ) then
dbms_sql.column_value(Cursor_Handle, 1, Count1 );
end if;
dbms_sql.close_cursor(Cursor_Handle);
... -
How to validate column name in dynamic made sql?
Oracle db, jdbc, web app with struts2/spring.
Example table could be this:
CREATE TABLE album
album_id number(10) not null,
artist varchar2(50) not null,
title varchar2(50) not null,
released DATE,
CONSTRAINT album_pk PRIMARY KEY (album_id)
);In may app the user MAY search, MAY sort, and the result from an select might return 10.000 rows.
The basic sql usually look like this.
String sql = "select album_id, artist, title, released from album";Then in the html page the user can add search criteria for each column. Like type "iron maiden" in artist field, put "1982" in released field. And you all know what the exceptionally result should be from that :)
Now I need to modify the sql a bit:
if( artist search field contains stuff )
sql = sql + " where nvl( artist,' ') like ?"
}we try use prepared statements right? So we use ? as placeholders, and then add "iron maiden" into this statement later on.
Nice, no big fuzz right, and pretty safe from sql injections i guess.
But now I have to have an if/else for every single field in the table. Boring. In my app I got like 25 tables like this, with 20 columns minimum. Copy/Paste have never been so boring.
I also might have to add "order by" with user selected columns and their order. I have to count the query to get total result in case i got to split it up in pages. So there is alot of if/else and sql = sql + "more stuff", and sticking to ? and pure prepared statements is impossible.
But doing this is not good either:
for( each element in a map)
sql = sql + " and nvl( " + key + ",' ') like ?"
}Where key is "artist".
In struts and other tag libs its easy to make kode like:
<s:textfield name="model.addSearch( 'artist' )" value="%{model.getSearch( 'artist' )}" size="30" />
Silly example maybe, but just to make a point.
Inputed values in an html form, can very easily be a part of a dynamic created sql - which becomes a security problem later on.
Artist is an column name. Key should be validated if it contained an valid column name.
I could make a list of strings, containing valid column names to check against.
My question is if there is possible to get this type of information from the database, so I don't have to hand-make these lists?
But I also want to keep the number of heavy and slowing queries down.
My app have like 25 tables now, and I could easily get away with hand-make everything, copy/paste around etc. But I have more projects and this question will be here next time too. And after there again...Etharo wrote:
Metadata. Then I have to query the database, take the result and use it for validating of input. If my sql only query 1 table, then this is ok. In this case I could do with that. But if the sql query mutliple tables, with sub-selects, unions etc. Then I might have to query all tables first, and even then I might not have what I want.
The best way is of course to run the query, then get the metadata from that query - cause then im 100% sure what columns will be returned, and then I can validate with that.... 1 query is often not that slow. But I might query once to find total number of rows the query return in order to decide if we need to page the result. then query to get the metadata for validating input, then query to get the result... Maybe this is ok -but my head don't like it as an general ok thing to do, but I can't really say why...If you have a gui screen then it needs to correspond to some specific query. It can't be all possible combinations.
So once you know the query you can obtain the meta data using a query that returns no results. Like the following.
select * from mytable wheren 1 = 0
>
Jschell:
I agree to what you say. I don't understood everything you said tho.
Im not sure if you talk about having 1 search field (like google), and you input stuff there that might be in any columns.
I have several search fields in one-to-one relasionship with view column/sql query column.
Then you already know what the field represents. So validate it in the gui and not via the database.
The first is way more advanced since you have to cover any input, any column, any case etc. Pluss add ranking. Lots of work for someone who have done little searchengines.
Latter is simpler, but might also be limiting.Huh?
As an example if you have a call center then the operators are not going to be doing unrestricted searches to find customers. They are going to look using a very limited set of data like the customer name and telephone number.
>
My job is very much like an consulent. They got an app, I shall add a new feature. The app is old and ugly coded. My boss ask how long it takes to make this, I say 2months, he decide 1 month. My dev time for features is rarely above 1 month, and I don't make much new apps.
So I don't have the time to make advanced codegenerator, or spend time to evaluate various frameworks. Bringing an framework into the existing code is actually difficult. But I do want to improve the code, and add good code into the existing app that can be extended without evil pain.
That doesn't jive with your OP. You made the following statement "My app have like 25 tables now, and I could easily get away with hand-make everything,...".
That suggests that you are doing much more than simply updating an existing application.
If you only need to add one new field then you should do only that. You shouldn't be attempting to add a system spanning validation system.
On the other hand if you are in fact adding a validation system, then code generation makes it likely that it would take less time or no more than the same. And it is less likely to introduce bugs.
Learn how to make an code generator? Well I guess thats what I asked help for - point me in the right direction if you could pls. Putting strings together to become code in an logic way is usually manageable, at least for simple querys. Evaluating that the generated code is good/safe - got no good clues...
Learn about frameworks? Got no time. Hope I will get the time, but I won't. The customer must want to spend the money so I can get the time, that won't happen cause an framework does not add features, its only cost saving in terms of dev time, and maintenance time. The customer have no such focus/interest. They got a bit money to spend now and then regularily. i.e. government.
I just want to try code as good as possible so I save myself from errors, painfull rewrites, and dev-time that gets out of proportions because of stupid code. So the question is actually about me trying to improve myself, its just that i don't know how right now.There are two goals.
1. Implement a specific feature in an existing application.
2. Learn a new way to solve problems.
Nothing says that the second will help with the first. They should be addressed separately and your post doesn't make it clear what the first is so it is hard to say how it should be down.
As for the second I already made a suggestion which provides two new ways to solve problems. -
Dynamically Pass sql query in Database adapter
hi',
How can we dynamically pass sql query in Database adapter, is there any way, I am using SOA 11G.
Thanks
YatanHi,
Tried that too. No luck. Gives me this.
The selected operation process could not be invoked.
An exception occured while invoking the webservice operation. Please see logs for more details.
oracle.sysman.emSDK.webservices.wsdlapi.SoapTestException: Exception occured when binding was invoked.
Exception occured during invocation of JCA binding: "JCA Binding execute of Reference operation 'selectUsingIn' failed due to: Pure SQL Exception.
Pure SQL Execute of select interface_id, property_name, property_value from ( (?) ) failed.
Caused by java.sql.SQLSyntaxErrorException: ORA-00903: invalid table name
The invoked JCA adapter raised a resource exception.
Please examine the above error message carefully to determine a resolution.
Regards,
Neeraj Sehgal -
Dynamic pl/sql in pro*c/c++
I have a stored procedure to query and will receive a result by it....
I used the dbms_sql package to give name of the table at run-time
then it runs in sql*plus well...
but If i called it in pro*c/c++, it would not return result...
This is my examples..
(1) stored procedure
CREATE OR REPLACE PACKAGE XDMS_STORE_PKG
IS
PROCEDURE isExistInstance(table_name IN VARCHAR2, url IN VARCHAR2, num OUT N
UMBER);
END XDMS_STORE_PKG;
CREATE OR REPLACE PACKAGE BODY XDMS_STORE_PKG IS
PROCEDURE isExistInstance (table_name IN VARCHAR2, url IN VARCHAR2, num OUT NUMBER)
IS
cursor1 integer;
rows_processed integer;
tmp NUMBER;
tmp_char VARCHAR2(10);
BEGIN
cursor1 := dbms_sql.open_cursor;
dbms_sql.parse (cursor1, 'SELECT count(*) FROM ' | | table_name | | ' WHERE DocURL = ' | | ':x', dbms_sql.v7);
dbms_sql.bind_variable(cursor1, 'x', url);
dbms_sql.define_column (cursor1, 1, tmp);
rows_processed := dbms_sql.execute (cursor1);
loop
if dbms_sql.fetch_rows (cursor1) > 0 then
dbms_sql.column_value (cursor1, 1, tmp);
num := tmp;
else
exit;
end if;
end loop;
dbms_sql.close_cursor (cursor1);
EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line(sqlerrm);
if dbms_sql.is_open (cursor1) then
dbms_sql.close_cursor (cursor1);
end if;
END isExistInstance;
END XDMS_STORE_PKG;
(2) In the sqlplus
set serveroutput on;
DECLARE
cnt NUMBER;
dtdid VARCHAR2(10) := 'DT_AAAAC';
url VARCHAR2(200) := 'http://www.ce.cnu.ac.kr/~xdms/data/personnel.xml';
BEGIN
XDMS_STORE_PKG.isExistInstance(dtdid, url, cnt);
dbms_output.put_line(to_char(cnt));
END;
(3) In the pro*c/c++
bool StorageManager::isExistInstance(char *this_url)
EXEC SQL BEGIN DECLARE SECTION;
int count = 0;
char dtdid[6];
char url[200];
EXEC SQL END DECLARE SECTION;
if(isNewDtd) return false;
sprintf(dtdid, "DT_%s", this_dtdid);
strcpy(url, this_url);
EXEC SQL EXECUTE
BEGIN
XDMS_STORE_PKG.isExistInstance(:dtdid, :url, :count);
END;
END-EXEC;
if(count < 1) return false;
else return true;
thanks...
nullThis is tough it seems. However here are a few thoughts if they can help:
- Generate(build) a dynamic pl/sql block like :
Begin
Your Procedure Name
End;
keep building this piece of code for each one of your procedures in C or C++. And then execute it as any PL/sql code in the form of a 'constructed' string. Pro*C also has DEscribe Using BInd, but i do not know if that can help. -
Hi everyone,
I am having difficulty in creating a query that uses a LIKE keyword for an application in htmldb.
eg:
DECLARE
q varchar2(4000);
BEGIN
q := 'SELECT * FROM MY_TABLE';
IF :P15_MY_ITEM IS NOT NULL THEN
q:= 'WHERE MY_COLUMN LIKE ' '& ' || :P15_MY_ITEM ||' ' ' ';
END IF;
return q;
END;
For some reason, i cannot parse the 'WHERE MY_COLUMN LIKE. . . . ' in the dynamic PL/SQL query that I am trying to create.
Please advise how should I write the WHERE condition.
Thanks!q:= 'WHERE MY_COLUMN LIKE ' '& ' || :P15_MY_ITEM ||' ' ' ';where will this query be executed?
leave a space before the where.
use % instead of &.
try using bind variables instead of concatenating the value like that. -
Dynamic pl/sql - Error -911: ORA-00911: invalid character
This is the first time I am using dynamic pl/sql for self education. I am getting
Error -911: ORA-00911: invalid character
Here is my code;
PROCEDURE DYNAMIC_SQL (table_name in varchar2,
column1 in varchar2,
column2 in varchar2,
v_no out number)
is
dyn_cur integer;
v_table varchar2(2000);
v_field1 varchar2(20);
v_field2 varchar2(20);
v_select varchar2(2000);
v_cursor integer;
begin
DBMS_OUTPUT.enable;
dyn_cur := DBMS_SQL.open_cursor;
v_table := table_name;
v_field1 := column1;
v_field2 := column2;
v_select := 'select '| |v_field1| |','| |
v_field2| |' from '| |v_table;
DBMS_SQL.parse(dyn_cur,v_select,DBMS_SQL.V7);
v_no := DBMS_SQL.execute(dyn_cur);
DBMS_OUTPUT.put_line(v_select);
end;
ANY IDEAS????
Mayur
Thanx
nullHi Mayur,
I don't exatly know your problem. It seems the syntax is correct. I too got the similar error when I was writing PL/SQL script few years ago. That time after few rounds of investigations, I found that I copied the code from some editor, due to which certain characters are not identified by Oracle. So just retype the code in any editor like (notepad, PF Editor) and compile.
I think this may solve problem.
Cheers!!
r@m@ -
Render Dynamic PL/SQL region as PDF?
Hi!
I would like to be able to render a Dynamic PL/SQL region as a PDF. Anybody have an idea how to do this or even if it can be done? This is not a report region.
Also any idea's on how I might do pagination in a dynamic PL/SQL region?
Any hope that a future version of APEX will accept lines from a PL/SQL function (including anonymous ones) as the source of a report region? It would need to preserve blank lines. Currently only select statements are valid for generating APEX reports.
Thanks in advance for your help!
Dave VenusScott,
This is what is what debug mode puts out just before it issues the data not found error:
0.07: ...Process "create collection": PLSQL (ON_SUBMIT_BEFORE_COMPUTATION) -- -- Create Collections -- -- declare la_cks apex_application_global.vc_arr2; begin if apex_application.g_f19.count > 0 then -- wwv_flow.debug('count gt 0 for checksum'); la_cks := apex_application.g_f19; else
0.09: Encountered unhandled exception in process type PLSQL
0.09: Show ERROR page...
0.09: Performing rollback...
I was hoping that the wwv_flow.debug statements would help me figure out where the error was occurring, but they did not produce anything so I commented them out. One thing that might be useful is that when I am not in debug mode and I click the OK link after the Oracle error message, the repainted screen still has the checkboxes that have been marked so I am guessing the error handler can see the data that I put into the .g_fnn arrays within my pl/sql region code.
In other tabular forms within the same application, the create collection code starts the same way and I do not have any problems.
One of the tests I did this morning was to replace my reference to the fcs array with f19 just in case there was something special being done for checksums, but the change had no effect.
thanks,
Peter -
Dynamically change the binding of a field
Hi,
I've been looking all over the internet for 2 days to find the answer to my question, but I couldn't get any information on my problem. Here's what i'm trying to do :
Based on a checkbox in my form, I want to export or I don't want to export a field to a XML document.
My checkbox is working properly and I got the Send button with the XML working too. I only need to find a way to dynamically change the binding property of my field. I've read some informations with the ".bind.match", but I can't seem to make it work.
I'm using Windows XP, LiveCycle Designer ES2 v.9.0 and I have to run the form in Reader 8.0.
Thanks alot for your help, it's greatly appreciated.
JonathanHi,
the binding cannot be changed at runtime.
You can use the checkbox to delete the value of the field so the exported xml contains an empty tag.
Or you try to delete the data node of the desired field in the data DOM (xfa.datasets). -
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. -
Applying a Template to a Dynamic PL/SQL Report
I have an application in which there are several reports, all based on the wizard and using standard templates.
One of my reports, however is a Dynamic PL/SQL Report, using htp.print statements to create the output.
I'm not quite sure, how I can specify that I want to use the same template as the rest of my reports, so as to maintain the look and feel of the whole application.
Can someone tell me how this is done, or where I can read about it?
Thank you.Sergio,
I have a table with two columns I want to display. The columns aren't wide but there are 15 or 20 rows. What I would like is that after 10 rows the report starts another set of colums beside the first ones. The standard report continues on down so you have to scroll down to see the bottom. I'm not sure if my explanation is clear so instead of:
1 info1
2 info2
3 info3
4 info4
5 info5
6 info6
I want:
1 info1 4 info4
2 info2 5 info5
3 info3 6 info6
Not being too picky, it could also be:
1 info1 2 info2
3 info3 4 info4
5 info5 6 info6
I don't see a way of doing this with standard reporting so a PL/SQL report seems to be the way to go (which works fine except for the formatting). Sorry if I've just missed it in the options. I'd prefer to do it using standard HTMLDB
Thanks.
Paul -
Dynamically change the Binding of a view object
I want to reuse a panel several times in my application. The VO has one bind parameter (:1). The same panel should be reused several times with different bind variables.
I found a technical note concerning this issue called: How to Dynamically Change the binding of a View Object to a JClient Panel. This works for JDeveloper 9i but not for JDeveloper 19g. Does anybody know how to dynamically change the binding in JDeveloper 10gYou may use bindRowSetIterator() and pass in a custom fetched ViewObject or a RowSetIterator to the iterator binding that is displayed in your panel.
-
NEED HELP IN SQL HOMEWORK PROBLEMS
I NEED HELP IN MY SQL HOMEWORK PROBLEMS....
I CAN SEND IT VIA EMAIL ATTACHMENT IN MSWORD....Try this:
SELECT SUBSTR( TN,
DECODE(LEVEL, 1, 1, INSTR(TN, '#', 1, LEVEL-1) + 1),
DECODE( INSTR(TN, '#', 1, LEVEL) , 0 ,
LENGTH(TN) + 1, INSTR(TN, '#', 1, LEVEL) )
- DECODE(LEVEL, 1, 1, INSTR(TN, '#', 1, LEVEL-1 ) + 1)
) xxx
FROM (
SELECT '234123#1254343#909823#908232#12345' TN FROM DUAL
CONNECT BY LEVEL <= LENGTH(TN) - LENGTH(REPLACE(TN,'#')) + 1
XXX
234123
1254343
909823
908232
12345
SELECT regexp_substr(tn, '[^#]+', 1, level) xx
FROM (
SELECT '234123#1254343#909823#908232#12345' TN FROM DUAL
CONNECT BY LEVEL <= LENGTH(TN) - LENGTH(REPLACE(TN,'#')) + 1
XX
234123
1254343
909823
908232
12345
Maybe you are looking for
-
I cannot listen to music that I purchased from I tunes years ago, using various email accounts, and various computers. I no longer have those email accounts, so I cannot access the password retrieval from them. I also tried the security questions,
-
Recently did an update of itunes and now it wont open
it also wont reinstall or repair just constant pop ups telling me its not working what can i do without deleting all my music?!
-
File Copy to Clipboard includes path - how to avoid
I'm writing an Automator action that does several actions to whatever file in the Finder is selected (or right-clicked). The first action in the Automator action is Copy To Clipboard. This works, however, it copies the entire absolute path of the fil
-
Preferences not opening after asking for restart
As we all know, when using 3rd party preferences panes the preferences asks you to restart (I think to go into 32/63-bit mode) But when I press ok, it quits then doesn't open again, It's extremely annoying and cripples my productivity and use of this
-
Since upgrading to firefox 5.0, countdown timers at the various file locker sites will no longer countdown when the page is not the active page. I am sure it is not a site-side change as ALL the sites countdown timers freeze when not the active page.