SQL function help
Hi, I am trying to write a sql query to replace the string starting with '<' with NULL. Right now I am using CASE statement to replace with NULLs. Is there any function to replace with NULLs for all the strings starting with '<%'.
Example:
CASE When field_name LIKE '<%' then NULL else field_name
(before) After
<NA> NULL
<UK> NULL
I want to replace the above sql suery with a single sql function without using CASE statements.
I tried to use REPLACE function, but it replaces only single character. I want to replace the whole string
Thanks in advance.
Hi,
Adam Martin posted a good solution. I hope that it is clear to you that you have to replace the string '<NA>' with your column(s).
I.e.:
SELECT REGEXP_REPLACE (a.col1, '^<.?+', '') AS col1
, REGEXP_REPLACE (a.col2, '^<.?+', '') AS col2
FROM table1 a;
{code}
You can use also the DECODE and SUBSTR functions to have the same result:
The code below will get the first character with SUBSTR function and the DECODE function will return NULL if the value of the first character is "<" otherwise the value of the column.
{code:sql}
SELECT DECODE(SUBSTR(a.col1,1,1),'<', NULL, a.col1) AS col1
, DECODE(SUBSTR(a.col2,1,1),'<', NULL, a.col2) AS col2
FROM table1 a;
{code}
but using REGEXP_REPLACE is easier to write.
Similar Messages
-
PL/SQL Function Help (
Does anyone know how to pass a table name to a function as a variable so that the function can act dynamically on that table? Here is an example of a very simple function that I can not seem to get to work.
create or replace function DATE_TIME_CHECK (Name_of_Table IN varchar2)
RETURN DATE
IS
table_update_date date;
begin
select trunc(max(last_update_date),'MI')
into table_update_date
from Name_of_Table;
RETURN (table_update_date);
end;
/Try using DBMS_SQL functions and
functionality to achieve this.
null -
Calling pl/sql function in CKM...pls help
Hi,
I have made a call to PL/SQL function in CKM customization. The code is :
declare
L_PMG_VALUE VARCHAR(3);
begin
L_PMG_VALUE:='PMG';
VALIDATE_PMG_VALUE(L_PMG_VALUE);
end;
When i run it, it throws error which says:
6550 : 65000 : java.sql.SQLException: ORA-06550: line 1, column 64:
PLS-00221: 'VALIDATE_PMG_VALUE' is not a procedure or is undefined
ORA-06550: line 1, column 64:
PL/SQL: Statement ignored
Function is compiled in the database and its working. I have selected the Technology as Oracle and correct Schema Name.
Please helpHi,
try the following way. i have not tried ....i think it helps you.
In which schema you have created that procedure.
Does the ODI user mantioned in topology have execute permissions on the procedure? if the ODI user have execute previlage on the procedure then in CKM customisation call the procedure like <schema>.<procedure>.
Please let me know any issues.
Thanks, -
Help w/MaxDB Function; also: how does the "Debug SQL" function work?
Hi there forum folks,
In my former life, I was a Basis guy, but I haven't had the pleasure of working directly with SAP applications in a few months. My current project is to attempt to use MaxDB in a real estate environment. We're tracking home listings so that we can build statistical reports... such as "what agents are in the Top 100 in postal code X?"
Anyway, as part of this project, I have attempted to construct my very first MaxDB database function. Unfortunately, it doesn't give me the answers I'm hoping to see. Here's the function:
CREATE FUNCTION COUNT_LISTINGS (AGENTID CHAR(10)) RETURNS FIXED(6,1) AS
VAR COLISTINGAGENTID CHAR(10);
LISTINGAGENTID CHAR(10);
MLSNUMBER CHAR(7);
UNITS FIXED(6,1);
SET UNITS = 0;
DECLARE FUNCTIONRESULT CURSOR FOR
SELECT MLSNUMBER,
LISTINGAGENTID,
COLISTINGAGENTID FROM FREDDIE.GLAR_SOLDS
WHERE LISTINGAGENTID = :agentid OR COLISTINGAGENTID = :agentid;
IF $COUNT IS NULL THEN
BEGIN
CLOSE FUNCTIONRESULT;
RETURN UNITS;
END
ELSE
SET $RC = 0;
WHILE $RC = 0 DO BEGIN
FETCH FUNCTIONRESULT INTO :mlsnumber, :listingagentid, :colistingagentid;
IF ( LISTINGAGENTID = AGENTID AND COLISTINGAGENTID IS NULL ) OR
( COLISTINGAGENTID = AGENTID AND LISTINGAGENTID IS NULL ) THEN
SET UNITS = UNITS + 1
ELSE
SET UNITS = UNITS + 0.5;
END;
CLOSE FUNCTIONRESULT;
RETURN UNITS;
I've tried to follow the official MaxDB documentation. My first deviation from that standard was the use of the "$COUNT" variable (instead of the "$RC" variable) immediately after the DECLARE/SELECT statement above. When I tried to use $RC, for either a successful or unsuccessful query, $RC was always set to a non-zero value.
I believe I'm past that, but now my issue is down around that FETCH statement. The UNITS variable doesn't end up with the value I expect. I know that it can be terribly confusing to try to analyze someone else's logic, but here's a brief narrative that describes what I'm trying to do...
The GLAR_SOLDS table holds one line for each home sold. It's keyed by the MLSnumber. Each record also stores up to four agents who've been involved in the transaction: the listing agent, the co-listing agent, the selling agent, and the co-selling agent. The database function I've written above pertains to the listing side only. If I can get this to work, a separate function will process the selling side. If no co-listing agent is involved in a given sell, that agent should get credit for 1 unit sold. If he/she has help from a co-listing agent, the agent should only get credit for 1/2 unit sold.
Also, does anyone know how the "Debug SQL" functionality is supposed to work within Database Studio? When I right-mouse click on my function, and follow the path thru "Debug As...", after entering the connection & function arguments, I'm presented with an empty screen. If you could point me to some documentation somewhere, I'd gratefully read it.
I'm using MaxDB 7.7.06.09 on Windows XP (WIN32) with MaxDB Database Studio 7.7.06.09 (build 009-123-202-944).
Thanks everyone for your help & advice.
~FredFred,
please either provide the full SQL statements for your example or stick with mine.
I'm not going to build it up myself a second time to suit yours now.
> But now, my issue is how do I store the resultant data in its own table?
So where is the problem?
INSERT INTO <target table> (field 1, field 2, ...) (<your query>) UDPATE DUPLICATES-
With my tables this looks like this:
create table sell_result (list_agent varchar(20) primary key, SUM_CREDIT fixed (10,2))
insert
into sell_result (list_agent,sum_credit)
( select list_agent, sum (credit) as SUM_CREDIT
from ( select sh.object_id,lag.name as list_agent, 1 as credit
from soldhomes sh join agents lag on lag.id = sh.list_agent_id
union all
select sh.object_id, lag.name as list_coagent, 0.5 as credit
from soldhomes sh join agents lag on lag.id = sh.list_coagent_id
group by list_agent
update duplicates
Check what we have now
sqlcli db770=> select * from sell_result
| LIST_AGENT | SUM_CREDIT |
| -------------------- | ----------------- |
| Lars | 4.50 |
| Lisa | 3.00 |
| Mona | 2.50 |
| Paul | 2.50 |
4 rows selected (600 usec)
Now add some sales data...
Insert into soldhomes values (11, 1, 2, NULL, NULL)
Insert into soldhomes values (12, 2, NULL, NULL, NULL)
Insert into soldhomes values (13, 2, NULL, NULL, NULL)
Re-run the INSERT command and you're done:
sqlcli db770=> select * from sell_result
| LIST_AGENT | SUM_CREDIT |
| -------------------- | ----------------- |
| Lars | 5.50 |
| Lisa | 3.00 |
| Mona | 5.00 |
| Paul | 2.50 |
4 rows selected (390 usec)
Neat, isn't it? -
LOOP in PL/SQL Function Body Help Needed
I have a PL/SQL function that I'm trying to run and use a LOOP but I'm having some problems. I know the loop works since it output's two commas for me, which is how many records the query used for the LOOP returns, but I can't seem to find the right syntax to reference the column.
DECLARE
str VARCHAR2(2000) := "";
BEGIN
IF :P21_GLOBAL_ID IS NOT NULL THEN
FOR q IN (
SELECT
ID,
DRAW_DATE,
ENTERED_BY
FROM
SAMPLE_T
WHERE
ID = :P21_GLOBAL_ID
ORDER BY
DRAW_DATE
LOOP
str := str || q.ID || ',' ;
END LOOP;
END IF;
RETURN STR
END;I just sent you the credentials.
Interestingly, I have this same code for the source of a textarea on the page and the source for a report. I then modified the PL/SQL code as follows:
DECLARE
varSelect VARCHAR2(32767) := ''; --hold query SELECT definition
varFrom VARCHAR2(32767) := ''; --hold query FROM clause definition
varWhere VARCHAR2(32767) := ''; --hold query WHERE clause definition
varOrderBy VARCHAR2(32767) := ''; --hold query ORDER BY clause definition
varQuery VARCHAR2(32767) := ''; --hold query definition
BEGIN
IF TRIM(LOWER(TO_NUMBER(:P21_GLOBAL_TEMPLATE_ID))) IS NOT NULL THEN
varSelect := 'SELECT SUBJECT_ID';
varSelect := varSelect || ', SUBJECT_ID AS PHI';
varSelect := varSelect || ', SUBJECT_ID AS ENTER_DATA';
varSelect := varSelect || ', SUBJECT_ID AS LOGISTICA';
for varTempQuery IN (
SELECT
stc.question_name as field_name,
sti.read_security,
sti.write_security,
nvl(sti.validation_type,decode(stc.validation_rules,'None','TEXT_FIELD')) as validation_type,
sti.html_caption,
nvl(upper(sti.html_display_type),'TEXTFIELD') as html_display_type,
sti.html_table_row,
sti.html_table_column
FROM
rix.study_subject_templates sst,
rix.study_subject_Template_items sti,
rix.questions stc
WHERE
TRIM(LOWER(TO_NUMBER(sst.ss_template_Id))) = TRIM(LOWER(TO_NUMBER(:P21_GLOBAL_TEMPLATE_ID)))
AND TRIM(LOWER(TO_NUMBER(sst.ss_Template_id))) = TRIM(LOWER(TO_NUMBER(sti.ss_Template_id)))
AND TRIM(LOWER(TO_NUMBER(sti.phi_qid))) = TRIM(LOWER(TO_NUMBER(stc.qid)))
AND TRIM(LOWER(TO_CHAR(sti.template_item_Status))) <> TRIM(LOWER(TO_CHAR('RETIRED')))
ORDER BY
sti.html_Table_row,
sti.html_table_column
LOOP
varSelect := varSelect || ', ' || varTempQuery.field_name;
END LOOP;
varFrom := 'FROM RIX.SUBJECTS';
varWhere := 'WHERE STUDY_ID = ' || TRIM(LOWER(TO_NUMBER(:P21_STUDY_ID )));
varOrderBy := 'ORDER BY';
varOrderBy := varOrderBy || ' subject_label ';
varQuery := varSelect || ' ' || varFrom || ' ' || varWhere || ' ' || varOrderBy;
ELSE
varQuery := 'SELECT SUBJECT_ID FROM SUBJECTS WHERE study_id = :P21_STUDY_ID;';
END IF;
RETURN varQuery;
END;
When I run the page now, the textarea has the SQL statement generated from the first IF block, but the report using the statement from the ELSE block. I thought it maybe was a timing issue, but both blocks reference other fields on the page, so it doesn't seem to be a timing issue. Shouldn't be a condition issue either with the IF block as the textarea and report use the same source, but are evaluating differently.
Very odd (to me at least). -
Problem to create a link with parameters using a PL/SQL function body
Hi everybody,
I need some help to create a link on a SELECT statement.
I have a region report with type "PL/SQL function body return SQL query".
I would like to use a link using HTML tag <a href>.
I know how to do the link, but I don't know to pass a parameters in <a href> statement.
Always I tried it doesn't work well.
My PL/SQL anonimous block is, (just with link) :
DECLARE
q vARCHAR2(4000);
BEGIN
q:='select "INDICADOR"."NRINDICADOR" as "NRINDICADOR",';
q:=q||' "INDICADOR"."DSINDICADOR" as "DSINDICADOR",';
q:=q||'''<span style="font-weight:bold;">';
q:=q||'''||TO_CHAR("TOTAL_INDICADOR"."VL_INDICADOR", ''999G999G999G990D00'')||''</span>''';
q:=q||' as "VL_INDICADOR",';
q:=q||' "TOTAL_INDICADOR"."VL_META" as "VL_META" ';
q:=q||' from "TOTAL_INDICADOR" "TOTAL_INDICADOR",';
q:=q||' "INDICADOR" "INDICADOR" ';
q:=q||' where "INDICADOR"."NRINDICADOR"="TOTAL_INDICADOR"."NR_INDICADOR"';
RETURN q;
END;
Thanks for any help,
AlessandraYour code is in a default value for an item, right?
You need to make sure :P33_YEAR is not null and handle the error in the PL/SQL if it is.
How is P33_YEAR populated? do you pass it in? check to see if it is making it there..
Message was edited by:
Bill Carlisle -
Problem with empty report parameters when passed to PL/SQL function
Hi,
We have come across what appears to be a bug in the JRC. When passing a report parameter to a PL/SQL function as a parameter, empty parameters are changed before being sent to the function. More specifically, an empty string "" ends up as the value "(')" in the PL/SQL function parameter. In our report we print the report parameters on the first page so we know that the parameters are OK before being passed to the database.
The problem exists for version 12.2.203, 12.2.204 and 12.2.205 of the JRC.
We have identified a workaround, but it is not exactly elegant: Before executing the report we modify all empty parameters ("") to " " . In the PL/SQL function, we trim all parameters before using them.
We call the function using a command object with a sql syntax like this example:
select * from table (qa_batch_release.get_qa_br('{?p_report_id}','{?p_reg_set_number}','{?p_cr_number}','{?p_change_id_decode}','{?p_country_id}','{?p_mfg_item_no}','{?p_4_no}','{?p_5_no}','{?p_7_no}'))
The PL/SQL function is a table returning function.
Best regards, ThorHi Kishore,
using #COLUMN_VALUE# would probably not make much sense, because normally a report has multiple columns and not just the numeric column which you want to verify if it's negative. But APEX will fire the template condition for each column, because the report template is a column cell template.
What you can do to make it more generic is to use for example
#CHECK_AMOUNT#
in the template and provide a not displayed column in your SQL statement which contains your value which is named CHECK_AMOUNT. For example:
SELECT NAME
, BALANCE
, BALANCE AS CHECK_AMOUNT
FROM XXX;Because this CHECK_AMOUNT column would be a generic name, you can use this template in all your reports as long as you provide this column.
Thope that helps
Patrick -
Passing #COLUMN_VALUE# as parameter to pl/sql function in column template
Hi all,
I want to color negative amounts in red in sql report using column template.
I created a pl/sql function"isNegativeNum" which returns 1 or -1.
create or replace function isNegativeNum(p_column_value varchar2) return number
as
l_dummy number;
begin
l_dummy := to_number(p_column_value,'999G999G990D00PR');
IF l_dummy < 0
THEN
RETURN 1;
else
return -1;
END IF;
exception
when others then
RETURN -1;
end;Below is column template.
Column Template 1
<td class="t3dataalt" #ALIGNMENT#><p color=red>#COLUMN_VALUE#</p></td>Column Template 1 Condition
isNegativeNum('#COLUMN_VALUE#') = -1The issue is #COLUMN_VALUE# value is not being passed to the function, Insert statement in function reveals p_column_value as a string "#COLUMN_VALUE#". When I try without quotes like isNegativeNum(#COLUMN_VALUE#) = -1, I get below error.
ORA-06550: line 1, column 48: PLS-00103: Encountered the symbol "#" when expecting one of the following: ( ) - + case mod new not null others select table avg count current exists max min prior sql stddev sum variance execute multiset the both leading trailing forall merge year month DAY_ hour minute second timezone_hour timezone_minute timezone_region timezone_abbr time timestamp interval date
Error ERR-1025 Error processing PLSQL expression. isNegativeNum(#COLUMN_VALUE#) = 1
Any help is appreciated.
KishoreHi Kishore,
using #COLUMN_VALUE# would probably not make much sense, because normally a report has multiple columns and not just the numeric column which you want to verify if it's negative. But APEX will fire the template condition for each column, because the report template is a column cell template.
What you can do to make it more generic is to use for example
#CHECK_AMOUNT#
in the template and provide a not displayed column in your SQL statement which contains your value which is named CHECK_AMOUNT. For example:
SELECT NAME
, BALANCE
, BALANCE AS CHECK_AMOUNT
FROM XXX;Because this CHECK_AMOUNT column would be a generic name, you can use this template in all your reports as long as you provide this column.
Thope that helps
Patrick -
PL/SQL function body returning SQL - report error:ORA-01403: no data found
Hi,
I am working on Application Express 4.0.2.00.06, and 11G database.
I have a problem with classic report area of type - PL/SQL function body returning SQL query. Query works if I define region area as - Use Generic Column Names (parse query at runtime only), and does not when I define it - Use Query-Specific Column Names and Validate Query.
I am getting error:
report error:ORA-01403: no data found
This is my query that is returned from function, and displayed with htp.p, and it works ok and returns data in SQL Developer and SQL Workshop (in Apex).
<code>
/* select 1 from dual */ SELECT SIFPRO, NAZIV, VODITELJ, DATPZA,SUM(DECODE(TJEDAN,'2010/46',BRDJEL,null)) as "2010/46" ,SUM(DECODE(TJEDAN,'2010/49',BRDJEL,null)) as "2010/49" ,SUM(DECODE(TJEDAN,'2010/50',BRDJEL,null)) as "2010/50" ,SUM(DECODE(TJEDAN,'2010/51',BRDJEL,null)) as "2010/51" ,SUM(DECODE(TJEDAN,'2010/52',BRDJEL,null)) as "2010/52" ,SUM(DECODE(TJEDAN,'2011/01',BRDJEL,null)) as "2011/01" ,SUM(DECODE(TJEDAN,'2011/02',BRDJEL,null)) as "2011/02" ,SUM(DECODE(TJEDAN,'2011/03',BRDJEL,null)) as "2011/03" ,SUM(DECODE(TJEDAN,'2011/04',BRDJEL,null)) as "2011/04" ,SUM(DECODE(TJEDAN,'2011/05',BRDJEL,null)) as "2011/05" ,SUM(DECODE(TJEDAN,'2011/06',BRDJEL,null)) as "2011/06" ,SUM(DECODE(TJEDAN,'2011/07',BRDJEL,null)) as "2011/07" ,SUM(DECODE(TJEDAN,'2011/08',BRDJEL,null)) as "2011/08" ,SUM(DECODE(TJEDAN,'2011/09',BRDJEL,null)) as "2011/09" ,SUM(DECODE(TJEDAN,'2011/10',BRDJEL,null)) as "2011/10" FROM (SELECT * FROM PMV_PLAN_TVRTKA) GROUP BY SIFPRO, NAZIV, VODITELJ, DATPZA ORDER BY SIFPRO, NAZIV, VODITELJ, DATPZA
</code>
As you can see, I even tried with workaround that I found on the previous post on the forum, and that is to put /* select 1 from dual */ to start query.
Any help would be appriciated./* select 1 from dual */ SELECT SIFPRO, NAZIV, VODITELJ, DATPZA,SUM(DECODE(TJEDAN,'2010/46',BRDJEL,null)) as "2010/46" ,SUM(DECODE(TJEDAN,'2010/49',BRDJEL,null)) as "2010/49" ,SUM(DECODE(TJEDAN,'2010/50',BRDJEL,null)) as "2010/50" ,SUM(DECODE(TJEDAN,'2010/51',BRDJEL,null)) as "2010/51" ,SUM(DECODE(TJEDAN,'2010/52',BRDJEL,null)) as "2010/52" ,SUM(DECODE(TJEDAN,'2011/01',BRDJEL,null)) as "2011/01" ,SUM(DECODE(TJEDAN,'2011/02',BRDJEL,null)) as "2011/02" ,SUM(DECODE(TJEDAN,'2011/03',BRDJEL,null)) as "2011/03" ,SUM(DECODE(TJEDAN,'2011/04',BRDJEL,null)) as "2011/04" ,SUM(DECODE(TJEDAN,'2011/05',BRDJEL,null)) as "2011/05" ,SUM(DECODE(TJEDAN,'2011/06',BRDJEL,null)) as "2011/06" ,SUM(DECODE(TJEDAN,'2011/07',BRDJEL,null)) as "2011/07" ,SUM(DECODE(TJEDAN,'2011/08',BRDJEL,null)) as "2011/08" ,SUM(DECODE(TJEDAN,'2011/09',BRDJEL,null)) as "2011/09" ,SUM(DECODE(TJEDAN,'2011/10',BRDJEL,null)) as "2011/10" FROM (SELECT * FROM PMV_PLAN_TVRTKA) GROUP BY SIFPRO, NAZIV, VODITELJ, DATPZA ORDER BY SIFPRO, NAZIV, VODITELJ, DATPZA
-
Error in report when executing pl/sql function body returning sql query.
Hi,
I have used the pl/sql function body returning sql query for creating a report. I have created a datepicker(
P10_TASK_DATE) which can be submitted.The code is as below
DECLARE
v_sql varchar2(3000);
BEGIN
if :P10_TASK_DATE is not null THEN
v_sql:='select
* from tasks';
return v_sql;
else
v_sql:='select * from discovery';
return v_sql;
END IF;
END;if the date field is empty "select * from discovery" is executed and report is getting generated. But when we give a
date using date picker the page is submitted and i get "report error: ORA-01403: no data found" even
though the "tasks" table has data in it. Plz help
Thanks,
TJhi
Please try this
1. Create 2 region
1st region source=
select * from tasks'
go to the tab -> condition =
item NOT NULL
EXpression1 =:P10_TASK_DATE
this will run whenever the item have any date
2. open your 2 nd region source code= select * from discovery
put the condition
item is NULL
EXpression1 =:P10_TASK_DATE
thanks
Mark Wyatt -
Pass a value from a PL/SQL function to a javascript (html header) ? ?
Hey Guys,
Have a question regarding how to pass a value from a PL/SQL function to a javascript in the HTML Header.
I have created a PL/SQL function in my database, which does looping.
The reason for this is: On my apex page when the user selects a code, it should display(or highlight buttons) the different project id's present for that particular code.
example= code 1
has project id's = 5, 6, 7
code 2
has project id's = 7,8
Thank you for your Help or Suggestions
Jesh
The PL/SQL function :
CREATE OR REPLACE FUNCTION contact_details(ACT_CODE1 IN NUMBER) RETURN VARCHAR2 IS
Project_codes varchar2(10);
CURSOR contact_cur IS
SELECT ACT_CODE,PROJECT_ID
FROM ACTASQ.ASQ_CONTACT where ACT_CODE = ACT_CODE1;
currec contact_cur%rowtype;
NAME: contact_details
PURPOSE:
REVISIONS:
Ver Date Author Description
1.0 6/25/2009 1. Created this function.
BEGIN
FOR currec in contact_cur LOOP
dbms_output.put_line(currec.PROJECT_ID || '|');
Project_codes := currec.PROJECT_ID|| '|' ||Project_codes;
END LOOP;
RETURN Project_codes;
EXCEPTION
WHEN NO_DATA_FOUND THEN
NULL;
WHEN OTHERS THEN
-- Consider logging the error and then re-raise
RAISE;
END contact_details;
/Jesh:
I have made the following modifications to your app to get it to work as I thing you need it to.
1) Changed the source for the HTML Buttons Region(note use of id vs name for the Buttons)
<script>
function hilitebtn(val) {
//gray buttons
$x('graduate').style.backgroundColor='gray'
$x('distance').style.backgroundColor='gray'
$x('career').style.backgroundColor='gray'
$x('photo').style.backgroundColor='gray'
//AJAX call to get project-ids
var get = new htmldb_Get(null,$x('pFlowId').value,'APPLICATION_PROCESS=GETPROJECTS',0);
get.addParam('x01',val)
gReturn = get.get();
var arr=gReturn.split(':'); //dump into array
get = null;
for (i=0;i<arr.length;i++) {
// alert('val=' + arr);
if ( arr[i]==5)
$x('graduate').style.backgroundColor='red';
if ( arr[i]==6)
$x('distance').style.backgroundColor='red';
if ( arr[i]==7)
$x('career').style.backgroundColor='red';
if ( arr[i]==8)
$x('photo').style.backgroundColor='red';
</script>
<table cellpadding='0' cellspacing='0' border='0'>
<tr><td>
<input type='button' id='graduate' value='Graduate'>
</td>
<td>
<input type='button' id='distance' value='Distance'>
</td>
<td>
<input type='button' id='career' value='Career/Tech'>
</td>
<td>
<input type='button' id='photo' value='Photos'>
</td>
</tr></table>
2) Defined the application process GETPROJECTS as DECLARE
IDS varchar2(1000);
l_act_code varchar2(100) :=4;
begin
IDS:='';
l_act_code := wwv_flow.g_x01;
for x in(
SELECT ACT_CODE,PROJECT_ID
FROM ASQ_CONTACT
where ACT_CODE = l_act_code)
LOOP
IDS := IDS || X.PROJECT_ID|| ':' ;
END LOOP;
HTP.PRN(IDS);
END;
3) Changed the 'onchange' event-handler on p1_act_code to be 'onchange=hilitebtn(this.value)'
4) Added the JS to the HTML Page Footer <script>
hilitebtn($v('P1_ACT_CODE'));
</SCRIPT> -
Multiple Select List looping thru PL/SQL function body returning SQL query
Hi,
I have a Multiple Select List. I want to loop through the values from the Select List and process them in a PL/SQL function body returning a SQL query. Currently, my code only returns the SQL SELECT results of one item in the select list. How do I change my code to make it return the results of all of the items in the select list? (I tested it and it is definitely picking up all the values in the select list).
<b>
DECLARE
selected_items HTMLDB_APPLICATION_GLOBAL.VC_ARR2;
s VARCHAR2(20);
q varchar2(32767);
BEGIN
selected_items := HTMLDB_UTIL.STRING_TO_TABLE(:P50_SELECTED_INSTRUMENTS);
-- htp.p('COUNT: '||selected_items.count);
FOR i in 1..selected_items.count LOOP
s := TO_CHAR(selected_items(i));
-- htp.p('First: '||s);
-- htp.p('Second: '||:s);
-- htp.p('Third: '||TO_CHAR(selected_items(i)));
q:= 'SELECT '||
'SUBSTR(orig_geo_loc_sys,1,INSTR(orig_geo_loc_sys,''-'')-1) AS INSTRUMENT, '||
'SUBSTR(orig_geo_loc_sys,INSTR(orig_geo_loc_sys,''-'')+1, LENGTH'||
' (orig_geo_loc_sys)) AS ORIG_LINENUM, '||
'sum(orig_intrl) orig_intrl, '||
'sum(orig_extrl) orig_extrl, '||
'sum(recv_intrl) recv_intrl, '||
'sum(recv_extrl) recv_extrl '||
'FROM line_usage_sum_view '||
'WHERE TO_CHAR(orig_geo_loc_sys) LIKE ''' || s ||'%'' '||
--'WHERE TO_CHAR(orig_geo_loc_sys) LIKE ''2213003%'' '||
'AND switch_id = ''' || :P1_SWITCH_ID || ''' ' ||
'AND call_start_date > TO_DATE(''30-NOV-1999'') ' ||
'AND call_clear_time > TO_DATE(''30-NOV-1999'') '||
'AND '||
:SORTFIELD||' BETWEEN '||
'TO_DATE(:STARTDATE,''dd-MON-YYYY HH24:MI'') AND '||
'TO_DATE(:STOPDATE, ''dd-MON-YYYY HH24:MI'') '||
'GROUP BY GROUPING SETS (orig_geo_loc_sys)';
-- htp.p('SQL query: '||q);
RETURN q;
END LOOP;
END;</b>
Thank you,
LauraLaura,
First, I would be careful of introducing SQL Injection possibilities. Any time I see
'Select ... ' || :P123_FOO || ' ... '
I worry about sql injection. In your case you are converting :P50_SELECTED_INSTRUMENTS into selected_items and then selected_items into s. So when I see
'WHERE TO_CHAR(orig_geo_loc_sys) LIKE ''' || s ||'%'' '||
I think, "I could use sql Injection and hack this."
So, I would do some validation on :P50_SELECTED_INSTRUMENTS or some other method to avoid this.
I'm not certain I understand your query. Do you really intend to allow the user to select the beginning of a string and then find all rows that start with that string? Or, do you just want to let them find when it matches the string. This is one way if you want to do matching:
DECLARE
selected_items HTMLDB_APPLICATION_GLOBAL.VC_ARR2;
s VARCHAR2(32767);
q varchar2(32767);
BEGIN
-- Change the : separate string to be comma separated with quoted strings
s := '''' || replace(:P50_SELECTED_INSTRUMENTS, ',', ''',''')|| '''' ;
-- htp.p('COUNT: '||selected_items.count);
q:= 'SELECT '||
'SUBSTR(orig_geo_loc_sys,1,INSTR(orig_geo_loc_sys,''-'')-1) AS INSTRUMENT, '||
'SUBSTR(orig_geo_loc_sys,INSTR(orig_geo_loc_sys,''-'')+1, LENGTH'||
' (orig_geo_loc_sys)) AS ORIG_LINENUM, '||
'sum(orig_intrl) orig_intrl, '||
'sum(orig_extrl) orig_extrl, '||
'sum(recv_intrl) recv_intrl, '||
'sum(recv_extrl) recv_extrl '||
'FROM line_usage_sum_view '||
'WHERE TO_CHAR(orig_geo_loc_sys) in (' || s ||' ) '||
--'WHERE TO_CHAR(orig_geo_loc_sys) LIKE ''2213003%'' '||
'AND switch_id = ''' || :P1_SWITCH_ID || ''' ' ||
'AND call_start_date > TO_DATE(''30-NOV-1999'') ' ||
'AND call_clear_time > TO_DATE(''30-NOV-1999'') '||
'AND '||
:SORTFIELD||' BETWEEN '||
'TO_DATE(:STARTDATE,''dd-MON-YYYY HH24:MI'') AND '||
'TO_DATE(:STOPDATE, ''dd-MON-YYYY HH24:MI'') '||
'GROUP BY GROUPING SETS (orig_geo_loc_sys)';
-- htp.p('SQL query: '||q);
RETURN q;
END;
If you want to do something more like you originally stated, try this:
DECLARE
selected_items HTMLDB_APPLICATION_GLOBAL.VC_ARR2;
s VARCHAR2(20);
q varchar2(32767);
BEGIN
selected_items := HTMLDB_UTIL.STRING_TO_TABLE(:P50_SELECTED_INSTRUMENTS);
-- htp.p('COUNT: '||selected_items.count);
q:= 'SELECT '||
'SUBSTR(orig_geo_loc_sys,1,INSTR(orig_geo_loc_sys,''-'')-1) AS INSTRUMENT, '||
'SUBSTR(orig_geo_loc_sys,INSTR(orig_geo_loc_sys,''-'')+1, LENGTH'||
' (orig_geo_loc_sys)) AS ORIG_LINENUM, '||
'sum(orig_intrl) orig_intrl, '||
'sum(orig_extrl) orig_extrl, '||
'sum(recv_intrl) recv_intrl, '||
'sum(recv_extrl) recv_extrl '||
'FROM line_usage_sum_view '||
'WHERE 1=1 ';
FOR i in 1..selected_items.count LOOP
s := TO_CHAR(selected_items(i));
q := q || ' and TO_CHAR(orig_geo_loc_sys) LIKE '''|| s ||'%'' ' ;
END LOOP;
q := q || ||'%'' '||
--'WHERE TO_CHAR(orig_geo_loc_sys) LIKE ''2213003%'' '||
'AND switch_id = ''' || :P1_SWITCH_ID || ''' ' ||
'AND call_start_date > TO_DATE(''30-NOV-1999'') ' ||
'AND call_clear_time > TO_DATE(''30-NOV-1999'') '||
'AND '||
:SORTFIELD||' BETWEEN '||
'TO_DATE(:STARTDATE,''dd-MON-YYYY HH24:MI'') AND '||
'TO_DATE(:STOPDATE, ''dd-MON-YYYY HH24:MI'') '||
'GROUP BY GROUPING SETS (orig_geo_loc_sys)';
-- htp.p('SQL query: '||q);
RETURN q;
END;
Hope this helps...
Anton -
Is it possible to retrieve RAD's extended variables with a pl/sql function?
Good morning everyone,
We have our forms and reports(10g) application, SSO enabled and we are using OID on 10g app server. some of our users use smart card to log in to the system and some who do not have smart cards provide their database userid, password and SID.
In the case of users who login with smart card, as a one time effort, they have to register their smart card. At that point OID presents a form prompting for their username, password, sid and then a RAD record is created for that particular user.
And from then on when the user enters the system using his smart card(12345@mil), forms servlet, does the look up of dbusername,dbpswd,sid which belong to the 12345@mil and user's database credentials are passed to the application. The entire application logic is based on that userid which is also an internal userid in the application. Everything is working fine.
I have read the documentation and found that 12345@mil is stored in the "cn" parameter and the orclownerguid and orclusernameattribute are stored under "cn"=extended properties in the oid. I am able to see this from the oid console.
But now I need some help. If I only know the id of the user as "12345@mil" , is it possible to manually query the RAD and retrieve the orclusername from a pl/sql function?
Any help is greatly appreciated.
Regards,
Suma.Please can anyone help me????
Regards,
Suma. -
Invoking a PL/SQL function from BPEL throws fault.
Hi, I'm trying to invoke a PL/SQL function that inserts data in to a table from a BPEL via DB Adapter. The process, when I test it, throws a runtime fault as follows:
*Exception occured when binding was invoked. Exception occured during invocation of JCA binding: "JCA Binding execute of Reference operation 'EmpRegister' failed due to: JCA Binding Component connection issue. JCA Binding Component is unable to create an outbound JCA (CCI) connection. AddEmployee:EmpRegister [ EmpRegister_ptt::EmpRegister(InputParameters,OutputParameters) ] : The JCA Binding Component was unable to establish an outbound JCA CCI connection due to the following issue: BINDING.JCA-12510 JCA Resource Adapter location error. Unable to locate the JCA Resource Adapter via .jca binding file element <connection-factory/> The JCA Binding Component is unable to startup the Resource Adapter specified in the <connection-factory/> element: location='eis/DB/DBConn_215'. The reason for this is most likely that either 1) the Resource Adapters RAR file has not been deployed successfully to the WebLogic Application server or 2) the '<jndi-name>' element in weblogic-ra.xml has not been set to eis/DB/DBConn_215. In the last case you will have to add a new WebLogic JCA connection factory (deploy a RAR). Please correct this and then restart the Application Server ". The invoked JCA adapter raised a resource exception. Please examine the above error message carefully to determine a resolution.*
Also, the fault description was a s follows:
*JCA Resource Adapter location error. Unable to locate the JCA Resource Adapter via .jca binding file element <connection-factory/> The JCA Binding Component is unable to startup the Resource Adapter specified in the <connection-factory/> element: location='eis/DB/DBConn_215'. The reason for this is most likely that either 1) the Resource Adapters RAR file has not been deployed successfully to the WebLogic Application server or 2) the '<jndi-name>' element in weblogic-ra.xml has not been set to eis/DB/DBConn_215. In the last case you will have to add a new WebLogic JCA connection factory (deploy a RAR). Please correct this and then restart the Application Server.*
I know, it looks like a JCA adapter error, but when I do a DB to DB table synchronization with this connection factory, no problems happen. Is ther any special procedure I should follow in mapping input data to db schema?HI,
I am working on BPEL process and human workflow...
I created a process and a Data control and now can see it as JCA Adapter in console..in this adapter I am executing a sql procedure.. we can execute in in BPEL process through invoke activity, now my requirement is how to invoke this data control through custom java code. please help...\
now i have two wsdl files.
RegistrationUpload.wsdl(process name)
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions name="RegistrationUpload"
targetNamespace="http://xmlns.oracle.com/RegistrationUpload_jws/RegistrationUpload/RegistrationUpload"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:client="http://xmlns.oracle.com/RegistrationUpload_jws/RegistrationUpload/RegistrationUpload"
xmlns:plnk="http://schemas.xmlsoap.org/ws/2003/05/partner-link/">
<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
TYPE DEFINITION - List of services participating in this BPEL process
The default output of the BPEL designer uses strings as input and
output to the BPEL Process. But you can define or import any XML
Schema type and use them as part of the message types.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<wsdl:types>
<schema xmlns="http://www.w3.org/2001/XMLSchema">
<import namespace="http://xmlns.oracle.com/RegistrationUpload_jws/RegistrationUpload/RegistrationUpload" schemaLocation="xsd/RegistrationUpload.xsd" />
</schema>
</wsdl:types>
<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
MESSAGE TYPE DEFINITION - Definition of the message types used as
part of the port type defintions
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<wsdl:message name="RegistrationUploadRequestMessage">
<wsdl:part name="payload" element="client:process"/>
</wsdl:message>
<wsdl:message name="RegistrationUploadResponseMessage">
<wsdl:part name="payload" element="client:processResponse"/>
</wsdl:message>
<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
PORT TYPE DEFINITION - A port type groups a set of operations into
a logical service unit.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<!-- portType implemented by the RegistrationUpload BPEL process -->
<wsdl:portType name="RegistrationUpload">
<wsdl:operation name="process">
<wsdl:input message="client:RegistrationUploadRequestMessage"/>
</wsdl:operation>
</wsdl:portType>
<!-- portType implemented by the requester of RegistrationUpload BPEL process
for asynchronous callback purposes
-->
<wsdl:portType name="RegistrationUploadCallback">
<wsdl:operation name="processResponse">
<wsdl:input message="client:RegistrationUploadResponseMessage"/>
</wsdl:operation>
</wsdl:portType>
<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
PARTNER LINK TYPE DEFINITION
the RegistrationUpload partnerLinkType binds the provider and
requester portType into an asynchronous conversation.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<plnk:partnerLinkType name="RegistrationUpload">
<plnk:role name="RegistrationUploadProvider">
<plnk:portType name="client:RegistrationUpload"/>
</plnk:role>
<plnk:role name="RegistrationUploadRequester">
<plnk:portType name="client:RegistrationUploadCallback"/>
</plnk:role>
</plnk:partnerLinkType>
</wsdl:definitions>
uploadDataToPermananentDB.wsdl
<?binding.jca uploadDataToPermananentDB_db.jca?>
<wsdl:definitions name="uploadDataToPermananentDB"
targetNamespace="http://xmlns.oracle.com/pcbpel/adapter/db/RegistrationUpload/RegistrationUpload/uploadDataToPermananentDB"
xmlns:db="http://xmlns.oracle.com/pcbpel/adapter/db/DAMSMGR/TEMP_TO_PERMANENTDB/"
xmlns:tns="http://xmlns.oracle.com/pcbpel/adapter/db/RegistrationUpload/RegistrationUpload/uploadDataToPermananentDB"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:plt="http://schemas.xmlsoap.org/ws/2003/05/partner-link/">
<plt:partnerLinkType name="uploadDataToPermananentDB_plt">
<plt:role name="uploadDataToPermananentDB_role">
<plt:portType name="tns:uploadDataToPermananentDB_ptt"/>
</plt:role>
</plt:partnerLinkType>
<wsdl:types>
<schema xmlns="http://www.w3.org/2001/XMLSchema">
<import namespace="http://xmlns.oracle.com/pcbpel/adapter/db/DAMSMGR/TEMP_TO_PERMANENTDB/"
schemaLocation="xsd/DAMSMGR_TEMP_TO_PERMANENTDB.xsd"/>
</schema>
</wsdl:types>
<wsdl:message name="args_in_msg">
<wsdl:part name="InputParameters" element="db:InputParameters"/>
</wsdl:message>
<wsdl:portType name="uploadDataToPermananentDB_ptt">
<wsdl:operation name="uploadDataToPermananentDB">
<wsdl:input message="tns:args_in_msg"/>
</wsdl:operation>
</wsdl:portType>
</wsdl:definitions>
please help me how to call the data adaper from my java code..
hope i will get some hint in this forum...
Edited by: user13370040 on Mar 22, 2011 5:55 AM -
PL/SQL Function to check user name and password
Hi,
I am new to PL/SQL. I have a table that stores user name and password. I want to write a PL/SQL function that checks if the entered user name and password is correct, by validation against the values in the table... Can someone help me with the code? Both user name and password is varchar2First of all, I believe you mean a procedure that would check the application username and password. Fot, if you mean a PL/SQL procedure, that runs in the database, and that means it has to be executed after the client application is connected to the database.
Maybe you need a procedure like this:
procedure check_pass(p_user varchar2, p_pass varchar2) is
pragma autonomous_transaction;
v_passwd varchar2(200);
begin
select passwd into v_passwd
from password_table
where user_name=p_user;
if v_passwd!=p_pass then
update password_table set
last_unsucc_logon=sysdate
,unsucc_logon_n=nvl(unsucc_logon_n,0)+1
where user_name=p_user;
commit;
raise_application_error(-20101,'Invalid username/password!');
end if;
exception
when no_data_found then
raise_application_error(-20101,'Invalid username/password!');
end;
Study this piece of code and see if this will do.
Maybe you are looking for
-
Work Status Report Date and Time Setting
Hi all We are running BPC10 on servers configured with Central European Time which is currently 2 hours ahead of GMT allowing for Daylight Savings Time. From what i can see in BPC10 date and times are now stored in GMT (Zulu time) in the Audit activi
-
Hi, 1. I have added new column to query that generate Interactive Report, but the column does not show on the report. 2. No matter how I change the order of these columns in the query and the report attribute, still does not change the way/order they
-
Mail to vendors abt vendors payment
Dear all We have one requirement : Generally first we will create batch( open item ) using zreport. After that we will cleared this batch using f110. My requirement is: When I created batch using z tocde: those document for clearing we need to sen
-
Whats wrong with my inputcheck...
Hey there, for my study i have to make a system that takes a double as input for the n hours somebody parked and eventually add that to a total.... Parking where the calculation is in is fine... public class parking public parking()//double atot
-
The extraction program does not support object ZTD_AW_17
Hi friends, When doing extraction I am getting the below error.Please see the below extract of system response. "The extraction program does not support object ZTD_AW_17 Message no. R3 009 Diagnosis The application program for the extraction of data