Help with Where clause

Hello world

I have an argument to function entry, lets call this file number. This argument can be 0 (zero) or any number like 9800. No negative number.

My where clause, I would like to say, if the number is 0 (zero), then extract all the cases, otherwise just retrieve the lines/records that belong to the passed in file number.

select * 
from table1
where case_num = (if case num is 0 then retrieve all cases, 
                otherwise retrieve only the records that belong to the number passed in)

Thanks in advance.

Select *.

FROM table1

where case_num = num

or num = 0;

SY.

Tags: Database

Similar Questions

  • Need help with where clause

    Hi all

    Could someone please help me on this one where clause.
    The structure of the table like this:

    < code >
    create table (test)
    primary key ID number,
    TYPE_ID number not null,
    name varchar2 (10));

    insert into test values (1, 10, 'name 1');
    insert into test values (2, 10, 'name 2');
    insert into test values (3, 20, 'name 3');
    insert into test values (4, 20, 'name 4');
    insert into test values (5, 20, 'name 5');
    insert into test values (6, 10, 'name 6');
    insert into test values (7, 10, 'name 7');
    commit;

    SQL * more > select * from test;

    TYPE_ID ID NAMES
    ---------- ---------- ----------
    1 10 name 1
    2 10 2 name
    3 20 name 3
    4 20 4 name
    5 20 5 name
    6 10 6 name
    7 10 7 name

    7 selected lines.
    < code >

    Here are the values of the drop-down list box which the user will be able to select
    0 all the project
    Type of project 10 10
    20 of the Type 20

    Based on the selection of the user, we need a SELECT to get all records or certain types of records.

    Thanks in advance!

    Hello

    If: selected_type_ID is the value in the drop-down list (0, 10, or 20), then:

    WHERE   :selected_type_id IN (test.type_id, 0)
    

    This assumes that test.type_id is never NULL.

  • Hi can anyone help with, where can I download 11.1.1.6.0 version of OSB

    Hi can anyone help with, where can I download 11.1.1.6.0 version of OSB

    Hello

    The Oracle Software Delivery Cloud and OTN currently have SP6 / 11.1.1.7 for download.

    Older versions are archived internally, but they are still available.

    File an SR to My Oracle Support , and we will have our support team provide you with a specific url to the platform and the version you need.

    See you soon

    Iain

  • Export (expdp) with where clause

    Hello gurus,

    I'm trying to export with where clause. I am getting error below.


    Here is my order of export.
    expdp "'/ as sysdba'" tables = USER1.TABLE1 directory=DATA_PUMP dumpfile=TABLE1.dmp logfile=TABLE1.log query= “USER1.TABLE1:where auditdate>'01-JAN-10'”
    Here is the error
    [keeth]DB1 /oracle/data_15/db1> DATA_PUMP dumpfile=TABLE1.dmp logfile=TABLE1.log query= USER1.TABLE1:where auditdate>'01-JAN-10'                    <
    
    Export: Release 11.2.0.3.0 - Production on Tue Mar 26 03:03:26 2013
    
    Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.
    
    Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    Starting "SYS"."SYS_EXPORT_TABLE_03":  "/******** AS SYSDBA" tables=USER1.TABLE1 directory=DATA_PUMP dumpfile=TABLE1.dmp logfile=TABLE1.log query= USER1.TABLE1:where auditdate
    Estimate in progress using BLOCKS method...
    Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
    Total estimation using BLOCKS method: 386 MB
    Processing object type TABLE_EXPORT/TABLE/TABLE
    Processing object type TABLE_EXPORT/TABLE/GRANT/OWNER_GRANT/OBJECT_GRANT
    Processing object type TABLE_EXPORT/TABLE/INDEX/INDEX
    Processing object type TABLE_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
    Processing object type TABLE_EXPORT/TABLE/TRIGGER
    Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
    ORA-31693: Table data object "USER1"."TABLE1" failed to load/unload and is being skipped due to error:
    ORA-00933: SQL command not properly ended
    Master table "SYS"."SYS_EXPORT_TABLE_03" successfully loaded/unloaded
    ******************************************************************************
    Dump file set for SYS.SYS_EXPORT_TABLE_03 is:
      /oracle/data_15/db1/TABLE1.dmp
    Job "SYS"."SYS_EXPORT_TABLE_03" completed with 1 error(s) at 03:03:58
    Version
    SQL> select * from v$version;
    
    BANNER
    --------------------------------------------------------------------------------
    Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
    PL/SQL Release 11.2.0.3.0 - Production
    CORE    11.2.0.3.0      Production
    TNS for IBM/AIX RISC System/6000: Version 11.2.0.3.0 - Production
    NLSRTL Version 11.2.0.3.0 - Production

    Hello

    You must use the settings file. Another question, I see you are using 11g. Why don't you use a data pump.?
    Data pump is faster and has more features and that regular improvement imp and exp.

    You can do the following:

    sqlplus / as sysdba
    
    Create directory DPUMP_DIR3  for 'Type here your os path that you want to export to';
    

    then tap on a file:
    Touch par.txt

    In this file, type the following line the following:

    tables=schema.table_name
    dumpfile=yourdump.dmp
    DIRECTORY=DPUMP_DIR3
    logfile=Your_logfile.log
    QUERY =abs.texp:"where hiredate>'01-JAN-13' "
    

    then proceed as follows
    expdp username/password name parfile = 'par.txt'

    You will import to Oracle 11 g to 10g version should add 'version = 10' parameter in the above setting file

    BR
    Mohamed enry
    http://mohamedelazab.blogspot.com/

  • 8287 error: manual/refresh operations with Where clause

    Hello

    I defined a group of read-only cache

    CREATE CACHE READONLY ABC GROUP

    AUTOREFRESH INTERVAL 60 seconds

    OF ORACLE_TABLE

    I want to only load the 3 months of the underlying table for Oracle data so I don't


    ABC LOADING CACHE GROUP

    WHEN TRUNC (date_column) > TRUNC (add_months (sysdate,-3))

    COMMIT ALL 256 ROWS

    4 PARALLEL;

    However, I get the error message

    8287: manual LOADING/REFRESH with clauses WITHID or WHERE operations are not be allowed on ABC Group cache because it is specified as AUTOREFRESH

    The command failed.

    What should I do to load the data of 3 months only if possible? Can I use autorefresh?

    Thanks in advance

    Cache AUTOREFRESH groups to include the WHERE clause in the definition of Group of cache. For example, if drop you in Oracle's:

    CREATE TABLE MYDATE

    (

    C1 VARCHAR2 (10) NOT NULL PRIMARY KEY,

    C2 DATE NOT NULL

    );

    Then your cache group definition would look like this:

    CREATE CACHE READONLY ABC GROUP

    AUTOREFRESH INTERVAL OF 60 SECONDS

    OF MYDATE

    (

    C1 VARCHAR2 (10) NOT NULL PRIMARY KEY,

    C2 DATE NOT NULL

    )

    WHEN TRUNC (c2) > TRUNC (add_months (sysdate,-3));

    And then you would load by using

    ABC LOADING CACHE GROUP

    COMMIT ALL 256 ROWS

    4 PARALLEL;

    As auto refreshes occur time passes, all the data that falls outside the range will be removed from the cache and new data that now lying in the range will be added to the cache.

    Chris

  • Case with where clause - ORA-00920: invalid relational operator

    Hi all, when I try to run the following query, I get the following error...

    ORA-00920: invalid relational operator

    00920 00000 - "invalid relational operator.

    * Cause:

    * Action:

    Error on line: column 16: 5

    Anyone know what the problem with my request? Thanks in advance.

    SELECT concat (year, period)

    OF DD_ACTUALS_FACT

    CASE WHERE period

    WHEN 'JAN' THEN '01'

    WHEN 'FEB' THEN '02'

    WHEN 'MAR' THEN ' 03 "

    WHEN "APR" THEN ' 04 "

    WHEN 'CAN' THEN ' 05 "

    WHEN "JUN" THEN '06'

    WHEN 'JUL' THEN '07'

    WHEN 'AUG' THEN '08'

    WHEN 'MS' THEN '09'

    WHEN 'OCT' THEN '10'

    WHEN 'NOV' THEN '11'

    WHEN 'DEC' THEN '12'

    END as number 'months '.

    ORDER OF CONCAT (year, number 'months') / / DESC

    The problem is the number 'month' - you cannot give an "ACE" alias for an expression in a where clause clause.

    You have not really given any condition, that a set of translations of period in a number.

    Also, you didn't say what you're trying to do.

    Maybe you want to:

    SELECT concat (year, period)

    OF DD_ACTUALS_FACT

    WHERE something

    ORDER OF CONCAT (year, period of the CASE

    WHEN 'JAN' THEN '01'

    WHEN 'FEB' THEN '02'

    WHEN 'MAR' THEN ' 03 "

    WHEN "APR" THEN ' 04 "

    WHEN 'CAN' THEN ' 05 "

    WHEN "JUN" THEN '06'

    WHEN 'JUL' THEN '07'

    WHEN 'AUG' THEN '08'

    WHEN 'MS' THEN '09'

    WHEN 'OCT' THEN '10'

    WHEN 'NOV' THEN '11'

    WHEN 'DEC' THEN '12'

    END DESC)

    /

  • Help with the clause of "default".

    Hi all

    I have a scenario where there is a table with 75 columns. out of the 75 columns, 30 are varchar and 30 are digital. The remaining columns are other types of data when creating the table, that I forgot to mention the default values to varchar and numeric columns.

    Now, approximately 20,000 records are inserted into the table where some records contain NULL varchar and numeric. Now, I want to replace the null with varchar values and digital default values respectively.

    I can change the columns by adding the clause by default now and update the lines of NULL for the default values accordingly. But this process could be very heavy.

    Is there a better way to do this. Please help me.

    Thanks in advance,
    Rambeau

    I want to know that is it possible to set the default values for all columns of type varchar, both using a single SQL statement. Then you can update all the values NULL with default values.

    You are looking for something like this?

    SQL> create table t (empno default 1, ename default 'x') as select cast(null as integer) empno, cast(null as varchar2(10)) ename  from emp where rownum <= 4
    /
    Table created.
    
    SQL> select * from  t
    /
         EMPNO ENAME
    ---------- ----------
    
    4 rows selected.
    
    SQL> update t set empno = default, ename=default
    /
    4 rows updated.
    
    SQL> select * from  t
    /
         EMPNO ENAME
    ---------- ----------
             1 x
             1 x
             1 x
             1 x         
    
    4 rows selected.
    
  • ORA-01427 with WHERE clause and CASE statement

    Hi guys,.
    I get the error ORA-01427 when you try to select * from my dimension table
    When the parameter: P_HZA is 4. I used the keyword IN but the error still appears.
    no idea why?

    Select * from testtab
    where mycar = 4
    and "coretable". "" HZA ' IN
    CASE
    When: P_HZA = "4" then (button SELECTION OF DIM_HZA)
    other: P_HZA
    END

    Thank you

    you missed table_name and also this can cause several error so lines (ORA-01427: einreihig subquery returns more than one line)

    SELECT *
      FROM tableA
     WHERE mycar = 4
           AND "coretable"."HZA" IN
                  CASE
                     WHEN :P_HZA = '4' THEN (SELECT key FROM DIM_HZA)   ---- may be you need to have max  to get only one value
                     ELSE :P_HZA
                  END
    

    See you soon,.
    Manik.

  • By using a WHERE clause in the tree APEX

    Hi all -

    I have a hierarchical SQL query that I display as a tree of the APEX.

    Here is my sample application:

    https://Apex.Oracle.com/pls/Apex/f?p=32581:29

    Login: guest

    PW: app_1000

    workspace: leppard

    I try to add a WHERE clause so that only nodes with the lowest-level children are displayed, i.e. something like "WHERE connect_by_isleaf = 0 OR level = 5'"

    The tree of query with where clause works very well in the SQL command window, but when I add the WHERE clause to my tree apex page no longer displays anything. Is this a problem with APEX or y at - it another way to filter my results?

    Thanks in advance for your suggestions,

    John

    Connect occurs in the first place, the where the provision is applied to these results, effectively cutting in the hierarchical structure. Since the apex has build a hierarchical structure of the query, it relies on the virtual level, which is butchered by applying the where clause. It's a miracle that you're not even receive errors because I expect almost an incorrect json array was built. With no top-level from and only level 5 or end nodes, there is no structure to present: the two apex cannot set a correct representation and not jstree neither. In your request, you will see your "root nodes", but it is not representable.

    I don't know why you want to present it in a tree? Levels both connect_by_is_leaf = 5 will give you everything just a list of nodes without any hierarchical structure.

    The best thing to do is to use a subquery to limit first your dataset and then use it for the basic tree query, this way you violate one of these vital columns.

    For example if you want only nodes and their immediate parent, you can opt for something like this (fast on some testdata model):

    with dataset as (
    select node_id, parent_id
       from treedata
      where connect_by_isleaf = 0
    connect by prior node_id = parent_id
      start with parent_id = 0
    ),
    dataset2 as (
    select node_id, parent_id
      from dataset
    union all
    select node_id, null parent_id
      from treedata
    where node_id in (select parent_id from dataset)
    )
    select level, node_id
       from dataset2
    connect by prior node_id = parent_id
      start with parent_id is null
    
  • Can I use truncated and where clause in the statement even?

    Hello guys,.

    Can I use truncated with where clause in the same statement.


    For ex:

    TRUNCATE TABLE my_table WHERE id < 500;

    If not, that you recommend me to overtemperature to the level of high water line?


    By the way
    select * from v$version;
    Oracle Database 11 g Enterprise Edition Release 11.2.0.1.0 - 64 bit Production
    PL/SQL Release 11.2.0.1.0 - Production
    "CORE 11.2.0.1.0 Production."
    AMT for 64-bit Windows: Version 11.2.0.1.0 - Production
    NLSRTL Version 11.2.0.1.0 - Production
    >

    Thank you very much.

    Published by: 970992 on 11:14 13.Ara.2012

    >
    Okay I need an increasing amount of space. However, at the same time I want to recover the spaces empty below HWM. So, I need to use less amount of space I am inserting. Therefore, shouldn't use retractable for this?
    >
    Why waste the effort. Oracle will reuse the space below the HWM when doing inserts. You already said that you insert more lines you delete so all these will be more accustomed to the top.

    The only time where that oracle may not use space is when the space is too small to be useful. It is documented in the doc, I told you
    >
    Understanding recoverable unused space
    Over time, Update, and Delete on objects within a tablespace can create pockets of empty space that individually are not large enough to be reused for the new data.
    >
    Most uses of CONTRACTION I've seen are totally useless. If you follow the doc and run the Advisor of segment it will tell you if there is space that can be retrieved and how much. But, even once, for your use even if case will get you will Oracle while you need to reassign the new extensions, then the HWM will just go still higher.

    If pay you a heavy price in Oracle did a full table scan, update of many blocks from the table, update THE index, impact performance for other users to access the table during the SHRINK and reallocate extensions (maybe even some of the same areas) when you insert more data.

    Do not SHRINK unless you know it's necessary.

  • Need help with dynamic where clause.

    Hello world.  I'm kind of a novice with PL/SQL, so please be patient with me.  I am building a web application using Weblogic Oracle 11 g and Oracle database.

    To make a long story short, I need to generate the complex dynamic WHERE clause.  I don't know what will be the name of the column or the operator of comparison or the value will be until the moment of execution.

    I'm not 100% certain, but I think I need to use dynamic SQL statements.  Unless there is a better way to do it.

    I'm sure that using dynamic SQL opens me up to SQL injection attacks if I use simple string concatenation.  I would like to use bind variable if possible.

    In any case, it seems like trying to build a dynamic where clause does not seem to work as I want it would be...

    bv1 := 'colA = 5 and colB >= 9';
    
    query_str := 'SELECT * FROM view WHERE :bv1';
    
    OPEN CUR FOR query_str USING bv1;
    

    The code above pours out when I try to run it.

    Is there a way to build dynamic where the provisions without the use of concatenation of simple string that leaves me open to attacks by SQL injection?

    Thank you

    Hello.  I have read briefly upward on things, you suggested, but it seems a bit abstract for me since I was a novice.

    Can you give us an explanation or an example of how to use it to accomplish what I need to do?

    Do ypu really plan create a query with a WHERE clause that contains a predicate for all possible columns?

    Variable bind offer performance when the same query is executed several times with different values for bind variables.

    Select * from emp where empno =: v_empno

    After the first run Oracle will always be this query in the library cache. The next running can use the version of the cache even if the bind value is different.

    Select * from emp where empno =: v_empno;

    Select * from emp where ename =: v_ename;

    Select * from emp where sal =: v_sal;

    Each one is a DIFFERENT query. Yes - each of them uses a variable binding, but queries are different.

    So, if your username select EMPNO, an '=', and a value from the first query can be executed. But the next time that the user can select the ENAME column so that 'stored' first request may not be used given that the query does not match.

    The third time your user selects SAL so none of the first two queries can be used in the library cache. The use of bind variables gives performance during the SAME QUERY is used multiple times with DIFFERENT values for the variable binding. Oracle is not to analyze the hard query everything simply because the VALUE is different.

    So bind variables do not help you if most of the queries were completely DIFFERENT sets of predicates. And SYS_CONTEXT will not help either since that simply provides a way to define binds the values of the variables.

    Just for the simple example above, there are at least SIX possible combinations of columns that could choose your user name: empno, ename, sal, empno ename, empno & sal, ename & sal

  • Where clause ' where 1 = 1 ' help with SQL tuning

    Hello Tuning specialists,.
    It is useful to use ' where 1 = 1 ' and then type all joins and conditions in the statements 'AND' of the SQL when writing SQL queries. I would like to know if it helps with the writing queirs this way SQL query performance.

    Thanks in advance.

    Published by: oracle_developer on October 8, 2012 10:41

    oracle_developer wrote:
    Hello Tuning specialists,.
    It is useful to use ' where 1 = 1 ' and then type all joins and joins in the statements "AND" when writing SQL queries.
    I would like to know if it helps with the writing queirs this way SQL query performance.

    He has No. performance impact.
    It is done when building dynamic SQL, so each sentence can start with AND

  • With the help of a list in a clause Where Clause

    I try to use a dynamic list, in a where clause clause, not having much luck and we tried different ways.

    Here's the closest thing I can find, the only problem is that the output returns an error caused by comma in where criteria if the list contains several items.

    Any help would be greatly appreciated!

    SELECT is the name of my list by commas.

    < name cfquery = 'list' datasource = "#dbnm #" >
    SELECT *.
    Students
    When status = ' #x # ' and (id = #Listqualify(select,"") #)
    < / cfquery >

    When the use of lists in sql, you do not use an equal sign. You use the key word in. You must also put your list in parentheses.

  • Passing the value of the where clause with the page

    Dear friends,

    I have a requirement like when I select a selection list value I should pass this value to sql query where clause without submitting the page

    ex I have a select like: P1_Dept guess I selects the value 10 in this

    then I have a query select * from emp where deptno =: P1_Dept.

    DB. ORACLE 11G

    APEX 4.1.1.00.23

    is this possible? can someone help me please in this topic

    Thanks and greetings

    Vballeda

    Suppose we have the selection list with the name P1_DEPT and query for report

    select * from emp where deptno = :P1_DEPT
    

    We create dynamic Action on the evolution of the P1_DEPT point. We will need two real actions:

    1-> set value action

    Set the Type - > body of the PL/SQL function

    The function of body - > return 1;

    Page item to submit-> P1_DEPT

    Change to delete-> Yes event

    Selecttion Type-> trigger element

    2. action-> Refresh

    Selecttion Type-> region

    Region-> your region of report

  • How to create a procedure for REF CURSOR output with any WHERE clause?

    I have a requirement like this: I have a huge question that need to reuse in my code over 10 times. This SQL has about 50 lines. Here for these 10 odd times sometimes changes in WHERE clause (columns are the same). So I can't create a view as SQL is not static.

    I thought to write a procedure with a para of WHERE_CLAUSE entry. I pulled out a refcursor sys by adding where clause. But I can't do it because you cannot add a clause like this where clause.

    i.e.
    PROCEDURE dynamyic_query (p_where_clause IN VARCHAR2, p_out_query OUT SYS_REFCURSOR ) IS
    BEGIN
    
      OPEN p_out_query FOR SELECT ......... FROM table WHERE || ' ' || p_where_clause;
    
    END;
    The foregoing gives an error.

    How to handle such a situation? Any help would be greatly appreciated.

    Hello

    Channa wrote:
    ... However, when I change the procedure like this:

    PROCEDURE FORMS_TEXT_DYN_SQL_TEST(p_where_cluase IN VARCHAR2, p_out_cursor OUT SYS_REFCURSOR) IS
    v_stmt VARCHAR2(1000);
    BEGIN
    v_stmt := 'SELECT tname FROM tab_test WHERE tname LIKE ''%ABS_V4%'' AND :y';
    
    OPEN p_out_cursor FOR v_stmt using p_where_cluase;
    
    END;
    

    And run this block of code:

    declare
    v_tname varchar2(200);
    out_cursor sys_refcursor;
    begin
    forms_text_dyn_sql_test(' 1 = 1 ', out_cursor );
    LOOP
    fetch out_cursor INTO v_tname;
    exit when out_cursor%NOTFOUND;
    DBMS_OUTPUT.PUT_LINE(v_tname);
    END LOOP;
    end;
    /
    

    I get the error:

    [1]: (Error): ORA-00920: invalid relational operator ORA-06512: at "ABS.FORMS_TEXT_DYN_SQL_TEST", line 6 ORA-06512: at line 5
    

    Looks like you can only set column_name =: z, column_name =: values of type y. You can not it seems to replace it with no WHERE CLAUSE?

    A bind variable, such as: it, represents a single value.
    If: is the VARCHAR2 '1 = 1', then

    SELECT tname FROM tab_test WHERE tname LIKE '%ABS_V4%' AND :y
    

    takes the value

    SELECT tname FROM tab_test WHERE tname LIKE '%ABS_V4%' AND '1 = 1'
    

    I think you want something like this:

    CREATE OR REPLACE PROCEDURE FORMS_TEXT_DYN_SQL_TEST
    (     p_where_clause      IN      VARCHAR2
    ,      p_out_cursor      OUT      SYS_REFCURSOR
    ) IS
      v_stmt VARCHAR2(1000);
    BEGIN
      v_stmt := 'SELECT ename FROM scott.emp WHERE ename LIKE ''%A%'' AND '
              || p_where_clause;
    
      OPEN p_out_cursor FOR v_stmt;
    
    END;
    /
    show errors
    
    SET  SERVEROUTPUT  ON
    
    declare
      v_tname varchar2(200);
      out_cursor sys_refcursor;
    begin
      forms_text_dyn_sql_test(' 1 = 1 ', out_cursor );
      LOOP
        fetch out_cursor INTO v_tname;
        exit when out_cursor%NOTFOUND;
        DBMS_OUTPUT.PUT_LINE(v_tname);
      END LOOP;
    end;
    / 
    

    Output:

    ALLEN
    WARD
    MARTIN
    BLAKE
    CLARK
    ADAMS
    JAMES
    

Maybe you are looking for

  • v10.11.3 El Capitan iMac freezes frequently at the login screen

    My iMac has been humming without any problem and superbly quick, recently, it has begun to drip slowly, often it hangs on the login screen, it is sometimes a complete crash with a full reboot! Can someone advise how to diagnose and fix this problem?

  • Pavilion dv6 6119tx: dv6 beatsaudio driver 6119tx

    Mr President My computer hp pavilion dv6 6119tx laptop. Kindly give me link of the driver software audio beats & bio metric software driver link (hp simple pass JJUJ print).

  • Chess Titans works fine on my pc windows 7, but not on windows XP

    Chess Titans works fine on my pc windows 7. I managed to find a copy of the titans of chess for my little Asus XP runnuing, I take with me on a trip. The problem I have is that there is no way to play as the first to have black. It is in white by def

  • disable the port on a HP5550n usp

    How can I disable USB ports & parallel on a HP5550n? I need to completely disable these ports.

  • Need help with ics. SQL return null

    Hi experts WCS.I have this ics. SQL statement that returns an IList as null and nothing in the errStr in debugging print.IList rsATypes is ics. SQL (, sqlATypes, listName, limit, bCache errStr);The code is in one of my jsp. He ran very well in my loc