Reg: Nullable column search

Hi all,
I have a table DIAGNOSIS which has a QDESC as a nullable column.
columns DIAGCODE and SDESC are not nullable.
I have written a Stored Procedure to retrieve records from DIAGNOSIS table based on the columns values specified.
p_<column_name> indicates the parameter passed to the Stored Procedure
The correspong SQL statement goes as follows.
SELECT * FROM DIAGNOSIS
WHERE
UPPER(DIAGCODE) LIKE
(CASE WHEN LENGTH(p_DIAGCODE) > 0 THEN '%' || UPPER(p_DIAGCODE) || '%' ELSE '%' END)
AND UPPER(SDESC) LIKE
(CASE WHEN LENGTH(p_SDESC) > 0 THEN '%' || UPPER(p_SDESC) || '%' ELSE '%' END)
-- QDESC is a nullable field; but the following logic doesnt work :-(
AND UPPER(QDESC) LIKE
(CASE WHEN LENGTH(p_QDESC) > 0 THEN '%' || UPPER(p_QDESC) || '%' ELSE '%' END)
Sample data of the table is as follows.
DIAGCODE SDESC QDESC
123 DESC 1 AAA
123 DESC 2
123 DESC 3 BBB
123 DESC 4
When I use the above query to find records with DIAGCODE as 123, I get
DIAGCODE SDESC QDESC
123 DESC 1 AAA
123 DESC 3 BBB
i.e QDESC with null values are not displayed.
How am I supposed to modify the query to get the correct result?
Any help would be highly appreciated.
Thanks n Regards,
Tanuja

Let's assume the formal parameter is called p_column_name.
The actual content of that parameter is 'DIAGCODE' or 'Q_DESC' or whatever.
In static sql
you can only have
&lt;column_name&gt; = &lt;constant&gt;
and &lt;constant&gt; can be replaced by a bind variable.
This construct
select *
from &lt;table&gt;
where p_column_name is null
is not going to work, as there is no p_column_name in that table.
This construct
declare
dynstr varchar2(100);
p_dummy varchar2(100);
p_column_name varchar2(30);
begin
p_column_name := 'bar';
dynstr := 'select bar from foo where '||p_column_name||' is null';
execute immediate dynstr into p_dummy;
end;
although silly dummy code is going to work.
Hth
Sybrand Bakker
Senior Oracle DBA

Similar Messages

  • Interactive report column search not working

    Hi,
    On Apex 4.01 and discovered that when using the individual column search functionality (clicking on the column label), the search on a column for a userid, the dropdown listing is not showing all userids that are clearly listed in the report. For example, the dropdown only shows up through IDs starting with 's--------' so when I search for an ID with 'vm' it does not show it, yet I can do a sort and go down the rows on the report and find it. Is there a limit to the dropdown list? Or is this a bug?
    Pat

    Hi,
    Login to APEX builder. Run your page.
    Select columns from report action menu and save default layout.
    Regards,
    Jari

  • User_tab_cols - nullable column?

    Dear All,
    check the workflow:
    C:\>sqlplus scott/tiger
    SQL*Plus: Release 10.2.0.1.0 - Production on Fri Apr 4 16:20:48 2008
    Copyright (c) 1982, 2005, Oracle. All rights reserved.
    Connected to:
    Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
    With the Partitioning, OLAP and Data Mining options
    SQL> CREATE TABLE TEST
    2 (ID NUMBER(*,0))
    3 /
    Table created.
    SQL>
    SQL> ALTER TABLE TEST ADD (CONSTRAINT TEST_ID_NOT_NULL CHECK (ID IS NOT NULL) EN
    ABLE)
    2 /
    Table altered.
    SQL>
    SQL> DESC TEST
    Name Null? Type
    ID NUMBER(38)
    SQL>
    SQL> -- Null? -> NULL
    SQL>
    SQL> SELECT TABLE_NAME
    2 ,NULLABLE
    3 FROM USER_TAB_COLS
    4 WHERE TABLE_NAME = 'TEST'
    5 /
    TABLE_NAME N
    TEST Y
    SQL>
    SQL> -- Nullable? Since when? I've declared a constraint on it. Ok, let's try:
    SQL>
    SQL> INSERT INTO TEST (ID) VALUES (NULL)
    2 /
    INSERT INTO TEST (ID) VALUES (NULL)
    ERROR at line 1:
    ORA-02290: check constraint (SCOTT.TEST_ID_NOT_NULL) violated
    SQL>
    SQL> -- True, I have a check constraint on the ID.
    SQL> -- But why is the column nullable if I check the user_tab_cols?
    SQL> -- I don't see the difference between forcing Oracle to add
    SQL> -- constraints automatically at creation time
    SQL> -- (create table test (id number not null)) and
    SQL> -- adding constraints manually... It will use constraints
    SQL> -- anyway...
    SQL>
    SQL> -- Don't forget to clean up!
    SQL> DROP TABLE TEST CASCADE CONSTRAINTS
    2 /
    Table dropped.
    SQL>
    Any thoughts?
    Thanks,
    Franky

    Franky,
    Oracle has worked this way for as long as I can remember. Observe
    UT1 > create table t1 (col1   varchar2(10)  not null);
    Table created.
    UT1 > desc t1
    Name                                      Null?    Type
    COL1                                      NOT NULL VARCHAR2(10)
    UT1 > select search_condition from dba_constraints where table_name = 'T1';
    SEARCH_CONDITION
    "COL1" IS NOT NULL
    UT1 > drop table t1
      2  /
    Table dropped.
    UT1 > create table t1 (col1 varchar2(10) );
    Table created.
    UT1 > desc t1
    Name                                      Null?    Type
    COL1                                               VARCHAR2(10)
      1* alter table t1 add (Constraint t1col1 check (col1 is not null))
    UT1 > /
    Table altered.
    UT1 > desc t1
    Name                                      Null?    Type
    COL1                                               VARCHAR2(10)
      1* select search_condition from dba_constraints where table_name = 'T1'
    UT1 > /
    SEARCH_CONDITION
    col1 is not nullUsing the "not null" keywords in the create table results in Oracle setting a switch as being turned on. It is this setting that describe reads for the table not null column. But in both cases dba_constraints will show a check constraint.
    It is just the way it is. I suggest using the "not null" key words on the table create rather than setting explicit column level constraints for the columns.
    I just noticed that in the first case that the column name is in double quotes in the search condition and is the second it is not.
    HTH -- Mark D Powell --

  • NULLABLE column is not updated after the NOT NULL constraint definition...

    Hi,
    SQL> select column_name,nullable from all_tab_columns where table_name='EMP';
    COLUMN_NAME                    NULLABLE
    EMPNO                          N
    ENAME                          Y
    JOB                            Y
    MGR                            Y
    HIREDATE                       Y
    SAL                            Y
    COMM                           Y
    DEPTNO                         Y
    CODE_POLEIS_DIAM               Y
    9 rows selected
    SQL> ALTER TABLE EMP add constraint emp_job_nn check(job is not null);
    Table altered
    SQL> select constraint_name from all_cons_columns
      2  where table_name='EMP';
    CONSTRAINT_NAME
    FK_DEPTNO
    PK_EMP
    EMP_JOB_NN
    SQL> select column_name,nullable from all_tab_columns where table_name='EMP';
    COLUMN_NAME                    NULLABLE
    EMPNO                          N
    ENAME                          Y
    JOB                            Y                         <---------'NULL'
    MGR                            Y
    HIREDATE                       Y
    SAL                            Y
    COMM                           Y
    DEPTNO                         Y
    CODE_POLEIS_DIAM               Y
    9 rows selected
    Why is not updated....????
    In Oracle ebook:
    Oracle® Database Reference
    10g Release 2 (10.2)
    Part Number B14237-02
    the comments about the NULLBLE column are as follows:
    "Specifies whether a column allows NULLs. Value is N if there is a NOT NULL constraint on the column or if the column is part of a PRIMARY KEY. The constraint should be in an ENABLE VALIDATE state."
    BUT BY DEFAULT ALL CONSTRAINTS ARE IN VALIDATE STATE
    (Ref: Oracle® Database SQL Reference
    10g Release 2 (10.2)
    Part Number B14200-02 )Note : I use OraDB 10g v.2
    Thanks a lot
    Sim

    Hi,
    Tom Kytes answer it before:
    SQL> create table t ( id int );
    Table created.
    SQL> desc t
    Name                            Null?    Type
    ID                                       NUMBER(38)
    SQL> alter table t add constraint t_nn check (id is not null);
    Table altered.
    SQL> insert into t (id) values (null);
    insert into t (id) values (null)
    ERROR at line 1:
    ORA-02290: check constraint (TANDREWS.T_NN) violated
    SQL> desc t
    Name                            Null?    Type
    ID                                       NUMBER(38)
    Followup July 16, 2003 - 10am US/Eastern:
    that is not a NOT NULL constraint, that is a check constraint
    ops$tkyte@ORA920LAP> create table t ( x int );
    Table created.
    ops$tkyte@ORA920LAP> alter table t modify x not null;
    Table altered.
    ops$tkyte@ORA920LAP> set linesize 50
    ops$tkyte@ORA920LAP> desc t
    Name                    Null?    Type
    X                       NOT NULL NUMBER(38)To see the full thread in asktom, please refer to:
    - http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:1338402651192
    Cheers,
    Francisco Munoz Alvarez
    http://www.oraclenz.com

  • Reg: full database search:

    Hi Experts,
    I need to search entire database for a particular column value and list down all the table & column names holding it.
    But want to achieve it using SQL and not PL/SQL.
    Is this possible?
    I remember seeing some XML solution to this kind of problem earlier. But not getting it right now.
    Any pointers how to achieve this? Help is highly appreciated.
    - Ranit
    (on Oracle Database 10g Enterprise Edition Release *10.2.0.5.0* - 64bi)

    I've met more or less this requirement. The DB had a corrupt entity and they needed to find all references to that entity's ID in a schema that a) lacked foreign key constraints (for legitimate reasons) and b) sometimes stored foreign keys in user-metadata defined columns.
    They didn't really need to search every column, but they couldn't easily identify which columns they needed to search.
    The query using user_tables / user_tab_columns and querying each table once for each column of the right data type ran for many hours.
    Much better to at least identify all the possible columns in a table and query that table once with an OR.
    Much much better to identify the right columns.

  • Multiple Column search based on column name

    Hi, Can anybody please help me with my issue. I have a table containing about 100 columns, I am using application express. I want to use a textbox for input, and input will be column name i.e. say one of the column name is "PARK" when user type park in that textbox and click on go or search it will display the records for "PARK" column. How can I do that.
    I am trying like this - select :P124_PARK_NAME from wp_parks.
    it displays the result but display "PARK" instead of actual data for that column. Please help...

    I would prefer some thing like this.
    SQL> create table hx_test
      2  as
      3  select level as rno
      4    from dual
      5  connect by level <=10
      6  /
    Table created.
    SQL> create or replace type num_type as table of number
      2  /
    Type created.
    SQL> create or replace package get_col_val
      2  as
      3     function get(pCol_Name in varchar2, pTable_Name in varchar2) return num_type PIPELINED;
      4  end get_col_val;
      5  /
    Package created.
    SQL> create or replace package body get_col_val
      2  as
      3      function get(pCol_Name in varchar2, pTable_Name in varchar2) return num_type PIPELINED
      4      as
      5       lcol_val number;
      6       lref_cur sys_refcursor;
      7     begin
      8              open lref_cur for 'select ' || pCol_Name || ' as col from ' || pTable_Name;
      9
    10              loop
    11                      fetch lref_cur into lcol_val;
    12                      exit when lref_cur%notfound;
    13                      pipe row (lcol_val);
    14              end loop;
    15
    16              close lref_cur;
    17
    18              return;
    19     end;
    20  end get_col_val;
    21  /
    Package body created.
    SQL> select * from table(get_col_val.get('rno','hx_test'))
      2  /
    COLUMN_VALUE
               1
               2
               3
               4
               5
               6
               7
               8
               9
              10
    10 rows selected.Thanks,
    Karthick.

  • Non nullable columns

    If we need to insert blank into a non nullable char and varchar fields
    what should we do. And in case of int and decimal fields can we insert
    0 and 0.0
    Thanks

    If you need to insert blank then you should insert
    blank. It makes no difference whether the column
    accepts null values or not because blank is not null.That is not entirely true. With Oracle a String of the length zero will be treated as a null value.

  • Reg: View column datatype

    Hi Team,
    While creating the views, column automatically converted into varchar2(81) data type from number datatype.
    but stage1 table has legacy_trx_number is number data type and statg2 table has header_num is number data type.
    Just i added the highlighted part in the view. So automatiicaly converted number to varchar2 datatype. How to keep data type remain the same as source stage table datatype even though those columns used in the view.
    CREATE OR REPLACE VIEW test_view  AS
        SELECT h1.legacy_trx_number
          ||'.'
          ||h2.header_num legacy_trx_number,
          h1.legacy_trx_date,
          h1.ledger_id,
          h1.legal_entity_id,
          h1.header_record_identifier,
          h2.header_num,
          h2.gl_date,
          h2.header_value_full,
          h2.header_value
        FROM stage1 H1,
          stage2 H2
      WHERE h1.header_record_identifier = h2.header_record_identifier;
    Please help give me suggestion on this.
    Thanks in advance.

    You can do it like this!
    Example:-
    SQL> ed
    Wrote file afiedt.buf
      1  create view v_num_test
      2  as
      3* select to_number(5478||'.'||87489) result from dual
    SQL> /
    View created.
    SQL> select * from v_num_test;
        RESULT
    5478.87489
    SQL> desc v_num_test
    Name                                      Null?    Type
    RESULT                                             NUMBER

  • A MVC datatable with dropdown filtering per column search with pagination example?

    Hello All,
    Just starting out a big project with MVC 3 and I've been searching for a while for any step by step example of creatintg a dynamic/ajax datatable that has real time filtering of the result set via dropdowns for mvc?  Is there a ready made solution already
    available for the MVC framework?
    Thanks,

    Hello,
    Thank you for your post.
    Glad to see this issue has been resolved and thank you for sharing your solutions & experience here. It will be very beneficial for other community members who have similar questions.
    Your issue is out of support range of VS General Question forum which mainly discusses
    WPF & SL designer, Visual Studio Guidance Automation Toolkit, Developer Documentation and Help System
    and Visual Studio Editor.
    If you have issues about ASP.NET MVC app in the future, I suggest that you can consult your issue on ASP.NET forum:
    http://forums.asp.net/
     for better solution and support.
    Best regards,
    Amanda Zhu [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

  • Creating a foreign constraint on a nullable column.

    hi,
    for example I am having a table x with columns(id primary key, no number,name,address);
    another table y in operapps schema with columns ( id primary key,code not null,desg);
    i want to create foreign key constraint as
    ALTER TABLE x ADD ( FOREIGN KEY (no) REFERENCES OPERAPPS.y(ID));
    this is erroring out as no column in table x can be null,and the messge is
    ORA-02298: cannot validate (SAFEX_DEV.SYS_C0081362) - parent keys not found.
    Please advice.

    The error message is telling you that there are values in the proposed FK column that are not found in the parent table, not that there is a problem with nulls.

  • Column Searching

    Dear Team
    I required query to find the table name and schema name
    My Question is
    I have 5 schema and i know only the column name
    i want to find the table and schema name.
    Is there any query..?
    Thank Advance..

    You can query the data dictionary:
    SELECT t.owner, t.table_name, t.column_name, t.data_type
      FROM dba_tab_columns t
    WHERE t.column_name = 'MY_COLUMN';If you don't have access to the DBA_TAB_COLUMNS view you may want to try it using ALL_TAB_COLUMNS or USER_TAB_COLUMNS logged as each of your 5 schemas to check them individually, just to make sure you have the privileges on the desired table.

  • Reg: Rows_Processed column in v$SQLAREA

    Hi all,
    I had a request to check the rows processed while an insert statement is running in the database.
    Can anyone clarify me on this from v$sqlarea (rows_processed) is it possible to get the rows processed till that time.
    As i am in thinking that it depends on how application has commit transactions.
    Can any one throw some light on this request...
    Thanks in advance...
    Satya G

    Hi,
    Rows_processed column of v$sql gives the count of total rows that has been processed whether it is committed or not committed. It gives the sum of rows processed by the query even if some of the transaction has been rollbacked.
    I suppose you are looking for USED_UREC in v$transaction.
    Regards
    Anurag

  • OSB10.3.1 fn-bea:execute-sql - nullable columns and type conversion

    Hi all,
    we are using the fn-bea:execute-sql function to retrieve data from an Oracle db:
    <ctx:route><ctx:service>{   
    fn-bea:execute-sql (
    fn:concat(xs:string($body/urn:clientDataLookup/ds/text()),'.SADataSource'),
    'resultset',
    'SELECT id, name, type_id, domi_country_id, open_date, close_date FROM my_table WHERE id=?',
    xs:string($body/urn:clientDataLookup/id/text())
    </ctx:service></ctx:route>
    Where my_table is defined as below:
    CREATE TABLE my_table
    ID NUMBER,
    NAME VARCHAR2(100 BYTE),
    TYPE_ID NUMBER,
    DOMI_COUNTRY_ID NUMBER,
    OPEN_DATE DATE,
    CLOSE_DATE DATE,
    As you can see ID,TYPE_ID,DOMI_COUNTRY_ID are defined as NUMBER and some columns could be null.
    Below an example of the result from the above query using fn-bea:execute-sql function:
    <resultset>
    <ID>161052.0</ID>
    <NAME>...</NAME>
    <TYPE_ID>3.0</TYPE_ID>
    <DOMI_COUNTRY_ID>2090.0</DOMI_COUNTRY_ID>
    <OPEN_DATE>2010-12-17T00:00:00</OPEN_DATE>
    </resultset>
    In the above example the column CLOSE_DATE is null for the given ID and the CLOSE_DATE tag, as you can see, is not included in the result.
    In addition the values for the columns defined as NUMBER are returned with decimals.
    Is there any way to return also tags for columns that are NULL ? E.g. something like <CLOSE_DATE null="Y"/> ?
    And for the columns defined as NUMBER that are returned with decimals what could we do to force the type without decimals ?
    We are wondering if fn-bea:execute-sql function accepts any extra param in order 'to drive' result format/structure ... as expected ...
    Thanks in advance
    ferp

    It sounds like a bug. Can you please contact bea support?
    Gregory Haardt
    ALSB Prg. Manager
    [email protected]

  • Comma Separated columns - Search

    Hi fellow,
    I need to query my db with a comma separated list but the results are not correct...What is the reason?
    My typical db problem_code column has valuas as :
    Problem_code
    1
    2,3
    5,6,7,8
    5
    And the list values I am sending as ("1","3")...etc
    SELECT * from table
    whereproblem_code in ('2','1')problem_code in ('2','1') 
    Thank you in advance..

    If you're sking SQL questions, you'd better off asking on a SQL forum.  But here you are, so let's have a look at it.
    Firstly, the other thing to always mention when raising an SQL question is to articulate what DB system you're using.  Because all of them handle SQL differently, and have their own extensions.
    In fact reading this is probably a good idea: http://www.catb.org/~esr/faqs/smart-questions.html
    Problem_code
    1
    2,3
    5,6,7,8
    5
    And the list values I am sending as ("1","3")...etc
    SELECT * from table
    whereproblem_code in ('2','1')problem_code in ('2','1') 
    Thank you in advance..
    What are you seeing here that's not expected (I presume the double-up of problem_code in ('2','1') is a typo)?
    Are you wanting to get any rows from TABLE which have either 1 or 2 in them?  That's not what you're asking for in your WHERE statement though, is it?
    Really, you should be normalising your data, because whilst you can write contorted logic to do what you need here, it will not perform well and certainly will not scale.  So it for be somewhat poor practice to perpetuate the current situation if it's at all possible not to.   The best thing to do is to normalise your data and refactor your code.  Which will probably mean going to your boss and say "this DB schema is f*cked, and needs reworking.  Needs reworking".
    Depending on your DB system, you're probably going to need to loop over the list you want to filter on and do a "WHERE problem_code LIKE" on each element of the list.  I think Oracle can do the sort of query you want to do - match elements of one list from another list - but I'm not sure.
    Adam

  • Re: Reg: View column datatype

    Hi All,
    After changing it, I was getting the output like for legacy_trx_number.
    220135.1
    220135.2
    220135.3
    220135.4
    220135.5
    220135.6
    220135.7
    220135.8
    220135.9
    220135.1 -- It should be 220135.10 after converting into to_number(h1.legacy_trx_number||'.'||h2.header_num legacy_trx_number)
    220135.11
    220135.12
    220135.13
    220135.14
    220135.15
    220135.16
    If it is varchar2 data type then i was gettign the correct output from view query output. can you let me know how to avoid this problem.
    Thanks in advance.

    In addition to your previous thread, you have 3 choices: -
    1) If a table/view is created with number datatype with precession 2, then 220135.10 value will be stored as 220135.1 in it. In short number type ignores trailing zero after decimal.
    2)  You can stick to your view creation with varchar2 datatype.
    3) Or as Blu suggested, you can display using to_char with format code. Like for  TO_CHAR( 220135.1, 'FM999999.00' ). But along with this, your all decimal part( before 10) will also have a trailing zero with them.
    Thanks!

Maybe you are looking for

  • BADI WORKORDER_UPDATE - creation of PO

    Hi, I am trying to create a purchase order using the method IN_UPDATE in BADI WORKORDER_UPDATE. I am using the BAPI BAPI_PO_CREATE to create the purchase order. However transaction IW32 abends when the BAPI is called with either of the following mess

  • Second queston using powershell in SCOM as recovery

    Hi guys, In a previous question i needed some ideas about using powershell in a recovery. Now i've implemented this in the XML, but it gives me this error as i import my managementpack back in SCOM 2012 R2 UR 2 Error, it gives the error on Microsoft.

  • Creating psd animation

    I imported  "Image Sequence"  inPS then created the sequence and adjusted the layers and timeline. Two questions: 1) How do I revert all the frames (the are in the wrong order) 2) from the file in Photoshop format but I can't figure out how to save a

  • FRM-41075-ERROR DELETING GROUP

    HI EVERYBODY, i created a form with one item which z not database item.i created lov based on query.i created a key-listval trigger for item.when i m running my form,i am getting the following error:FRM-41075:Error deleting group.how to solve this er

  • HT201364 "The product distribution file could not be verified. It may be damaged or was not signed." WANTED TO UPDGRADE TO MAVERICK. PLEASE HELP. THANKS.

    Hi Guys, I wanted to upgrade to Maverick but encountered this diffcult "The product distribution file could not be verified. It may be damaged or was not signed" Need your help. Thanks CMKong