Question - Passing date to a function from a Query
Hello,
I have a function which looks like this
CREATE OR REPLACE FUNCTION CAL_DATES_FNC
(fp_fddate IN VARCHAR2,
fp_task IN VARCHAR2
RETURN VARCHAR2
IS
BEGIN
IF TO_CHAR(TO_DATE(fp_fddate,'YYYYMMDD'),'DD-MON-YYYY') <= TO_CHAR(ADD_MONTHS(TO_DATE(fp_fddate,'YYYYMMDD'),60),'DD-MON-YYYY')
THEN
RETURN TO_CHAR(ADD_MONTHS(TO_DATE(fp_fddate,'YYYYMMDD') +21,6 * SUBSTR(fp_task,-2)) ,'DD-MON-YYYY');
ELSIF TO_CHAR(TO_DATE(fp_fddate,'YYYYMMDD'),'DD-MON-YYYY') >= TO_CHAR(ADD_MONTHS(TO_DATE(fp_fddate,'YYYYMMDD'),72),'DD-MON-YYYY')
THEN
RETURN TO_CHAR(ADD_MONTHS(TO_DATE(fp_fddate,'YYYYMMDD') +21,12 * SUBSTR(fp_task,-2)) ,'DD-MON-YYYY');
END IF;
END;
I am using this function in a query as given below to pass a date fp_fddate
The problem I am having is that the function is executing only the first part of the IF construct it is not going into the second IF condition.
Can some one please let me know where I could be going wrong.
SELECT ABC.PT,
ABC.INV,
ABC.INVSITE,
ABC.TASK TASK_NAME,MAX(XYZ.FPDATE) fpdate ,
CAL_DATES_FNC(MAX(XYZ.FPDATE),ABC.CPTASK) "DATE1",
TO_CHAR(TO_DATE(ABC.D_YR||ABC.D_MON||ABC.D_DAY,'YYYYMMDD'),'DD-MON-YYYY') "DATE2"
FROM ABC,
XYZ
WHERE ABC.PT = XYZ.PT
AND PATSTAT.PT = '61090'
GROUP BY ABC.PT,ABC.INV,ABC.INVSITE,ABC.D_YR,ABC.D_MON,ABC.D_DAY,ABC.CPTASK
Regards
Fm
Hi,
IQ wrote:
Thanks for your messages. I am sending the scripts for the tables and insert statements in this message. Hope this will help to recreate the scenario.Don't forget to post the output you want from that data, and an explanation of how you get that output from the given data.
Some of my answers are as follows,
1) I know that the function is not in a proper syntax and thats the reason I need to fix it to be able to perform well. All I want is to compare the dates for a 5 year period(60 months) and then return something . For a period greater than 6 years (72 months) it should return something else.What dates do you want to compare? I assume fp_fddate is one of them, but what about the other(s)?
When does the 5-year period begin or end?
When does the 6-year period begin or end?
I understand the fucntion may return either of two values. Do you care what those two values are? If so, give examples.
What if the date is in neither the 5-year nor the 6-year period? (A fucntion has to return something in all cases. It can return NULL, if that's what you want.)
What if the argument can't be interpreted as a date?
2) Regarding the string datatype for date columns I cannot change the database design as this is done by another team, I can however explain them the points mentioned here.
Please find below the scripts When you say TEST_DATES, do you mean TEST_DATES1. or is there another table? Test before you post.
CREATE TABLE TEST_DATES
pt VARCHAR2(10 BYTE),
inv VARCHAR2(10 BYTE),
invsite VARCHAR2(10 BYTE),
task_name VARCHAR2(20 BYTE),
fpddate VARCHAR2(8 BYTE),
DATE1 VARCHAR2(4000 BYTE),
DATE2 VARCHAR2(17 BYTE)
insert into test_dates1(pt,inv,invsite,task_name,fpddate,date1,date2)
values (61090,'XDUMMY1' ,'R1111','UP01' ,'19990714','04-FEB-2000', '17-JAN-2000');
insert into test_dates1(pt,inv,invsite,task_name,fpddate,date1,date2)
values (
61090, 'XDUMMY1','R1111','UP02','19990714','04-AUG-2000','20-JUL-2000');
insert into test_dates1(pt,inv,invsite,task_name,fpddate,date1,date2)
values (
61090, 'XDUMMY1','R1111','UP03','19990714','04-FEB-2001','19-JAN-2001');
insert into test_dates1(pt,inv,invsite,task_name,fpddate,date1,date2)
values (
61090,'XDUMMY1','R1111','UP04','19990714','04-AUG-2001','21-JUL-2001');
insert into test_dates1(pt,inv,invsite,task_name,fpddate,date1,date2)
values (
61090,'XDUMMY1','R1111','UP05','19990714','04-FEB-2002','20-JAN-2002');
insert into test_dates1(pt,inv,invsite,task_name,fpddate,date1,date2)
values (
61090,'XDUMMY1','R1111','UP06','19990714','04-AUG-2002','19-JUL-2002');
insert into test_dates1(pt,inv,invsite,task_name,fpddate,date1,date2)
values (
61090,'XDUMMY1','R1111','UP07','19990714','04-FEB-2003','17-JAN-2003');
insert into test_dates1(pt,inv,invsite,task_name,fpddate,date1,date2)
values (
61090,'XDUMMY1','R1111','UP08','19990714','04-AUG-2003','15-JUL-2003');
insert into test_dates1(pt,inv,invsite,task_name,fpddate,date1,date2)
values (
61090,'XDUMMY1','R1111','UP09','19990714','04-FEB-2004','20-JAN-2004');
insert into test_dates1(pt,inv,invsite,task_name,fpddate,date1,date2)
values (
61090,'XDUMMY1','R1111','UP10','19990714','04-AUG-2004','25-JUL-2004');
insert into test_dates1(pt,inv,invsite,task_name,fpddate,date1,date2)
values (
61090,'XDUMMY1','R1111','UP11','19990714','04-FEB-2005','27-JAN-2005');
insert into test_dates1(pt,inv,invsite,task_name,fpddate,date1,date2)
values (
61090,'XDUMMY1','R1111','UP12','19990714','04-AUG-2005','25-JUL-2005');
insert into test_dates1(pt,inv,invsite,task_name,fpddate,date1,date2)
values (
61090,'XDUMMY1','R1111','UP13','19990714','04-FEB-2006','28-JAN-2006');
insert into test_dates1(pt,inv,invsite,task_name,fpddate,date1,date2)
values (
61090,'XDUMMY1','R1111','UP14','19990714','04-AUG-2006','30-JUL-2006');
insert into test_dates1(pt,inv,invsite,task_name,fpddate,date1,date2)
values (
61090,'XDUMMY1','R1111','UP15','19990714','04-FEB-2007','31-JAN-2007');
/You said that sometimes the data contains values like 'NA'. Shouldn;t the sample data have an example or two of that?
Once the data is populated in the table , use the following query
select TASK_NAME,RCM_CAL_THEORETIC_DATES_FNC(MAX(fpddate),task_name) "DATE1"
from test_dates1
group by task_name When you say
RCM_CAL_THEORETIC_DATES_FNC, do you mean the function you posted in your first message, which was called
CAL_DATES_FNC, or is there another funciton?
When I make those changes and run the query, I get 15 rows:
TASK_NAME DATE1
UP06 04-AUG-2002
UP07 04-FEB-2003
UP14 04-AUG-2006
UP08 04-AUG-2003
UP10 04-AUG-2004
UP12 04-AUG-2005
UP15 04-FEB-2007
UP01 04-FEB-2000
UP02 04-AUG-2000
UP03 04-FEB-2001
UP05 04-FEB-2002
UP13 04-FEB-2006
UP04 04-AUG-2001
UP09 04-FEB-2004
UP11 04-FEB-2005Is that correct?
If so, what is the problem?
If not, what results should I get?
What is the function supposed to do?
Edited by: Frank Kulash on Nov 9, 2010 4:45 PM
Similar Messages
-
Passing data to custom smartform from a custom program...
Hello Gurus,
Since, the function module gets generated dynamically at runtime when smartform is activated, I know that first I should use "SSF_FUNCTION_MODULE_NAME" and pass custom smartform name to it to get the name of function module. Then I have to use call function '/XXXXXXXXX'.
Now, I am writing a custom code and I want the data from my select program in custom program to be passed to smartform ? How can I pass the data from my custom program to smartform ? Do I pass it before using function module "SSF_FUNCTION_MODULE_NAME" ? If yes, how ?
Regards,
Rajesh.hi,
u have to declare ur structures in form interface and can retrive the data from custom program.
check this sample code.
declare structure in interface.
WA_MKPF TYPE MKPF.
write ur custom code lik this.
DATA: wahz TYPE zmemigo_form_header,
wa_mkpf TYPE mkpf.
DATA: t_itemz LIKE zmemigo_form_item OCCURS 0,
t_mseg TYPE mseg OCCURS 0,
waitemz TYPE zmemigo_form_item,
waitem TYPE mseg.
DATA : form_name TYPE tdsfname VALUE 'ZPS_STN'.
DATA : fnc_module TYPE rs38l_fnam.
SELECT SINGLE mblnr INTO wa_mkpf-mblnr FROM mseg
CLIENT SPECIFIED WHERE mandt EQ sy-mandt
AND mblnr EQ p_mblnr
AND mjahr EQ p_mjahr
AND bwart EQ '351'
AND shkzg EQ 'H'.
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname = form_name
VARIANT = ' '
DIRECT_CALL = ' '
IMPORTING
fm_name = fnc_module
EXCEPTIONS
no_form = 1
no_function_module = 2
OTHERS = 3
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
CALL FUNCTION fnc_module
EXPORTING
wa_headz = wahz
wa_mkpf = wa_mkpf
TABLES
it_itemz = t_itemz
it_mseg = t_mseg
EXCEPTIONS
formatting_error = 1
internal_error = 2
send_error = 3
user_canceled = 4
OTHERS = 5.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF. -
Call external function from SQL query
Hi,
I am new to PL/SQL programming.I don't think this is possible but please let me know if there is a way to achieve this. I have a function written in VB.net and I would want to call from the query.
create table temp as select id, callvbfunction(note_text) from temp2
Here callvbfunction is the vb.net function.I need to pass note_text field value to the function.
Thanks..Yes it is possible.
No idea how to specifically call a .Net function (from Oracle) as I do not do Windows (except for playing games ;-) ). But external procedures (extproc) and Java stored procs can be wrapped by PL/SQL wrapper functions and used in SQL statements. -
Form blows up when clicked in data block using a FROM clause query
Hi,
I have a form that has two blocks. The detail block is based on a "FROM query clause" in the 'Query Data Source Type' in the block Properties.
I have a simple select in the 'Query Data Source Name'.
I made sure the select is enclosed in parenthesis and the alias names in the SELECT are the same as the ITEMS defined in the block
The data needs to be displayed in a tabular fashion.
When I run the form, the data is displayed correctly..but when I click the mouse on any item of this block or try to scroll down, everything just blows up and it closes my form.
I have made sure both blocks have the same properties. But, this seems to happen no matter what.
Any help in regard is greatly appreciated.
Thanks much,
VijjiThis is how I set the relationship for the detail block say BLOCK2.
1. I first do this:
Database Data Block = YES
Query Allowed = YES
Query Data Source Type = FROM clause query Query Data Source Name = ( select jio.order_header_id order_header_id, jii.item_code item_code, SUM(jii.item_qty) item_qty from joe_indv_items jii, joe_indv_orders jio where jii.indv_order_id = jio.indv_order_id group by jio.order_header_id, jii.item_code )
The master and detail need to be tied by the order_header_id which I can get from the header block.
2. In the WHEN-NEW_BLOCK-INSTANCE trigger for BLOCK2, I wrote the following where I dynamically pass the order_header_id:
DECLARE
q varchar2(1000);
BEGIN
q := '(SELECT jio.order_header_id order_header_id,
jii.item_code item_code,
SUM(jii.item_qty) item_qty
FROM joe_indv_items jii, joe_indv_orders jio
WHERE jio.order_header_id = ' || :HEADERS.order_header_id||'
AND jii.indv_order_id = jio.indv_order_id
GROUP BY jio.order_header_id, jii.item_code )';
CLEAR_BLOCK;
SET_BLOCK_PROPERTY('BLOCK1', QUERY_DATA_SOURCE_NAME, q);
EXECUTE_QUERY;
END;
I am not sure if I should write the exact select statement in the Query Data Source Name or not.
Please advice.
Thanks much,
Vijji -
Calling the function from SQL query
Hi,
I am trying to run the below statement,
Select to_number(apps.pay_balance_pkg.get_value( 326, :paa.assignment_action_id,to_date ('31032011','ddmmyyyy'))) from dual;
getting an error as :
ORA-14552 cannot perform a DDL, commit or rollback inside a query or DML
ORA - 06512 at apps.pay_balance_pkg , line 4526.
How can I execute this funciton "apps.pay_balance_pkg.get_value" from sql query?
Thanks in advance.user1175432 wrote:
Hi,
I am trying to run the below statement,
Select to_number(apps.pay_balance_pkg.get_value( 326, :paa.assignment_action_id,to_date ('31032011','ddmmyyyy'))) from dual;
getting an error as :
ORA-14552 cannot perform a DDL, commit or rollback inside a query or DML
ORA - 06512 at apps.pay_balance_pkg , line 4526.
How can I execute this funciton "apps.pay_balance_pkg.get_value" from sql query?
Thanks in advance.If the function is performing DDL, commit or rollback inside it then you will not be able to call it from an SQL statement.
Either change the function so it doesn't perform DDL, commit or rollback, or use a different means to obtain the information you want (assuming you can't change the function) -
Passing values to a function from spry:repeat
Is this a viable solution?
<div spry:repeat="dsData">
<script
type="text/javascript">addPin("{ds_RowNumberPlus1}","{site}&q uot;,"{latitude}","{longitude}");</script>
</div>quote:
Originally posted by:
victor.corey
Hello V1 Fusion,
Yes this did work. Thank you.
For clarification, why add this to a spry:if in a hidden span
versus just adding a javascript script block inside the
spry:repeat. Both seem to work so far, but it seems your solution
may help with error handling???
Thanks,
Victor Corey
I know u could use functions in Spry if, im
using them my self i should show a row based on cookie values ( the
function checks if certain data is in a cookie, and if its there it
shows the row).
I was about to use the same technique for my own project my
self to, so i thought it would be a good way to gather certain
data, based on what u get returned from your own data set.
And if u add a javascript block, each time u repeat it, it
has to be created. its allot smaller size wise to create a little
span (or u can even add it to the repeat self). That was basicly
the reason why i suggested using a spry:if ^_^ -
Passing data to SAP script from print program-VF03
Hi All,
I have a stand alone print program which ahs the invoice number in its selection screen which when entered displays the layout of invoice by using a sap script.
Now since I have to get this layout displayed from VF03, I have added the program, sap script name and a subroutine which contains the code which was initially there under the start-of-selection event in the stand alone program, in NACE. I have replaced the selection screen parameter for invoice number in my program with nast-objky which contains the invoice entered in vf03.
But when I am entering the invoice in vf03 and selecting print preview, the data is getting captured in the internal table defined in my program but the same is not getting reflected in the layout displayed. So I am always getting the blank values in the output though I did not modify the original sap script at all. Pls help.Keep a breakpoint in your print program and see if your program is being triggered indeed. Do not forget to start Update debugging, otherwise it will not stop in your print program.
Regards,
Ravi -
Best way to pass data back and forth from multiple NativeProcess threads
Hi all,
We have an application that requires multiple concurrent accesses to mulitple instances of a java NativeProcess. The input and output is XML data. I can see how to shunt this back and forth with only a single listening thread on stdout, but with multiple threads the whole thing is going to get rather jumbled. At the moment we are looking at using temporary files to read and write data from each instance, but I wonder if there might be a better way ... any suggestions?
Thanks.I may not be completely understanding your issue...however you should be able to check which NativeProcess instance is giving you stdin/stdout/stderror data by checking the target member of the ProgressEvent. If that is not helpful, could you please provide some additional information about what you are trying to do, and what trouble you are running in to?
Thanks,
Chris Thilgen
AIR Engineering -
IFRAME in portlet question - possible to call parent function from iframe?
From the iframe I tried to call the parent function by doing this parent.myFunc(). I got a permission denied javascript message. Just curious if anyone has successfully done this. If so please share your thoughts and comments.
Hi,
You will get "Persmission denied" error due to cross site scripting. Either you need to change browser settings to allow cross site scripting or you need to make sure both the URLs fall under same parent domain like both URLs ending with "*.abc.com".
Thanks -
Best design for Boolean function from simple query
Hello,
what is the most efficient, shorter, readable, simple way to make a boolean function that simply return true or false from a simple query that return 0 or 1 to n records?
Is this solution using a cursor's the best (working...):
FUNCTION is_date_present (p_date IN DATE)
RETURN BOOLEAN
IS
CURSOR chk_cursor
IS
SELECT COUNT (*)
FROM target_dates
WHERE target_date = p_date;
nb NUMBER := 0;
BEGIN
OPEN chk_cursor;
FETCH chk_cursor
INTO nb;
CLOSE chk_cursor;
IF nb >= 1
THEN
RETURN TRUE;
ELSE
RETURN FALSE;
END IF;
END;Performance, clarity and simplicity are important...
ThanksWell, I prefer (not tested):
FUNCTION is_date_present (p_date IN DATE)
RETURN BOOLEAN
IS
nb NUMBER := 0;
BEGIN
SELECT COUNT (*)
INTO nb
FROM target_dates
WHERE target_date = p_date;
IF nb >= 1 THEN
RETURN TRUE;
LSE
RETURN FALSE;
IF;
END;Regards,
MiguelWhy count multiple records when you only care if you get at least 1 occurrence? Just wasted cycles.
FUNCTION is_date_present (p_date IN DATE)
RETURN BOOLEAN
IS
nb NUMBER := 0;
BEGIN
SELECT COUNT (*)
INTO nb
FROM DUAL
WHERE EXISTS
SELECT NULL
FROM target_dates
WHERE target_date = p_date
IF nb >= 1 THEN
RETURN TRUE;
ELSE
RETURN FALSE;
END IF;
END;Or you could just add a ROWNUM = 1 on to yours, either way. -
Calling boolean function from tree query
Hi all,
I have placed a tree on my sidebar region from the following query
select PAGE_NO id,
PARENT_PAGE_NO pid,
NAME name,
'f?p=&APP_ID.:'||page_no||':&SESSION.' link,
null a1,
null a2
from #OWNER#.APEX_PAGES
WHERE page_no = :APP_PAGE_ID
AND nvl(navigation,'N') = 'Y'
Its running perfectly fine. Now i have my custom function "isUserAllowed(app_user, name_of_node, isParent)" which returns a boolean expression is the logged in User has access privilege on that node.
How can i run my function inside the tree query so that node is visible only for those values in which my function returns "true"? and not on others?
With Regards,
Sunil BhatiaThe "wrapper" function would actually be pretty easy - just another function to call the one returning the boolean and convert it to some other value, numeric or character. something like (untested)
<pre>
FUNCTION wrapper_function(P_whatever varchar2) return varchar2 IS
v_return_value_c varchar2(5);
BEGIN
r_return_value_c := case boolean_function(p_whatever)
when true then 'true'
else 'false;
return v_return_value_c;
END;
</pre>
Using the function in the WHERE clause could look something like this (untested, but should work if done correctly)
<pre>
select whatever
from your_table
where wrapper_function(whatever) = 'true'
</pre> -
CF 9 How pass data in one grid to a query that populates another grid?
I have a cfgrid from which a user would choose a data row. Based on the values in the selected row, I would run to a query to get
detailed data that would display in another grid. In that new grid, I would want to be able to insert and also maybe edit a row in that
detailed grid.
I haven't found any explanation of how to get the values of the selected row.
Any other ideas on how to structure the process I described would also be really helpful.
Thanks.I have a cfgrid from which a user would choose a data row. Based on the values in the selected row, I would run to a query to get
detailed data that would display in another grid. In that new grid, I would want to be able to insert and also maybe edit a row in that
detailed grid.
I haven't found any explanation of how to get the values of the selected row.
Any other ideas on how to structure the process I described would also be really helpful.
Thanks. -
Getting session hang When calling Function from SQL query
Hi All,
I am using Oracle 8.1.7.4.0. I have a fucntion in a Package and I am calling it from the SQL query. When I am firing the query my oracle session is going to hang position and I am not able to any thing. I have to kill the session.
But this same thing is working fine in Oracle 9.i.
There are no out parameter and no DML, DDL and DCL statement in this fucntion.
Could you please get back me what is the problem on it.
Regards
SUNCheck why your session hangs.
Just a few ideas:
* Blocking locks?
* Endless loop?
* Performance (maybe it is just slow in orac8i and you have to wait a bit longer). Check the execution plans of the SQL statements in your function.
* Don't use a function, but direct SQL, it is faster in both versions. -
Execution date in Excel export from a query
Dear all,
I am wondering if it is possible to have the query execution date in an exported excel.
Case: When working in a query it should be possible to export the query to excel. However I am missing the execution date of the query and the last successful data load (which is visible in the webquery).
Anyone has an idea how to achieve that?
Thank you in advance,
AndreasHey Guys,
Just wanted to point out that I know how to do this with a webapplication but I would need that within an excel export from an ordinary web query.
Could someone help out here?
Thanks in advance,
Andreas -
Need to select XMLTYPE data in unindented form, from a query.
I need to select XMLTYPE data among relational data as an xml element.
SELECT
XMLSERIALIZE(DOCUMENT
XMLELEMENT ("Account",
XMLATTRIBUTES (LPAD(ROWNUM, 10 , '0') AS "recordId" )
,XMLELEMENT ("Header"
,XMLELEMENT ("AccountId"
,XMLELEMENT ("AccountNumber" ,car.acc_nbr )))
,XMLELEMENT ("CreditPurpose" ,car.credit_purp )
,XMLELEMENT ("AccountType" ,car.acc_type )
, (cdx.cus_dtls) -- /*THIS IS XMLTYPE data*/
))AS crdtrpt
FROM cus_acc_rpt car , cus_dtls_xml cdx
WHERE car.ar_id = cdx.ar_id
Here cdx.cus_dtls need to be selected in unindented form (each records as a long unbroken string of data). So that I can SPOOL huge number of records in lesser time.
I am trying to convert this into CLOB and Insert into CLOB type column of a table.
But XMLSERIALIZE does not seem to serialize the xml data in cus_Dtls column.
However it does serialize the xml typ data selected other than cus_dtls.
Any quick hints to meet the requirements will be very welcomed !!
Cheers !!
SaxenaUse XMLSerialize with NO INDENT option :
SELECT XMLSERIALIZE(DOCUMENT
XMLELEMENT ("Account",
NO INDENT
)AS crdtrpt
FROM cus_acc_rpt car , cus_dtls_xml cdx
WHERE car.ar_id = cdx.ar_id
Maybe you are looking for
-
My ipad is showing the connect to itunes and will not move from there.
After trying to update my ipad. I recieved an "unable to update" error message. Now all my ipad will do is show the connect to itunes symbols. I cannot get is to restart or restore. itunes is not recognizing the ipad.
-
Apply Ink Signature Option Grayed-Out
Why would other computers except mine within my company who have the most recent Reader installed not be able to access the "apply ink signature" option under "extended?" I have enabled extended features.
-
Convert .mov to flash for web?
Is there a relatively easy way to convert QT mov to a flash file for use on the web? I have Flash CS3 thanks.
-
Move from one request number to other request number
hi, i created one tcode and saved it in one request number. but i want to save it in other request number. what i did ....i deleted that tcode and again created but its saving on the same request number... can any one help me...
-
Open file command not working... suggestions?
Running InDesign CS6 on Mac OSX 10.8.5. When I go to open a file from InDesign, I can use Command-Arrow Up and Command-Arrow Down to navigate up and down through folders, but then when I select the file I wish to open, another Command-Down Arrow does