Create a view with a changing where clause

Hi all,
i'm developing an application with oracle forms i want to create a view in the database with a different where clause in every time , the where clause is determined due to the department id of the current user .
thanks alot.

SQL> create view emp_view as select empno, ename, deptno from emp;
View created.
SQL> select * from emp_view where deptno = 10;
     EMPNO ENAME          DEPTNO
      7782 CLARK              10
      7839 KING               10
      7934 MILLER             10
SQL>

Similar Messages

  • Create a view on a table where x = Report_paramter

    Hi people,
    I want to create a view, but in the where clause I wanted to be dependable on the parameter entered in the Report builder parameter form
    Example
    CREATE OR REPLACE VIEW TMP AS
    ( SELECT *
    FROM EMP
    WHERE EMP_NO = &EMP_ID (this will be entered in the parameter form of the report builder)

    Create a package variable and define it in your view.
    Assign the value to parameter before accessing the view.
    CREATE OR REPLACE VIEW TMP AS
    ( SELECT *
    FROM EMP
    WHERE EMP_NO = package.varibale_name

  • How to create a view with parameter?

    who can tell me hwo to create a view with
    parameters just like a cursor?

    Hi,
    This is not possible in Oracle. What u can do is create the view without the where clasue and supply the where clause at runtime.
    Hope this helps...
    Regards,
    Ganesh R

  • How to create a view with parameters; read the documentation but nothing!

    Hello!
    I'm new to the Oracle world but together with my coworkers we need to very quickly study Oracle to figure out whether we'll add Oracle to our list of supported databases or not.
    Question: How do I create a view with parameters?
    I've read the documentation but I could not find this! I found the sql syntax to create a view but no parameters whatsoever...
    I have found on the web some very complicated way of doing this, but doesn't Oracle support Views with parameters?
    The goal here is to return a recordset, don't forget, so,please don't speak about stored procedures unless you are going to tell me how to get a recordset out of a stored procedure! ;)
    Thanks for all your help and attention!
    Jorge C.

    You can set up a parameterized view via context as follows:
    1. Set up a procedure to set your context values:
    create or replace procedure p_set_context (p_context IN VARCHAR2,p_param_name IN VARCHAR2,p_value IN VARCHAR2)
    as
    BEGIN
    sys.dbms_session.set_context(p_context,p_param_name,p_value);
    END;
    2. Create your context using the procedure you just created
    create or replace context my_ctx using p_set_context
    3. This is the test table I'll use
    create table my_table(col1 number)
    and populate it:
    begin
    for v_index in 1..10
    loop
    insert into my_table values(v_index);
    end loop;
    end;
    and the view that will be parameterised
    create or replace view v_my_table as select col1 from my_table where col1 between sys_context('my_ctx','start_range') and sys_context('my_ctx','end_range')
    4. Now set the parameters using the procedure above.
    begin
    p_set_context('my_ctx','start_range','1');
    p_set_context('my_ctx','end_range','5');
    end;
    5. Selecting from my_table will give you 1 to 10 (no surprise there :-) )
    selectng from v_my_table will give you 1 to 5
    You can use the context to set formats etc using the same principle. A common gotcha to watch for is trying to set the context directly using DBMS_SESSION.SET_CONTEXT instead of creating a procedure. This belongs to SYS and SYS won't have the privileges to set your context so you get an insufficient privileges result leading to much headscratching and unnecessary grants (at least that's my understanding of it).
    Sorry Jorge, as you're new to Oracle I should also have pointed out for completeness sake, that you can change the parameters at any time through recalling the p_set_context, for example, following on from above, after your "select * from v_my_table" and seeing 1 to 5, you could then do
    begin
    p_set_context('my_ctx','start_range','3');
    end;
    and when you requery 'Select * from v_my_table' you will now see rows 3 to 5.
    Bit of a simplistic example, but you can see how easy it is. :-)
    Message was edited by:
    ian512

  • Cardinality estimator 2014 is off with OR in where clause

    Here is my test setup on SQL Server 2014.
    -- Create big table
    CREATE TABLE [dbo].[Store](
    Id int IDENTITY(1,1) NOT NULL,
    City int NOT NULL,
    Size int NOT NULL,
    Name varchar(max) NULL,
    CONSTRAINT [PK_Store] PRIMARY KEY CLUSTERED ([Id] ASC)
    GO
    CREATE NONCLUSTERED INDEX [IX_Store] ON [dbo].[Store] (City ASC, Size ASC)
    GO
    -- Fill with 100k rows
    INSERT Store
    SELECT i % 101, i % 11, 'Store ' + CAST(i AS VARCHAR)
    FROM
    (SELECT TOP 100000 ROW_NUMBER() OVER (ORDER BY s1.[object_id]) AS i
    FROM sys.all_objects s1, sys.all_objects s2) numbers
    GO
    -- Create small table
    CREATE TABLE #StoreRequest (City int NOT NULL, Size int NOT NULL)
    GO
    INSERT #StoreRequest values (55, 1)
    INSERT #StoreRequest values (66, 2)
    Now I execute the following query (I force the index to show statistics estimates)
    SELECT s.City
    FROM #StoreRequest AS r
    INNER JOIN Store AS s WITH(INDEX(IX_Store), FORCESEEK)
    ON s.City = r.City AND s.Size = r.Size
    WHERE s.Size <> 1 OR r.City <> 55
    Here are the estimates that I get (I'm not allowed to upload pictures):
    Index Seek IX_Store
    Actual Number of Rows: 90
    Estimated Number of Rows: 50000
    Fixing WHERE clause to use one table not two makes the estimate perfect:
    SELECT s.City
    FROM #StoreRequest AS r
    INNER JOIN Store AS s WITH(INDEX(IX_Store), FORCESEEK)
    ON s.City = r.City AND s.Size = r.Size
    WHERE s.Size <> 1 OR s.City <> 55
    Index Seek IX_Store
    Actual Number of Rows: 90
    Estimated Number of Rows: 89.74
    Switching to 2012 compatibility mode gives estimate of 1 in both cases:
    Index Seek IX_Store
    Actual Number of Rows: 90
    Estimated Number of Rows: 1
    Could anyone explain the first result? I'm a bit worried about it. The fix in this case is trivial, but this problem gave us quite some headache in more complex real life queries with multiple joins.
    Thank you!

    But not full statistics on a field basis, just sometimes some default stats like total row count that some plans will build.  Even your StoreRequest table only has one two-field index that will have a full histogram.
    But I've seen SQL Server make massively bad plans on two-field indexes.
    I've seen SQL Server go wrong one-column indexes, so that is not a very relevant point.
    Temp tables or not, the estimate here is clearly incorrect. SQL Server knows the density of Size and City. It knows the cardinality of the temp table. The density information gives how many rows the the join will produce. The WHERE clause will then remove
    a certain number of rows. With no statistics for the temp table, it does not now how many, but it will apply some standard guess.
    50000 is a completely bogus number, because the join cannot produce that many rows, and SQL Server is able to compute the join with out the WHERE clause decently. (Well, it estimates 90, when the number is 180.) No, this is obviously a case of the cardinality
    estimator giving up completely.
    It is worth noting that both these WHERE clauses gives reasonable estimates:
     WHERE r.Size <> 11 OR r.City <> 550
     WHERE s.Size <> 11 OR s.City <> 550
    Whereas these two gives the spooky 50000:
     WHERE s.Size <> 11 OR r.City <> 550
     WHERE r.Size <> 11 OR s.City <> 550
    Erland Sommarskog, SQL Server MVP, [email protected]

  • Create a view with parameter

    it's posible create a view with parameters?
    i want to create a view and pass it parameters, in the same way when i create a procedure or function.
    i never have seen it, but i would like to know if that's posible
    thanks

    You cannot create a view with parameters. The only way is to use a stored proc to dynamically create the sql statement. The substitution variable approach does not work. SQL*Plus will prompt for the value of the variable at compile time (i.e. when you create the view) and use the value you provide in the view's query.
    SQL> create or replace view jws_test_v as
      2  select * from jws_test where flag = '&flg'
      3  /
    Enter value for flg: AA
    old   2: select * from jws_test where flag = '&flg'
    new   2: select * from jws_test where flag = 'AA'
    View created.
    SQL> select * from jws_test_v
      2  /
    no rows selected
    SQL> select text from user_views where view_name = 'JWS_TEST_V'
      2  /
    TEXT
    select "LEV1","LEV2","LEV3","LEV4","LEV5","LEV6","FC","FLAG","ONAFT","ONAPT","CU
    PEFT","CUPEPT" from jws_test where flag = 'AA'This makes sense, since substitution vartiables are a sqlplus construct, not a sql or Oracle construct. A view constructed in this way would not be callable from anywhere other than sqlplus.

  • Define a Standalone Download Integrator with an Additional Where clause - SQL error

    Hi,
    I am trying to create a standalone integrator with an Additional Where clause. Followed the steps mentioned in the metalink note 360105.1. When I run the integrator, I get the following error message.
    Please resolve the following error to continue.
    SQL error: ORA-00936: missing expression occurred
    processing stored SQL for Content 20007:GENERAL_441_CNT.
    When I look at the log file, here is what I can see:
    10/22/14 10:50 AM AJPRequestHandler-HTTPThreadGroup-15 TRACE          BneHrSQLControl - SQL:SELECT  FROM PER_PEOPLE_V where last_name=$PARAM$.last_name
    10/22/14 10:50 AM AJPRequestHandler-HTTPThreadGroup-15 TRACE          validateSQLStatement value of sqlStatement is: SELECT  FROM PER_PEOPLE_V where last_name=:RSQLP1
    10/22/14 10:50 AM AJPRequestHandler-HTTPThreadGroup-15 DETAIL         BneHrSQLControl.validateSQLStatement() paramName: last_name
    10/22/14 10:50 AM AJPRequestHandler-HTTPThreadGroup-15 DETAIL         BneHrSQLControl.validateSQLStatement() error in SQL: java.sql.SQLSyntaxErrorException: ORA-00936: missing expression
    So, clearly, the SQL statement that is getting built internally is wrong. Ideally, I would expect the statement to be something like this:
    SELECT *  FROM PER_PEOPLE_V where last_name=$PARAM$.last_name.
    RDBMS : 11.2.0.3.0
    Oracle Applications : 12.1.3
    Any pointers towards the resolution of the issue would be of great help.
    Thanks in Advance!
    Lalitha.

    This is a duplicate post of your other question:  create trigger automatic
    DO NOT start duplicate threads for the same question.
    Locking this thread

  • How can i create a view with jdevlopper 10132

    hi,
    i want to know how to create a view with JDeveloper 10132.
    thanks

    Sorry, but I had to jump in here.
    7rouz - you've certainly violated the 10 commandments for posting here...
    Do you want to:
    1). Create a database view directly in the database
    2). Model a database view using the database modeller
    3). Create an ADF BC View Object
    4). Create some type of visual object (web page, Swing panel)
    5). something else.
    Your question is too ambiguous to yield an answer, unless by luck.
    Regards,
    John

  • Need help in creating a view with Encryption for hiding the code used by the multiple users

    Hi,
    Can anyone help me out in creating view with encryption data to hide the stored procedure logic with other users.
    I have create a stored procedure with encryted view but while running this manually temporary views are getting created, therefore the problem is if there are 500 entries then 500 temp views will get created.
    Any solution to aviod creating temporary views, please refer my code below
    USE [etl_validation]
    GO
    /****** Object:  StoredProcedure [dbo].[Pr_DBAccess_mod]    Script Date: 05/23/2014 12:53:22 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    ALTER PROCEDURE [dbo].[Pr_DBAccess_mod](@ETL_CONFIG_ID INT)
    AS
    BEGIN
    DECLARE @openquery NVARCHAR(MAX),
     @DATABASENAME NVARCHAR(100),
     @HIERNAME NVARCHAR(100),
     @TABLENAME NVARCHAR(100),
     @SERVERTYPE NVARCHAR(100),
     @SERVERNAME NVARCHAR(100),
     @USERNAME NVARCHAR(100),
     @PASSWORD NVARCHAR(100),
     @ETL_CONFIG_IDN NVARCHAR(100);
     SET @ETL_CONFIG_IDN=CAST(@ETL_CONFIG_ID AS NVARCHAR);
     SET @TABLENAME='Department';
     SET @SERVERTYPE='SQL';
     SET @SERVERNAME ='192.168.31.176';
     SET @DATABASENAME='AdventureWorks2008R2';
     SET @HIERNAME = 'HumanResources';
     IF @SERVERTYPE='SQL'
     BEGIN
    /*SET @openquery= 'SELECT * INTO ##TestTable
                     FROM OPENROWSET(''SQLNCLI'',''server=192.168.31.176;Trusted_Connection=yes;'','''+@query+''')'
    SET @openquery=  'CREATE VIEW '+@TABLENAME+@ETL_CONFIG_IDN+
                     ' WITH ENCRYPTION AS SELECT * FROM OPENROWSET(''SQLNCLI'',''SERVER='+@SERVERNAME+';TRUSTED_CONNECTION=YES;'',''SELECT * FROM '+@DATABASENAME+'.'+@HIERNAME+'.'+@TABLENAME+''')'
    SELECT @openquery
    END
    EXECUTE sp_executesql @openquery
    END

    Hi aa_rif,
    According to your description and code message, you execute the sp_executesql statement in your stored procedure, it indeed create many views with a tablename and ETL_CONFIG_ID named. If you need not to use these temporary views, you can delete them when
    it contains the tablename in one view name.  
    In addition, if you want to create view with encryption in SQL Server, you can use directly the ENCRYPTION option to encrypt the T-SQL of a view in create view commands, for more information, see:
    http://learnsqlserver.in/4/Create-View-With-Encryption.aspx. if not, you can descript more detail about requriements, so that more forum members can involve into the thread and help you
    out. 
    Regards,
    Sofiya Li
    Sofiya Li
    TechNet Community Support

  • Creating Materialized View with the Distinct key word

    Hi
    I need help to create Materialized View with the Distinct key word.
    my query is
    select distinct col1, col2 from t1;
    is there any alternate of DISTINCT because I can not refresh the MV as fast on demand if I am using it and Fast on Demand is a must for me.

    hi
    check out this link
    http://download-west.oracle.com/docs/cd/B12037_01/server.101/b10736/basicmv.htm#i1007299
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14220/intro.htm#sthref183
    hope this helps
    CHeers

  • How to create a view with a column of counts of the occurence of values

    If my table is:
    ID
    1
    2
    3
    3
    5
    5
    5
    I want to create a view with the following result:
    ID   COUNT
    1     1
    2     1
    3     2
    5     3
    How would I accomplish this?

    Sorry, my mistake. I was thinking about counting distinct events.
    I created a table with your example values:
    You should do a projection with a calculated column = 1:
    And then add this calculated column as an aggregated measure on the aggregation node:
    Result:
    Cheers,
    Fernando

  • Create a View with Aggregation Function (COUNT)

    I've been looking up and down for a way to create a view with a few basic fields and some other fields containing aggregation function.
    For instance:
    To display a view that contain all the Contract Agreement and the corresponding count of the PO releases.
    Agreement Nbr, Total PO releases
    I need this view so that I can create a search help with this view.
    I found something about the "CREATE VIEW" statement, but I don't have any idea how to use it.
    Any helps toward this matter is very much appreciated, thanks.

    Hello Aldern
    I guess you have read about the SQL statement "CREATE VIEW". When we create a view in the dictionary this SQL statement is finally called to create the view on the DB. Thus, since we do not have any aggregation options in views you cannot achieve what you want using views.
    The solution for your problem is to create a <b>search help</b> having a <b>search help exit</b>. Within the exit you can do your aggregation functions and add these values to the displayed search help data.
    Regards
      Uwe

  • On success of form save I want to go to another for with a detail where clause

    I have the follow code snippet which is intented to go to a form on a successfull save. I query some data based on the save then build a url to navigate to a new form. I want the form to show only data that is lacking in one column not being populated (column is null). The url works, but the form detail where clause is ignored. Does anyone have any experience with passing detail where clauses to a form? Did I miss something in the code below?
    begin
    select count(rl_id) into n_rl_id_cnt
    from rfq_lines
    where part_part_id is null and rh_rh_id=n_rh_id;
    exception
    when others then
    null;
    end;
    htp.p('cnt '||to_char(n_rl_id_cnt));
    if n_rl_id_cnt>0 then
    htp.p('cnt >1');
    my_url := 'PORTAL30.wwa_app_module.link?' ||
    'p_arg_names=_moduleid&p_arg_values=3677858481' ||
    '&p_arg_names=_show_header&p_arg_values=YES' ||
    '&p_arg_names=rh_id&p_arg_values=' || LTRIM(TO_CHAR(n_rh_id)) ||
    '&p_arg_names=_rh_id_cond&p_arg_values=%3D'||
    '&p_arg_names=_detail_where_clause&p_arg_values=part_part_id%20is%20null'; -- <this is not working right. where clause is ignored.
    htp.p(my_url);
    go (my_url);

    Hi Jeffrey ,
    You need to use a custom Format script for the field.
    Regards
    Sukrit Dhingra

  • Creating a view with a primary key

    I want to create a view with a defined primary key. I understand
    the view is created within a select statement, but do not
    understand how you would define a particular field as a primary
    key in the view. Also if your select statement attempts to build
    the view and has duplicate keys in the select result set, what
    would happen when the duplicate key is found? Would it just not
    include the duplicate key in the view?
    Thanks in advance for your help.
    -Pat

    I have a rather difficult problem with duplicate invoice numbers
    contained in unique records. In other words I have many records
    that appear as follows:
    3593, 0004009090, CUSTOMER, TAX, 20000117,014011976-01
    4411, 0004009090, CUSTOMER, TAX, 20000718,014011976-01
    The last field is invoice number '014011976-01' In my case I am
    building a flat file using UTL_FILE for loading into SAP
    Business Warehouse. In SAP I need to have Invoice number as a
    key in which case I can't have duplicate invoice numbers. All
    the SQL I have tried to date returns a large amount of records
    similar to the above records. I am selecting these records from
    4 different schemas which represent 4 different companies. I
    realize the data is the problem and that the vendor of the
    product I am working with should not allow records with
    duplicate invoice numbers, but I have to get the data loaded as
    that is what they want and are paying for. So back to my View. I
    was hoping to create a view and be able to work in the view to
    remove duplicate records prior to writing them to a file. Any
    suggestions are welcomed.
    Thanks
    -Pat

  • How to create table view with reference table

    Hi experts,
    How to create table view with reference table in SE11, plz gve me stp by stp procedure.
    pints grnded for hlp.

    Hi
    Go to Tcode se11 choose view and enter the name and create a popup opens up choose database view option
    enter the description
    On the left hand side choose the table name.
    Click on view fields tab and choose your table fields.Here you can choose which fields you want in your view.
    Save and then activate.
    Hope this helps.
    Regards,
    Harish

Maybe you are looking for