Logical operators in Oracle select query

Hello all,
Can i use logical operators in oracle select queries?
for 1 and 0 =0 ; 1 or 0 =0
if i have two fileds in a table COL1 have a value of 1010 and COL2 have a value of 0001.
Is there any way to use select col1 or col2 from table? where or is a logical operator?
Regards,

Hi,
NB wrote:
Hello all,
Can i use logical operators in oracle select queries?Sure; Oracle has the logical operators AND, NOT and OR. All the comparison operators, including >, >=, = !=, EXISTS, IN, IS NULL, LIKE and REGEXP_LIKE are really logical operators, since they return logical values. You can use them in SELECT statements, and other places, too.
for 1 and 0 =0 ; 1 or 0 =0
if i have two fileds in a table COL1 have a value of 1010 and COL2 have a value of 0001.It's unclear what you want. Maybe you'd be interested in the BITAND function:
http://download.oracle.com/docs/cd/B28359_01/server.111/b28286/functions014.htm#sthref1080
BITAND is the only logical function that I know of. Many other functions, especially numberical fucntions such as MOD, have applications in logic.
Is there any way to use select col1 or col2 from table? where or is a logical operator?Whenever you have a question, please post a little sample data (CREATE TABLE and INSERT statements), and also post the results you want from that data.
Explain how you get those results from that data.
Always say which version of Oracle you're using.

Similar Messages

  • Check Index used in an oracle select query

    Hi Friends,
    I have partitioned an oracle table and created Local Index for the Partitioned table .
    Now i want to make sure that the Local index is being used when i perform select query on the Table partition.
    How do i confirm that ?
    can i check the explain plan generted for the select query to confirm local index is being used ?
    Please let me know.
    Regards,
    DB

    Now i want to make sure that the Local index is being used when i perform select query on the Table partition.Why? Have you proven that using this local index is the "best" plan?
    How do i confirm that ?
    can i check the explain plan generted for the select query to confirm local index is being used ?When I asked Google "how to read an oracle explain plan," I found lots of information - what did you find?

  • Give me some logic for the mentioned select query

    hi.
    i am writing a select query hereby but seems that it is not logically viable.please give me the best possible,logically correct piece of code.....thnks in adv.
    i am using tables to give the output depending on the date.
    ranges r_audat for vakpa-audat.
    r_audat-sign  = 'I'.
    r_audat-option = 'BT'.
    r_audat-low = '20060101'.
    r_audat-high = '20071231'.
    append r_audat.
    clear r_audat.
    select vbeln kunde vkorg audat
           from vakpa
           into table it_vakpa
           for all entries in it_knb1
           where kunnr = it_knb1-kunnr
           and vkorg = it_tvko-vkorg
           and audat in r_audat.
    sort it_vakpa by vkorg.
    delete adjacent duplicates from it_vakpa.
    sort it_knb1 by kunnr.
    loop at it_knb1.
      Read table it_vakpa with key vkorg = it_tvko-vkorg.
      if sy-subrc ne 0.
    delete it_knb1 where bukrs = it_knb1-bukrs.
      delete it_knb1.
      endif.
    endloop.

    Hi,
    while looping don't delete the entries from the internal table on which you are looping.
    take one more vairable(flag(1) type c) in internal table structure it_knb1.
    after read statement
    if sy-subrc <> 0.
       it_knb1-flag = 'X'.
       modify it_knb1 transporting flag.
    endif.
    after endloop, write the delete statement on it_knb1.
    delete table it_knb1 where flag = 'X'.
    this is the best approach.
    Reward if useful.
    Thanks,
    Sreeram.

  • Spatial query w/ logical operators in a subquery on Linux using Oracle 1

    Hello...
    I'm being given XML that I need to parse and create SQL from it. Below my signature is the SQL that I generate (its a simple example) and can be more elaborate due to the logical operators (AND and OR) given in the XML.
    The problem that we're seeing is performance-based: when one of the logical operator queries is Spatial-based, like below. Running it in JDBC, the query never returns.
    The spatial query just by itself returns ~300 rows (takes approximately 0.2 seconds). The "PERCENTAGE" query by itself returns about ~40000 rows (takes approximately ~.8 seconds).
    If we run the query below with 2 non-spatial subqueries, the result returns and performance is very acceptable (~ 0.9 seconds)-- the result set is about 80000 rows.
    Thanks,
    Jim
    =========================
    SELECT
    COLUMN_WE_WANT , RESULTS
    FROM
    TABLE_A
    WHERE
    COLUMN_WE_WANT IN
    SELECT
    COLUMN_WE_WANT
    FROM
    TABLE_A
    WHERE
    SDO_OVERLAPBDYINTERSECT(TABLE_A.MY_SPATIAL_COLUMN,
    SDO_GEOMETRY(2003,
    4326,
    null,
    SDO_elem_info_array( 1 , 3 , 1 ),
    SDO_ORDINATE_ARRAY( lng_1,lat_1 , lng_2,lat_2 , lng_3,lat_3 , lng_4,lat_4 , lng_1,lat_1 )
    ) = 'TRUE'
    OR
    COLUMN_WE_WANT IN
    SELECT
    COLUMN_WE_WANT
    FROM
    TABLE_B
    WHERE
    SOME_PERCENTAGE_RATE_COLUMN < 90
    )

    Its difficult to comment without seeing the execution plan. You should trace this query to get a better idea of exactly what's happening.
    Depending on the complexity of the logical operators, I would look at doing this using set operations. So for an OR you might have...
    SELECT COLUMN_WE_WANT, RESULTS
    FROM TABLE_A
    WHERE COLUMN_WE_WANT IN (
         SELECT COLUMN_WE_WANT
         FROM TABLE_A
         WHERE SDO_OVERLAPBDYINTERSECT(TABLE_A.MY_SPATIAL_COLUMN,SDO_GEOMETRY(2003,4326,
         NULL, SDO_elem_info_array( 1 , 3 , 1 ),
         SDO_ORDINATE_ARRAY( lng_1,lat_1 , lng_2,lat_2 , lng_3,lat_3 , lng_4,lat_4 , lng_1,lat_1 ) )) = 'TRUE'
    UNION
         SELECT COLUMN_WE_WANT
         FROM TABLE_B
         WHERE SOME_PERCENTAGE_RATE_COLUMN < 90)For an AND, you would use INTERSECT.
    Edited by: Reggie to remove the extra INTERSECT

  • Spatial query w/ logical operators in a subquery on Linux using Oracle 10g

    Hello...
    I'm being given XML that I need to parse and create SQL from it. Below my signature is the SQL that I generate (its a simple example) and can be more elaborate due to the logical operators (AND and OR) given in the XML.
    The problem that we're seeing is performance-based: when one of the logical operator queries is Spatial-based, like below. Running it in JDBC, the query never returns.
    The spatial query just by itself returns ~300 rows (takes approximately 0.2 seconds). The "PERCENTAGE" query by itself returns about ~40000 rows (takes approximately ~.8 seconds).
    If we run the query below with 2 non-spatial subqueries, the result returns and performance is very acceptable (~ 0.9 seconds)-- the result set is about 80000 rows.
    Thanks,
    Jim
    =========================
    SELECT
    COLUMN_WE_WANT , RESULTS
    FROM
    TABLE_A
    WHERE
    COLUMN_WE_WANT IN
    SELECT
    COLUMN_WE_WANT
    FROM
    TABLE_A
    WHERE
    SDO_OVERLAPBDYINTERSECT(TABLE_A.MY_SPATIAL_COLUMN,
    SDO_GEOMETRY(2003,
    4326,
    null,
    SDO_elem_info_array( 1 , 3 , 1 ),
    SDO_ORDINATE_ARRAY( lng_1,lat_1 , lng_2,lat_2 , lng_3,lat_3 , lng_4,lat_4 , lng_1,lat_1 ) )
    ) = 'TRUE'
    OR
    COLUMN_WE_WANT IN
    SELECT
    COLUMN_WE_WANT
    FROM
    TABLE_B
    WHERE
    SOME_PERCENTAGE_RATE_COLUMN < 90
    )

    There is a spatial forum. You will likely have a far better experience there.

  • Query form requires Logical operators and/or Quotes

    In ORACLE 9I Jdeveloper beta I used the BC4J JSP wizard to create a - Query Form. The query form looks nice and runs except I have to also include the logical operators (= > <) and Quotes. For example to query on the name Joe I have to enter it as ="JOE". If I use JOE it gives me a JSP error. The error message shows the generated Select statment with the where clause JOE but is missing the "=" and quotes.
    How do I hard code the "=" and quotes around strings so that the user doesn't have to?

    In ORACLE 9I Jdeveloper beta I used the BC4J JSP wizard to create a - Query Form. The query form looks nice and runs except I have to also include the logical operators (= > <) and Quotes. For example to query on the name Joe I have to enter it as ="JOE". If I use JOE it gives me a JSP error. The error message shows the generated Select statment with the where clause JOE but is missing the "=" and quotes.
    How do I hard code the "=" and quotes around strings so that the user doesn't have to?

  • Oracle 11g :SELECT query blocked..??

    Hi Experts,
    could you please explain why the below SQL query is blocked?
    SELECT 1 FROM DUAL is blocking the SQL statement on GTTAPPUSR@gttccuatcriba04 ( SID=469 ) blocked SQL -> DELETE FROM GTTDB.PURCHASE_ENTRY_ID=:1
    SELECT 1 FROM DUAL is blocking the SQL statement on GTTAPPUSR@gttccuatcriba04 ( SID=367 ) blocked SQL -> DELETE FROM GTTDB.PURCHASE_ENTRY_ID=:1
    I am scratching my head without any solution when I had a look at the db today. Thanks in advance for your help.
    Regards,
    Boris
    Edited by: user12075620 on Dec 4, 2012 8:58 AM

    The SELECT statement is not blocking the UPDATE. As I said in the previous reply, the string that this query produces does not match the logic.
    This query is (at least on the surface) correctly identifying that session 1 is blocking session 2. Session 1 holds some lock that session 2 is waiting on. So far, so good. Since session 2 is waiting on the lock, we can easily enough see what session 2 is running (the UPDATE statement). But since session 1 is not blocked, it is potentially off running a ton of other SQL statements (or no SQL statement at all). The query is looking to see what session 1 is running currently. It has no way of determining what session 1 ran at some point in the past to acquire the lock in the first place.
    Going back to my KING example,
    At noon, session 1 runs
    UPDATE emp
       SET sal = sal * 2
    WHERE ename = 'KING'Session 1 now has a lock on the KING row in the EMP table. But session 1 neither commits nor rolls back, it is still in a transaction. Session 1 might not have any more activity for a long time-- the user might go off to lunch, for example (obviously, applications should not be designed to allow users to maintain open transactions indefinitely, but not all applications are designed correctly). Or it might start running other queries. Let's say that session 1 now runs a query that is going to go for an hour
    SELECT *
      FROM giant_view_with_lots_of_computationsNow, at 12:45, session 2 comes in and runs
    UPDATE emp
       SET bonus = 100
    WHERE ename = 'KING'Session 2 is blocked. Session 2 is running the UPDATE statement. Session 1 still holds the lock but it is running some completely unrelated SQL statement.
    If we run the query you posted, the query will correctly report that session 1 is running the query against the GIANT_VIEW_WITH_LOTS_OF_COMPUTATIONS but incorrectly imply that this SELECT query is the source of the lock. It is not. It simply happens to be the query that the session that does hold the lock happens to be executing at the current moment (why the application seems to be running a lot of queries that select a constant from dual is a separate question).
    Justin

  • Select query differences between oracle 9 and oracle 8.

    Hi,
    I have a problem using the select query between oracle 7 and oracle 9i I don't have the same result :
    ex:
    With oracle7
    SQL> select 'champ1','champ2' from DUAL;
    'CHAMP 'CHAMP
    champ1 champ2
    With Oracle 9
    SQL> select 'champ1','champ2' from DUAL;
    'CHAMP1' 'CHAMP2'
    champ1 champ2
    So Can someone tell me how to solve this problem ? Is there a parameter in oracle 9 to set?
    Thanx.

    Whenever you are posting anything over internet forums like this - you should be very careful about not just posting the details which requires to solve the problem - also should be sensible about your question.
    This is not at all desired when you are posting such question. It may be because - you may not well aware of the fact.
    My suggestion is -> First Go through the basics Of SQL in general.
    Then go for any specific product like Oracle/ SQL Server/ Sybase etc.
    And, finally learn the advanced commands of that DB.
    You asked it - may be you thought the difference in output in terms of lines. But, that is not your actual output. That is the graphical display part only.
    Anyway,
    You can get the quite familier output by first type the following command ->
    set lin 310Regards.
    Satyaki De.

  • Select query is working on oracle 10.1.0 but its not working in 10.2.0

    select query is working and retrieving some data from oracle database server 10.1.0.2.0, but same query is not working in 10.2.0.1.0 database server, its throws(ORA-00942: table or view does not exist)
    But schema related tables and relevant details are same in 10.2.0.1.0 database server, so don't think that table is missing on that schema.
    Note: Query length is upto 480 line
    I have validate all the things, everything is fine, i don't why that query is not executing in different version.
    I am in helpless in this situation?, anybody faced this issue?
    Thanks in advance

    Validated means all the tables and and columns are verified, i just running in sqlprompt,
    Say for example:
    sql> select * from table1;
    One thing i observed while executing the query its showed error in one location of select sql. i mean particular word in select sql.
    After that i combined some three lines of huge select sql into single then i am getting error in different location i mean different word...
    My question is how same query executing in Oracle 10g Release 1, same dump (its exported from Release1) imported into oracle 10g release 2 is not executing. its shows Table or view doesn't exit.

  • In oracle rac, If user query a select query and in processing data is fetched but in the duration of fetching the particular node is evicted then how failover to another node internally?

    In oracle rac, If user query a select query and in processing data is fetched but in the duration of fetching the particular node is evicted then how failover to another node internally?

    The query is re-issued as a flashback query and the client process can continue to fetch from the cursor. This is described in the Net Services Administrators Guide, the section on Transparent Application Failover.

  • How to get result of select query from  oracle  in VC

    Dear All ,
    I have a application in oracle which insert the data in the oracle database table.
    Now i want to show all the data that has been inserted into the database table in my VC application but i don't know how to handle select query in VC.
    Regards
    Krishan

    Hi Goivndu
    Thanks for your reply .
    I know all those things.
    I have created the system & alias  for my backend oracle system.
    I can also see all the stored procedure that are there in my oracle system.
    I just want to know how to write a select query in a stored procedure .
    you can insert data , Update data through oracle procedure but i don't think there is any way to get the result of select query in stored procedure .
    If you know any way to do that please do let me know .
    Regards
    Krishan

  • NullPointerException on System.arraycopy command while executing select query in Oracle 10

    I'm getting this error below while trying to execute some select query.
        java.lang.NullPointerException at java.lang.System.arrayCopy(Native Method) at
        oracle jdbc.driver.T4CNumberAccessor.saveDataFromOldDefineBuffers(T4CNumberAccessor.java:276) at
        oracle.jdbc.driver.T4CPreparedStatement.saveDefineBuffersIfRequired(T4cPreparedStatement.java:486) at
        oracle.jdbc.driver.OracleStatement.prepareAccessors(OracleStatement.java:919) at
        oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(T4CPreparedStatement:836) at
        oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1124) at
        oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3286) at
        oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:3329) at
    I've already downloaded the latest ojdbc5.jar file to access Oracle 10 database.
    This is my java version:
        bash$java -version
        HEAP_DUMP_OPTIONS= -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=../Logs -XX:+PrintClassHistogram
        java version "1.5.0_22"
        Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_22-b03)
        Java HotSpot(TM) Server VM (build 1.5.0_22-b03, mixed mode)
    Any idea of what may cause this problem?

    No one can debug code that they can't see.
    You need to SHOW US (not just tell us):
    1. WHAT you are doing
    2. HOW you are doing it
    3. WHAT result you are getting
    4. WHAT result you expected to get.
    The latest JDBC jar that can access Oracle 10 DBs is the 12.1.0.2 driver and is available here:
    JDBC/UCP Download Page

  • Oracle "IO Error" during SELECT query under heavy load

    We're experiencing a strange connection break during SELECT queries under heavy load.
    Platform Details: Solaris, Oracle 11G, JDK 1.6, 
    Application: Spring + Hibernate (C3p0 connection pooling)
    Exact error messages from a lengthy stack trace are mentioned below:
        2013/06/05 18:49:02 | Caused by: org.springframework.dao.DataAccessResourceFailureException: Hibernate operation: could not execute query; SQL [SQL Ommitted]; IO Error: No such file or directory;      nested exception is java.sql.SQLException: IO Error: No such file or directory 
        2013/06/05 18:49:02 | Caused by: java.sql.SQLException: IO Error: No such file or directory
        2013/06/05 18:49:02 |    at oracle.jdbc.driver.T4CPreparedStatement.fetch(T4CPreparedStatement.java:1091)
        2013/06/05 18:49:02 |    at oracle.jdbc.driver.OracleResultSetImpl.close_or_fetch_from_next(OracleResultSetImpl.java:369)
        2013/06/05 18:49:02 |    at oracle.jdbc.driver.OracleResultSetImpl.next(OracleResultSetImpl.java:273)
        2013/06/05 18:49:02 |    at com.mchange.v2.c3p0.impl.NewProxyResultSet.next(NewProxyResultSet.java:2706)
        2013/06/05 18:49:02 |    at org.hibernate.loader.Loader.doQuery(Loader.java:697)
        2013/06/05 18:49:02 | Caused by: java.net.SocketException: No such file or directory
        2013/06/05 18:49:02 |    at java.net.SocketInputStream.socketRead0(Native Method)
        2013/06/05 18:49:02 |    at java.net.SocketInputStream.read(SocketInputStream.java:129)
        2013/06/05 18:49:02 |    at oracle.net.ns.Packet.receive(Packet.java:282)
    We've started looking at TCP connection settings (Max. TCP connections allowed, Max File descriptors allowed for socket connections at system level). Anything we're missing?
    Why "IO Error: No such file or directory"? Any clue?

    user2951561 wrote:
    That's a better answer indeed.
    I can refine my question if it does not provide you enough information.
    The stack trace i displayed here states that oracle jdbc driver has found the connection to be closed, interrupted etc.
    Application behaves perfectly under normal load but blows up as soon as we reach 3000 concurrent sessions. No firewall is breaking connections, the select query that we observe this behavior for is part of a larger workflow that write data, update some, delete some as well in different tables. Then we see above stack trace for the select query.
    I am trying to explore possible options to investigate. One i mentioned is related to Solaris file descriptors. Could it be database it self?
    Any possible course of action for investigation? Help is much appreciated.
    Oracle errors get reported with error code & message; like ORA-01555 Snapshot Too Old; which is not present in your post.
    You indicated that Connection Pooling is used.
    Is there some (artificial) limit within the application that falls off the cliff at 3000 sessions?
    Oracle does not know or care about the "flavor" of client connection. It treats jdbc the same as OCI or ODBC connections.
    Is OS limited to fixed number of open file handles?

  • Oracle SQL Select query takes long time than expected.

    Hi,
    I am facing a problem in SQL select query statement. There is a long time taken in select query from the Database.
    The query is as follows.
    select /*+rule */ f1.id,f1.fdn,p1.attr_name,p1.attr_value from fdnmappingtable f1,parametertable p1 where p1.id = f1.id and ((f1.object_type ='ne_sub_type.780' )) and ( (f1.id in(select id from fdnmappingtable where fdn like '0=#1#/14=#S0058-3#/17=#S0058-3#/18=#1#/780=#5#%')))order by f1.id asc
    This query is taking more than 4 seconds to get the results in a system where the DB is running for more than 1 month.
    The same query is taking very few milliseconds (50-100ms) in a system where the DB is freshly installed and the data in the tables are same in both the systems.
    Kindly advice what is going wrong??
    Regards,
    Purushotham

    SQL> @/alcatel/omc1/data/query.sql
    2 ;
    9 rows selected.
    Execution Plan
    Plan hash value: 3745571015
    | Id | Operation | Name |
    | 0 | SELECT STATEMENT | |
    | 1 | SORT ORDER BY | |
    | 2 | NESTED LOOPS | |
    | 3 | NESTED LOOPS | |
    | 4 | TABLE ACCESS FULL | PARAMETERTABLE |
    |* 5 | TABLE ACCESS BY INDEX ROWID| FDNMAPPINGTABLE |
    |* 6 | INDEX UNIQUE SCAN | PRIMARY_KY_FDNMAPPINGTABLE |
    |* 7 | TABLE ACCESS BY INDEX ROWID | FDNMAPPINGTABLE |
    |* 8 | INDEX UNIQUE SCAN | PRIMARY_KY_FDNMAPPINGTABLE |
    Predicate Information (identified by operation id):
    5 - filter("F1"."OBJECT_TYPE"='ne_sub_type.780')
    6 - access("P1"."ID"="F1"."ID")
    7 - filter("FDN" LIKE '0=#1#/14=#S0058-3#/17=#S0058-3#/18=#1#/780=#5#
    8 - access("F1"."ID"="ID")
    Note
    - rule based optimizer used (consider using cbo)
    Statistics
    0 recursive calls
    0 db block gets
    0 consistent gets
    0 physical reads
    0 redo size
    0 bytes sent via SQL*Net to client
    0 bytes received via SQL*Net from client
    0 SQL*Net roundtrips to/from client
    0 sorts (memory)
    0 sorts (disk)
    9 rows processed
    SQL>

  • Dynamic %HINT ORACLE in select query

    Hi Experts,
    I am trying to implement given below code with dynamic % hint oracle
          SELECT vbeln posnr uepos
             FROM vbap INTO TABLE i_vbap
             FOR ALL ENTRIES IN i_vbak
              WHERE vbeln EQ i_vbak-vbeln
                %_hints oracle '&max_in_blocking_factor 500&&max_blocking_factor 500&'.
    I want value 500 dynamic,
    So far I have tried
    %hint oracle lv_oracle_string.
    %hint oracle (lv_oracle_string).
    WHERE (lv_oracle_string).     "where conditon with %_hints oracle '&max_in_blocking_factor 500&&max_blocking_factor 500&'.
    Any other ideas?
    Thanks in Advance

    Samuel,
    Thank you so much, whatever you mentioned, I have tried ealier, but it was giving me dump because of incorrect spacing in my string.
    Given below sloved my problem.
    CONCATENATE '''&max_in_blocking_factor ' lv_oracle '&&max_blocking_factor ' lv_oracle '&'''
              INTO lv_oracle_string RESPECTING BLANKS.
              SELECT vbeln posnr uepos
                 FROM vbap INTO TABLE i_vbap
                 FOR ALL ENTRIES IN i_vbak
                 WHERE vbeln EQ i_vbak-vbeln
                 %_hints oracle lv_oracle_string.
    Thanks you so much again. You Rock

Maybe you are looking for

  • Hp laserjet pro 500 color mfp m270dw

    i have one new hp laserjet pro 500 color mfp m270dw in my office. can any anyone show me how to setup password or enter password i really like my printer have a password. thanks student

  • Is there a way to find out if your java application is already running?

    Hi, Im trying to find a way to find out if my java app is already running in windows. Basically i've registered a file extension with my application and when i person opens that file it launches my app. Now the question is how do i know whether the c

  • How can I tell when an ical event was added?

    I'm on a shared ical calendar and there are times when 2 events have been put on at the same time.  How can I tell when the event was added and by who? Thanks!

  • Can you put KM attributes in a office document?

    Hello, I have a question : "Can you put KM attributes such as a document version number automatically in a Office document"? For iso documents it's needed to have a version counter in the word document itself. If the km version number could be copied

  • Error in rcv_transactions_interface table but no record in po_interface_err

    Hi Everyone, I'm having a issue in receipts interface. I'm inserting data into rcv_headers_interface table and rcv_transactions_interface tables and then doing fnd_request.submit_request of Receiving transaction processor program. The import program