Re: Use bind variables in a view



On 16 Nov 2005 16:43:23 -0800, "Chelsea" <mtbgirl@xxxxxxxxx> wrote:

>- Hi
>Ideally I would love to use variables defined and assigned inside a
>view.
>
>create or replace view as rates
>as
>declare
> d_sysdate date;
> d_start_date date;
> d_end_date date;
>
>begin
>d_sysdate := ADD_MONTHS(current_date,-1);
>d_start_date :=
>TO_DATE('01-'||TO_CHAR(d_sysdate,'MON')||'-'||TO_CHAR(d_sysdate,'YYYY'));
>d_end_date := LAST_DAY(d_sysdate);
>
>When I try to create the view - it is unhappy because the select is not
>where it expects to see it. ( I am assuming that I simply can not do
>that.. yes I know what happens when you assume)
>
>SOOO I was reading somewhere .. and I can not seem to find it again ..
>Is to basically wrap the view creation with a stored procedure, create
>and assign the variables in the stored procedure, then do create the
>view using execute immediate (I think)
>
>This is procedure that would have to be run once a month, to refresh
>the dates to the current date.
>
>Does any one have any other ideas, or any comments about this approach?
>
>Thanks
>C.M.

Basically what you need to do (and it works like a charm) is
- set up a package
- define the variables in the package spec
- have one procedure per variable (in the package) to set the variable
- have one function per variable (in the package) to get it's value
- use the function in the view definition

Alternatively (courtesy of Tom Kyte) you could set up a context, and
use the sys_context function to get the value of your variable.
According to Tom, that approach works better. Refer to
http://asktom.oracle.com

--
Sybrand Bakker, Senior Oracle DBA
.



Relevant Pages

  • Re: How to force a SSIS package step to fail?
    ... I've now tried to add an Expression to the Precedence Constraints, bit I have some troubles defining the Varible it's going to look at..:-(. ... My Stored Procedure returns a character value, but when I set the step to return the value to the type String, then I get an "String: the Size property has an invalid size of 0" error everytime I execute the task. ... Why would you want the package to fail? ... could "fail" steps in order to control package flow, ...
    (microsoft.public.sqlserver.dts)
  • Re: I just want to run a stored procedure...
    ... I have a stored procedure that I want to run.The shell of it is ... PROCEDURE CODE0 (pCUR1 OUT CUR, ... You can't run a package, only the procedures and functions within it: ... I guess I just need to declare one? ...
    (comp.databases.oracle.server)
  • Re: remotely call a DTS
    ... I am not sure right now whether you get Access Denied on the package or Access Denied on something inside the package. ... This worked when I was logged into the server and ran it from my ... but the DTS blows up. ... The only time this stored procedure hsa worked was when I ran it ...
    (microsoft.public.sqlserver.dts)
  • Re: Delete DTS Package in code
    ... How can I run a package ... >asynchronously without saving it to run it through a stored procedure? ... Stick with the save, execute and delete. ... global community for SQL Server professionals ...
    (microsoft.public.sqlserver.dts)
  • Re: Previously Undiscovered Oracle Gold
    ... | I was looking around the OWA_UTIL package over the weekend and found ... | Daniel Morgan ... Is this not the procedure written by Tom Kyte years ago? ... Michel Cadot ...
    (comp.databases.oracle.server)