anumoses
asked on
DBMS_SESSION.set_context
DBMS_SESSION.set_context(' mydate', 'given_date', '06-apr-2010');
Instead of hardcoding the last parameter the date as 06-apr-2010, I want this to be passed as parameter for any date. How to do that. Now it pulls data only for 6th april, but I need to get data for any date that I give as input.
Instead of hardcoding the last parameter the date as 06-apr-2010, I want this to be passed as parameter for any date. How to do that. Now it pulls data only for 6th april, but I need to get data for any date that I give as input.
put in a variable instead of a constant wherever you are invoking that
ASKER
DBMS_SESSION.set_context(' mydate', 'given_date', 'p_date');
How do I refer to this variable when I call this package?
my_pkg.test_context;
How do I refer to this variable when I call this package?
my_pkg.test_context;
for example...
CREATE OR REPLACE PACKAGE my_pkg
IS
PROCEDURE test_ctx;
END my_pkg;C
CREATE OR REPLACE PACKAGE BODY my_pkg IS
PROCEDURE test_ctx(p_date_string in varchar2) IS
BEGIN
DBMS_SESSION.set_context('mydate', 'given_date', p_date_string);
END;
END my_pkg;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Date format is 04/06/2010
is that dd/mm/yyyy? or mm/dd/yyyy?
also, are you passing in a string or a date? If a string you don't need to format it, it should already be formatted. If a date, then simply modify the format in the example to whatever you want
also, are you passing in a string or a date? If a string you don't need to format it, it should already be formatted. If a date, then simply modify the format in the example to whatever you want
ASKER
date in the format dd/mm/rrrr
"date in the format dd/mm/rrrr"
that still doesn't answer the question of what you want as a parameter.
Rember, dates don't have formats. Strings have formats.
if you want strings to be your parameter then use my first example.
if you want dates to be your parameter then use my second example and put in the format you want
that still doesn't answer the question of what you want as a parameter.
Rember, dates don't have formats. Strings have formats.
if you want strings to be your parameter then use my first example.
if you want dates to be your parameter then use my second example and put in the format you want
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I get not a valid date error
ORA-01843: not a valid month
ORA-01843: not a valid month
what are you doing?
which version are you using? what are you passing in? how are you using the context? your previous question used it in a view with dd-mon-yyyy string format to convert to a date. Have you changed formats?
which version are you using? what are you passing in? how are you using the context? your previous question used it in a view with dd-mon-yyyy string format to convert to a date. Have you changed formats?
ASKER
As you told me I used the format dd/mm/yyyy in the view and changed the package accordingly.
PROCEDURE test_ctx(p_date in date) IS
BEGIN
DBMS_SESSION.set_context(' mydate', 'given_date', to_char(p_date,'dd-mon-yyy y'));
END;
-----------------------
I get ORA-01843: not a valid month (this error)
PROCEDURE test_ctx(p_date in date) IS
BEGIN
DBMS_SESSION.set_context('
END;
-----------------------
I get ORA-01843: not a valid month (this error)
you changed the view to dd/mm/yyyy
but the package is dd-mon-yyyy?
but the package is dd-mon-yyyy?
ASKER
Sorry it was my mistake (typo)
DBMS_SESSION.set_context(' mydate', 'given_date', to_char(p_date,'dd/mm/yyyy '));
DBMS_SESSION.set_context('
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I am getting the error in the view, when I run my form with that date
ASKER
CREATE OR REPLACE VIEW QC_DAILY_VW
(DEPT_ID, QC_TYPE_ID, QC_SUBTYPE_ID, QC_DATES, CONTROL_NO)
AS
select a.dept_id,a.qc_type_id,
a.qc_subtype_id,b.qc_dates ,b.control _no
from qc_dept_subtypes a,qc_daily b
where a.dept_id = b.dept_id(+)
and a.qc_subtype_id = b.qc_subtype_id(+)
and a.qc_type_id = b.qc_type_id(+)
and b.qc_dates(+) = to_date(sys_context('mydat e','given_ date'),'dd -mon-yyyy' )
(DEPT_ID, QC_TYPE_ID, QC_SUBTYPE_ID, QC_DATES, CONTROL_NO)
AS
select a.dept_id,a.qc_type_id,
a.qc_subtype_id,b.qc_dates
from qc_dept_subtypes a,qc_daily b
where a.dept_id = b.dept_id(+)
and a.qc_subtype_id = b.qc_subtype_id(+)
and a.qc_type_id = b.qc_type_id(+)
and b.qc_dates(+) = to_date(sys_context('mydat
so, the view is dd-mon-yyyy and the package is dd/mm/yyyy ?
and, if the form is generating the error, are you sure you're getting the error in the view
and not in some before-trigger that calls the package?
and, if the form is generating the error, are you sure you're getting the error in the view
and not in some before-trigger that calls the package?
ASKER
I changed the view and its working now. Thanks
ASKER
Thanks a lot