MINUS IN SQL PLUS

Hi I have this query and it returns 4 records one of those is a duplicate
SQL> col adjustment_reason format a30
SQL> SELECT account_no ,descr as adjustment_reason,
2 gl_id,amount as adjustmentamount
3 FROM src_misc_adj_rpt;
ACCOUNT_NO ADJUSTMENT_REASON GL_ID ADJUSTMENTAMOUNT
1-36795186 Acct Transfer Adjust-System 135 -37.61
1-36795186 Acct Transfer Adjust-System 135 59.24
1-36795186 Acct Transfer Adjust-System 135 -36.78
1-36795186 Acct Transfer Adjust-System 135 -36.78
and another query
SQL> SELECT account_no ,descr as adjustment_reason,
2 gl_id,amount as adjustmentamount
3 FROM tgt_misc_adj_rpt;
no rows selected
I get no results
I am doing a minus on these
SQL> SELECT account_no ,descr as adjustment_reason,
2 gl_id,amount as adjustmentamount
3 FROM src_misc_adj_rpt
4 MINUS
5 SELECT account_no ,descr as adjustment_reason,
6 gl_id, amount as adjustmentamount
7 FROM tgt_misc_adj_rpt;
ACCOUNT_NO ADJUSTMENT_REASON GL_ID ADJUSTMENTAMOUNT
1-36795186 Acct Transfer Adjust-System 135 -37.61
1-36795186 Acct Transfer Adjust-System 135 -36.78
1-36795186 Acct Transfer Adjust-System 135 59.24
I get only 3 records . I want to get all the 4 records even the duplicate record. Is there any other way to do that

Shahid Ali Tcs wrote:
Still question is why minus is removing duplicate rows?MINUS, INTERSECT, UNION etc. are "set operations".
In mathematics, generally speaking, sets contain a set of values, not the number of occurences of them.
Hence, when you use set operations on your data, it looks at the values in the set, and not the number of occurences, so what is returned is the resultant values of the operation. i.e. it turns from being a table of rows to a set of values.
e.g. if you get the union of data in the sets...
SQL> ed
Wrote file afiedt.buf
  1  with t as (select 1 as num from dual union all
  2             select 2 from dual union all
  3             select 3 from dual union all
  4             select 3 from dual union all
  5             select 4 from dual)
  6      ,t2 as (select 2 as num from dual union all
  7              select 2 from dual)
  8  --
  9  select * from t
10  union
11* select * from t2
SQL> /
       NUM
         1
         2
         3
         4... you just get 1 occurence of each value
Likewise if you request the intersection of the sets...
SQL> ed
Wrote file afiedt.buf
  1  with t as (select 1 as num from dual union all
  2             select 2 from dual union all
  3             select 3 from dual union all
  4             select 3 from dual union all
  5             select 4 from dual)
  6      ,t2 as (select 2 as num from dual union all
  7              select 2 from dual)
  8  --
  9  select * from t
10  intersect
11* select * from t2
SQL> /
       NUM
         2... you just get the value that intersects, not all occurences of it
And, of course as you've found out...
SQL> ed
Wrote file afiedt.buf
  1  with t as (select 1 as num from dual union all
  2             select 2 from dual union all
  3             select 3 from dual union all
  4             select 3 from dual union all
  5             select 4 from dual)
  6      ,t2 as (select 2 as num from dual union all
  7              select 2 from dual)
  8  --
  9  select * from t
10  minus
11* select * from t2
SQL> /
       NUM
         1
         3
         4... minus only deals with the values, not the occurences
The one exception to the rule is oracles implementation of UNION ALL...
SQL> ed
Wrote file afiedt.buf
  1  with t as (select 1 as num from dual union all
  2             select 2 from dual union all
  3             select 3 from dual union all
  4             select 3 from dual union all
  5             select 4 from dual)
  6      ,t2 as (select 2 as num from dual union all
  7              select 2 from dual)
  8  --
  9  select * from t
10  union all
11* select * from t2
SQL> /
       NUM
         1
         2
         3
         3
         4
         2
         2
7 rows selected.... where the ALL keyword specifically indicates that we want to deal with the occurences when unioning the sets together.
It's all in the documentation...
http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/queries004.htm#i2054381

Similar Messages

  • IF statement in SQL*Plus - how to do it

    Hi,
    In SQL*Plus script, I would like to keep conditional checking (IF statement) and proceed. For example, whatever is done in PL/SQL block below, want to do the same in SQL*Plus script, I know partly it can be done using VARIABLE keyword, conditional checking can be done using DECODE in SELECT statement, but I want to carry out a more complex requirement, hence I want to use IF statement somehow in SQL*Plus.
    Another question, how to do spooling in PL/SQL script, it can be done using UTL_FILE, any other option is there to achieve this.
    declare
    v_ind_count int;
    begin
    select count(1) into v_ind_count from user_indexes where index_name = 'index_object_name';
    IF v_ind_count > 0
    THEN
    dbms_output.put_line('index found');
    ELSE
    dbms_output.put_line('index does not exist');
    END IF;
    end;
    /

    Hello,
    SQL*PLUS has no scripting language. It can only execute SQL and PL/SQL scripts. There are some commands like SPOOL or SET but no commands for conditional statements. You should describe your requirements, maybe we can find a way.
    Or you can search the forum, maybe your question has already been answered
    [Google for SQL*PLUS + condition|https://www.google.de/search?q=site%3Aforums.oracle.com+"SQL*PLUS"+condition]
    # {message:id=4189517}
    # {message:id=4105290}
    how to do spooling in PL/SQL scriptFrom within PL/SQL you can use dbms_output, the spool has to be started by the calling SQL script when it is executed in SQL*PLUS. Or you can use utl_file, but then you can only write to a server directory, not into a client file. To give an advice we need more information about what you want to do.
    Regards
    Marcus

  • Apex 4.0 - Can see view data in SQL*Plus but no data in Object Browser

    Hi There,
    I have just started using Apex 4.o and migrated some apps. I have an issue with a report, but see the same issue with Object browser, which is easier to describe.
    I have a view:
    create or replace view V_PLJ_USERDEF_CODES (
             CODE_SET_ID,
             CODE_SET_CODE,
             CODE_SET_DESC,
             CODE_ID,
             CODE_SYS_CODE,
             CODE_VALUE,
             CODE_DESC,
             DISPLAY_SEQ,
             DISPLAY_FLAG,
             LANGUAGE_CODE) as
      select CS.CODE_SET_ID,
             CS.CODE_SET_CODE,
             CS.CODE_SET_DESC,
             C.CODE_ID,
             C.CODE_SYS_CODE,
             C.CODE_VALUE,
             C.CODE_DESC,
             C.DISPLAY_SEQ,
             C.DISPLAY_FLAG,
             C.LANGUAGE_CODE
        from PLJ_CODES C,
             PLJ_CODE_SETS CS
       where C.CODE_SET_ID         = CS.CODE_SET_ID
         and CS.CODE_SET_TYPE_CODE = SYS_CONTEXT('PLJUMPSTART','C_USERDEF_CODE_SET');This returns data in SQL*Plus, but no data in Object Browser OR report region based on this view.
    Workspace parses in the same schema as tested in SQL*Plus.
    If, in report, I swap out view, and use underlying table - no problem.
    Any ideas -
    thanks
    P

    Hi all,
    Thanks for getting back so promptly.
    It just seems weird to me, as tables are just fine, but not views.
    In the underlying schema:
    SQL> sho user
    USER is "ICSREPORTING"
    SQL> select count(*) from plj_codes;
      COUNT(*)
           107
    SQL> select count(*) from v_plj_userdef_codes;
      COUNT(*)
            29And in the APEX schema
    SQL> sho user
    USER is "APEX_040000"
    SQL> select count(*) from icsreporting.plj_codes;
    select count(*) from icsreporting.plj_codes
    ERROR at line 1:
    ORA-00942: table or view does not exist
    SQL> select count(*) from icsreporting.v_plj_userdef_codes;
    select count(*) from icsreporting.v_plj_userdef_codes
    ERROR at line 1:
    ORA-00942: table or view does not exist
    SQL>However, in SQL browser, I can see the data in PLJ_CODES but in V_PLJ_USERDEF_CODES, just the message "This view has no data". Indeed, it is like this for all views.
    I even explicitly granted access to APEX_040000 but no good.
    In fact, I would like to know more about how Apex gets access to do DML against the underlying parsing schema(s).
    This is a little frustrating though. It worked just fine in lots of apps in version 2.1 to 3.2
    Am I missing something
    paul
    p.s I knew there would be a question about the context, but I had already checked that. :)
    Edited by: PJ on Nov 19, 2010 4:09 AM

  • Can not query PQH_BUDGET_DETAILS in SQL*Plus

    Hi!
    I can see the Positions in the Forms-Mask within EBS.
    I want to write a concurrent Programm which queries some data form the positions-table.
    If i klick on "Help > Diagnostics > Examine" and select "system.last_query" i can see, that the data comes from a view called: "PQH_POS_BUDGETS_V".
    But if i try to query this view in SQL*Plus, it is empty.
    So i had a look at how this view is build, and i found, that the base tables should be PQH_BUDGETS and PQH_BUDGET_DETAILS.
    How can i query the position_id in PQH_BUDGET_DETAILS in a concurrent program or an self-writen BI Publisher Report?
    If i try to query in SQL*Plus it's empty.
    Who can help me with this issue?
    Thank you for your help!
    Best regards,
    Thomas

    Hi!
    Thats great!
    Thank you very much!
    Best regards,
    Thomas

  • SQL*Plus - how to suppress the SQL in a spool file

    This is my SQL*Plus script. I thought I had solved the problem, but it is back now and I don't know what I am missing. But I don't want the query at the top of the file.
    SET SERVEROUTPUT ON
    SET MARKUP HTML ON -SILENT
    SET ECHO OFF
    SET PAGESIZE 33
    SET TERMOUT OFF
    Spool C:\DuaneWilson.xls
    SELECT *
    FROM RPT_DS1_CNT_CAT_vw
    WHERE ROWNUM <=100
    ORDER BY CVBI_KEY;
    SET MARKUP HTML OFF
    SET ECHO ON
    SET PAGESIZE 20
    SET TERMOUT ON
    SET SERVEROUTPUT OFF

    It turns out when I run the script with the @ or Start with the file name, there is no SQL put out to the file. But when I just copy the text out of the file and run it at the prompt, the SQL appears in the output file. In reference to the -SILENT, I put that in after the MARKUP statement and got an error. Maybe I don't know where that goes. And I am not sure why there is a difference if it is run as a script or just pasted to the buffer. At least it should be the same in the output file, I would think.

  • Checking Module to Prevent SQL Plus usage on Database

    I have a question regarding logon triggers checking against SYS_CONTEXT('USERENV', 'MODULE'). I created a logon trigger that looks for SYS_CONTEXT('USERENV', 'MODULE') = 'SQLPLUS.EXE'
    and if it matches then it only allows specified users to log in to the database. This code works but I am confused as to why when I check SYS_CONTEXT('USERENV', 'MODULE') after I login in
    shows SQL*Plus which clearly does not match my IF statement in my logon trigger.
    Second issue. If I rename sqlplus.exe to jeff.exe and run it I am abled to log in to the database as a non DBA user. But the module still shows as SQL*Plus. Why is this?
    Database Version: 11.2.0.2 64bit
    OS: Windows Server 2003 R2
    Client: 11.2.0.1
    /*********************Create Trigger******************************/
    CREATE OR REPLACE TRIGGER application_check_al
      after logon ON database 
    DECLARE
      l_username VARCHAR2(20);
      l_module   VARCHAR2(20);
    BEGIN
      l_username := SYS_CONTEXT('USERENV', 'SESSION_USER');
      l_module   := UPPER(SYS_CONTEXT('USERENV', 'MODULE'));
      IF l_module LIKE 'SQLPLUS.EXE' AND
         l_username NOT IN ('SYS', 'SYSTEM', 'DVOWNER', 'DVMGR') THEN
        raise_application_error(-20001, 'SQLPLUS ACCESS RESTRICTED FOR NON DBA USERS');
      END IF;
    END application_check_al;
    /*********************Run SQLPLUS******************************/
    SQL*Plus: Release 11.2.0.1.0 Production on Wed Mar 7 12:22:23 2012
    Copyright (c) 1982, 2010, Oracle.  All rights reserved.
    Enter user-name: jeffc@dev
    Enter password:
    ERROR:
    ORA-00604: error occurred at recursive SQL level 1
    ORA-20001: SQLPLUS ACCESS RESTRICTED FOR NON DBA USERS
    ORA-06512: at line 10
    Enter user-name: system@dev
    Enter password:
    Connected to:
    Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
    With the Partitioning, OLAP, Data Mining, Oracle Database Vault
    and Real Application Testing options
    system@dev> select sys_context('USERENV','MODULE') from dual;
    SYS_CONTEXT('USERENV','MODULE')
    SQL*Plus
    SQL>

    jeff81 wrote:
    That doesn't make sense. Why am I able to log in when I renamed the exe? And why does the module still show as SQL*Plus?You are right - it does not make sense. The idea that Oracle might perhaps set module to SQLPLUS.EXE on executable start, and then re set from SQLPLUS.EXE to SQL*Plus after connect, or in glogin.sql, to ensure it is consistent across all operating system never crossed my mind.
    You might want to refer to Support Note "SQL*Plus Session/Module is Not Showing in V$SESSION" [ID 1312340.1] to see whether anything in there helps. I'm pretty sure http://docs.oracle.com/cd/E11882_01/server.112/e16604/ch_twelve040.htm#i2698573 doesn't help much, though.
    I'd certainly be raising it with Support as a potential security challenge, to get that potential hole closed.
    Edited by: Hans Forbrich on Mar 7, 2012 2:23 PM
    I wonder whether Oracle put that capability in there - if an untained SQLPLUS.EXE, it tells you that it is SQLPLUS.EXE, but if renamed it tells you 'SQL*Plus'? Specuklation, but it is one thing I might do to subtly raise the flag. Best bet - ask Support.
    Edited by: Hans Forbrich on Mar 7, 2012 2:29 PM

  • Cannot see table in sql developer or sql plus

    I have created a record in application designer. I have then built the table. I can close the record and then find it again in application designer. But if I go to sql plus or sql developer, I cannot see it. Am I missing a step?

    You probably can see all the tables of sysadm because someone else give you proper grant for that on existing sysadm's objects.
    For the new or modified object (drop+create) you should :
    1. connect as sysadm and run
    grant select on new_table_name to your_own_user;2. connect with your own user and run
    create synonym new_table_name for sysadm.new_table_name;Then you'll be able to query that table without using schema name alias.
    Some admin have also a ddl trigger to make it automatically.
    You could also work through a role and public synonym if more than one user needs to access sysadm's objects.
    Nicolas.

  • Oracle10g Developer Suite - Application Development - SQL Plus Login Info

    I have installed Oracle10g Developer Suite and when I am trying to login into the sql*plus environment the username scott with the passcode tiger is not working. I have Oracle9i Enterprise Edition Release 9.2.0.1.0 as the database.
    Can anyone help me in setting up the username and password to login into Sql*plus Release 10.1.0.4.2

    It sounds like you may be new to Oracle and its products. I would recommend doing some reading.
    Oracle 9.2 Net Services Admin Guide
    http://download-west.oracle.com/docs/cd/B10501_01/network.920/a96580/toc.htm
    Oracle Developer Suite Installation Guide
    http://download-west.oracle.com/docs/cd/B25016_06/doc/dl/core/B16012_03/toc.htm
    You create the "login" information when you install the database. If you are not the person who performed the installation, you will need to contact them or install it again. Also, be aware that the SCOTT schema is disabled by default in newer database versions for security reasons.
    The tnsnames.ora and sqlnet.ora files can be found in the ORACLE_HOME\network\admin directory. This is the same for all Oracle products that use Sql-Net for database connections. You can also use the TNS_ADMIN environment variable to point to a pre-existing tnsnames.ora file (see previously mentioned documents).
    The tnsnames.ora entry will be unique to your database and its listener however here is an example:
    ORCL =
    (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = someServer.com)(PORT = 1521))
    (CONNECT_DATA =
    (SERVICE_NAME = orcl)
    )

  • Oracle:JDBC Call returns no results, SQL*Plus returns 1 record, Please help

    Any help would be greatly appreciated.
    Running 9.2.0.5.0, and using latest 9.2 JDBC 1.4_g drivers in thin mode.
    Execute the following query from SQL*Plus and it returns one row, from JDBC using a PreparedStatement, I get no results. Here's the query, table def, record, etc.:
    Query:
    SELECT
    ID_WEB_FRM,ID_WEB_SIT,CDE_LVL_1_FUNC,
    CDE_LVL_2_FUNC,NUM_WEB_FUNC_PG,NUM_WEB_PG_ID
    FROM
    WEB_FRM
    WHERE
    ID_WEB_FRM = ' '
    OR
    (ID_WEB_SIT = 'test' AND CDE_LVL_1_FUNC = ' '
    AND CDE_LVL_2_FUNC = 'u2T' AND NUM_WEB_FUNC_PG = 1
    AND NUM_WEB_PG_ID = 0)
    Record returned from SQL*Plus:
    ID_WEB_FRM ID_WEB_SIT CDE CDE NUM_WEB_FUNC_PG NUM_WEB_PG_ID
    NfRRmc5XZu test u2T 1 0
    Both in the data returned and the query, there are no blanks, but they are a single space instead (hard to see in message here).
    Java code:
    int count = 1;
    findDBNameStatement.setString(count++," ");
    findDBNameStatement.setString(count++,form.getSiteID());
    findDBNameStatement.setString(count++," ");
    findDBNameStatement.setString(count++, form.getFunctionID());
    findDBNameStatement.setInt(count++,form.getPageNumber());
    findDBNameStatement.setInt(count++,form.getSectionNumber());
    ResultSet resultSet = findDBNameStatement.executeQuery();
    ResultSetMetaData metaData = resultSet.getMetaData();
    resultSet.next() returns false
    DB table:
    CREATE TABLE web_frm (
    ID_WEB_FRM varchar2(10) NOT NULL,
    ID_WEB_SIT varchar2(20) NOT NULL,
    NAM_WEB_FRM varchar2(40),
    TXT_EMAIL_SUBJ varchar2(50),
    CDE_LVL_1_FUNC char(3),
    CDE_LVL_2_FUNC char(3) NOT NULL,
    NUM_WEB_FUNC_PG int NOT NULL,
    NUM_WEB_PG_ID smallint NOT NULL,
    DTE_WEB_FRM_EFF date NOT NULL,
    DTE_WEB_FRM_TRM date,
    CDE_VLDT_RUL char(3),
    DTE_LAST_EXPRT date,
    TXT_CNFRMN_MSG varchar2(4000),
    IND_UPDT_ALWD char(1) NOT NULL,
    TXT_RECAP_HDR varchar2(4000),
    TXT_RECAP_FTR varchar2(4000),
    CDE_WEB_OBJ char(3),
    NUM_MAX_FRM_WIDTH number(4,0),
    IND_RECAP_PG char(1) NOT NULL,
    IND_CNFRM_PG char(1) NOT NULL,
    IND_DSPL_CNFRM_NUM char(1) NOT NULL,
    CNT_SUBM_MAX int,
    TXT_CHCE_ADD_MSG varchar2(255),
    TXT_CHCE_MOD_MSG varchar2(255),
    TXT_WEB_HDR varchar2(4000),
    TXT_WEB_FTR varchar2(4000),
    TXT_WAIT_LIST_MSG varchar2(255),
    FORMOBJECTHEIGHT int NOT NULL,
    FORMOBJECTWIDTH int NOT NULL
    ALTER TABLE web_frm ADD ( CONSTRAINT PK_web_frm PRIMARY KEY (ID_WEB_FRM));
    ALTER TABLE web_frm ADD ( CONSTRAINT UK_web_frm UNIQUE (ID_WEB_SIT,CDE_LVL_1_FUNC,CDE_LVL_2_FUNC,NUM_WEB_FUNC_PG,NUM_WEB_PG_ID)) ;
    Thanks,
    Matt

    That's not quite right. From the javadocs:
    next
    public boolean next()
    throws SQLException
    Moves the cursor down one row from its current position. A ResultSet cursor is initially positioned before the first row; the first call to the method next makes the first row the current row; the second call makes the second row the current row, and so on.
    If an input stream is open for the current row, a call to the method next will implicitly close it. A ResultSet object's warning chain is cleared when a new row is read.
    Returns:
    true if the new current row is valid; false if there are no more rows
    Throws:
    SQLException - if a database access error occurs

  • JDBC Call returns no results, SQL*Plus returns 1 record, Please help!

    Any help would be greatly appreciated.
    Running 9.2.0.5.0, and using latest 9.2 JDBC 1.4_g drivers in thin mode.
    Execute the following query from SQL*Plus and it returns one row, from JDBC using a PreparedStatement, I get no results. Here's the query, table def, record, etc.:
    Query:
    SELECT
    ID_WEB_FRM,ID_WEB_SIT,CDE_LVL_1_FUNC,
    CDE_LVL_2_FUNC,NUM_WEB_FUNC_PG,NUM_WEB_PG_ID
    FROM
    WEB_FRM
    WHERE
    ID_WEB_FRM = ' '
    OR
    (ID_WEB_SIT = 'test' AND CDE_LVL_1_FUNC = ' '
    AND CDE_LVL_2_FUNC = 'u2T' AND NUM_WEB_FUNC_PG = 1
    AND NUM_WEB_PG_ID = 0)
    Record returned from SQL*Plus:
    ID_WEB_FRM ID_WEB_SIT CDE CDE NUM_WEB_FUNC_PG NUM_WEB_PG_ID
    NfRRmc5XZu test u2T 1 0
    Both in the data returned and the query, there are no blanks, but they are a single space instead (hard to see in message here).
    Java code:
    int count = 1;
    findDBNameStatement.setString(count++," ");
    findDBNameStatement.setString(count++,form.getSiteID());
    findDBNameStatement.setString(count++," ");
    findDBNameStatement.setString(count++, form.getFunctionID());
    findDBNameStatement.setInt(count++,form.getPageNumber());
    findDBNameStatement.setInt(count++,form.getSectionNumber());
    ResultSet resultSet = findDBNameStatement.executeQuery();
    ResultSetMetaData metaData = resultSet.getMetaData();
    resultSet.next() returns false
    DB table:
    CREATE TABLE web_frm (
    ID_WEB_FRM varchar2(10) NOT NULL,
    ID_WEB_SIT varchar2(20) NOT NULL,
    NAM_WEB_FRM varchar2(40),
    TXT_EMAIL_SUBJ varchar2(50),
    CDE_LVL_1_FUNC char(3),
    CDE_LVL_2_FUNC char(3) NOT NULL,
    NUM_WEB_FUNC_PG int NOT NULL,
    NUM_WEB_PG_ID smallint NOT NULL,
    DTE_WEB_FRM_EFF date NOT NULL,
    DTE_WEB_FRM_TRM date,
    CDE_VLDT_RUL char(3),
    DTE_LAST_EXPRT date,
    TXT_CNFRMN_MSG varchar2(4000),
    IND_UPDT_ALWD char(1) NOT NULL,
    TXT_RECAP_HDR varchar2(4000),
    TXT_RECAP_FTR varchar2(4000),
    CDE_WEB_OBJ char(3),
    NUM_MAX_FRM_WIDTH number(4,0),
    IND_RECAP_PG char(1) NOT NULL,
    IND_CNFRM_PG char(1) NOT NULL,
    IND_DSPL_CNFRM_NUM char(1) NOT NULL,
    CNT_SUBM_MAX int,
    TXT_CHCE_ADD_MSG varchar2(255),
    TXT_CHCE_MOD_MSG varchar2(255),
    TXT_WEB_HDR varchar2(4000),
    TXT_WEB_FTR varchar2(4000),
    TXT_WAIT_LIST_MSG varchar2(255),
    FORMOBJECTHEIGHT int NOT NULL,
    FORMOBJECTWIDTH int NOT NULL
    ALTER TABLE web_frm ADD ( CONSTRAINT PK_web_frm PRIMARY KEY (ID_WEB_FRM));
    ALTER TABLE web_frm ADD ( CONSTRAINT UK_web_frm UNIQUE (ID_WEB_SIT,CDE_LVL_1_FUNC,CDE_LVL_2_FUNC,NUM_WEB_FUNC_PG,NUM_WEB_PG_ID)) ;
    Thanks,
    Matt

    I have verified the parameters and such, and if I run as a Statement instead of a PreparedStatement, the query works fine. After some more troubleshooting, I narrowed the problem down, but not sure of the fix.
    If I eliminate teh extra parameters and simplify things to:
    SELECT ID_WEB_FRM FROM WEB_FRM WHERE ID_WEB_SIT = 'test' AND CDE_LVL_2_FUNC = 'u2T' AND NUM_WEB_FUNC_PG = 1 AND NUM_WEB_PG_ID = 0
    The code works. But if I add the additional WHERE clause of CDE_LVL_1_FUNC = ' ' (has single space), it returns no data (record in the DB has single space in this new column. Query that does not work:
    SELECT ID_WEB_FRM FROM WEB_FRM WHERE ID_WEB_SIT = 'test' AND CDE_LVL_1_FUNC = ' ' AND CDE_LVL_2_FUNC = 'u2T' AND NUM_WEB_FUNC_PG = 1 AND NUM_WEB_PG_ID = 0
    It appears the JDBC Driver is trimming the parameter when it is a space when set through a PreparedStatement.setString(2," ")

  • Explain plan results are different in SQL Developer than SQL Plus

    My Environment:
    SQL Developer 1.0.0.15.27
    Platform where SQL Developer is running: Windows XP 2002 SP2
    Oracle Database and Client 9.2.0.7
    Optimizer_mode: FIRST_ROWS
    I have the following SQL statement:
    SELECT a1.comp_id
    FROM temp_au_company a0, au_company a1
    WHERE :b2 = a0.temp_emp_code
    AND a0.comp_id = a1.comp_id
    AND a0.sls_terr_code != a1.sls_terr_code
    AND a1.last_mdfy_date > :b1
    When I run an Explain in SQL Developer I get the following access path (which is the one I really want):
    SELECT STATEMENT                          TABLE ACCESS(BY INDEX ROWID) FEDLINK.AU_COMPANY          NESTED LOOPS                                   INDEX(RANGE SCAN)
    FEDLINK.UX2_TEMP_AU_COMPANY
              INDEX(RANGE SCAN) FEDLINK.PX1_COMPANY
    However, when I execute the statement with sql_trace turned on and use tkprof to generate the actual access path, the statement executes as follows (which is WAY more expensive):
    call count cpu elapsed disk query current rows
    Parse 1 0.00 0.00 0 0 0 0
    Execute 1 0.00 0.00 0 0 0 0
    Fetch 1 3.58 6.68 28136 29232 0 0
    total 3 3.58 6.69 28136 29232 0 0
    Misses in library cache during parse: 1
    Optimizer goal: FIRST_ROWS
    Parsing user id: 979 (FEDLINK) (recursive depth: 1)
    Rows Row Source Operation
    0 NESTED LOOPS
    0 TABLE ACCESS FULL AU_COMPANY
    0 INDEX RANGE SCAN UX2_TEMP_AU_COMPANY (object id 49783)
    Notice the FULL access of au_company.
    I understand that SQL Developer has nothing to do with why the statement executed the way it did, but why is the Explain in SQL Developer different than the actual execution plan?
    Added note....when I run the explain in SQL Plus it is the same as the actual execution. Here is the explain from SQL Plus:
    explain plan for SELECT a1.comp_id
    FROM temp_au_company a0, au_company a1
    WHERE '1' = a0.temp_emp_code
    AND a0.comp_id = a1.comp_id
    AND a0.sls_terr_code != a1.sls_terr_code
    AND a1.last_mdfy_date > '01-MAY-2006';
    PLAN_TABLE_OUTPUT
    | Id | Operation | Name | Rows | Bytes | Cost |
    | 0 | SELECT STATEMENT | | 2 | 76 | 2597 |
    | 1 | NESTED LOOPS | | 2 | 76 | 2597 |
    | 2 | TABLE ACCESS FULL | AU_COMPANY | 2 | 42 | 2595 |
    | 3 | INDEX RANGE SCAN | UX2_TEMP_AU_COMPANY | 1 | 17 | 2
    Thanks,
    Brenda

    The explain is different (full scan of au_company in SQL Plus / index access in SQL Developer) even when I use variables in SQL Plus. Here is the output for SQL Plus using variables instead of literals:
    SQL> variable b1 varchar2
    SQL> variable b2 char
    SQL> explain plan for SELECT a1.comp_id
    2 FROM temp_au_company a0, au_company a1
    3 WHERE :b2 = a0.temp_emp_code
    4 AND a0.comp_id = a1.comp_id
    5 AND a0.sls_terr_code != a1.sls_terr_code
    6 AND a1.last_mdfy_date > :b1
    7 /
    Explained.
    PLAN_TABLE_OUTPUT
    | Id | Operation | Name | Rows | Bytes | Cost |
    | 0 | SELECT STATEMENT | | 3184 | 118K| 2995 |
    | 1 | HASH JOIN | | 3184 | 118K| 2995 |
    | 2 | INDEX RANGE SCAN | UX2_TEMP_AU_COMPANY | 3187 | 54179 | 3 |
    | 3 | TABLE ACCESS FULL | AU_COMPANY | 24009 | 492K| 2983 |
    Any other ideas? They should be the same.
    Brenda

  • Locked out of SQL*PLUS!! HELP!

    i have just started using sql*plus to access my 10g database as it was all installed on my computer by someone else for me.... and the helpfully didnt tell me the user name and password they had used
    so when i got my laptop back and discovered that i couldnt log in as scott/tiger or anything else... started messing around and managed to get a dialoge box asking me to enter a password for SYSMAN so i did so and everything was fine,,,,,
    Until i restarted my computer now it says that SYSMAN is locked just like it says for all the other standard logins!! now ive had a read around and people keep saying just grant the privelages to the scott/tiger account..... how can i do that if i cant log in as anything???
    please help oh super smart guru peoples :)
    thanks in advance
    RMMO (PL/SQL / SQL*PLUS NOOBMASTER!)

    thanks for that... sadly it didnt work... the database is local to my laptop.... but when i entered that command into cmd... another command prompt opens up for a split second then closes back down... there isnt enough time to see anything displayed in it... but i assume that it tells me that either the account is locked like all the other accounts or it says that its not a valid username/password... or somthing to that effect....
    again thankyou for the time you put into helping.... and sadly again any other ideas or possible solutions would be GREATLY appreciated!
    RMMO
    (undercover noob)

  • How to change the default directory from within SQL*Plus ?

    Hello,
    I want to change the default directory directly from within SQL*Plus to be able to launch my command files with simple instructions like :
    @my_command.sql
    If I haven't launched SQL*Plus from the directory containing the file my_command.sql, how do I change the default directory to the directory of my command files ?
    I've searched through the Oracle documentation, there's no SET DEFAULTDIR or something like that. When I do a SHOW ALL, there's no variable containing the default directory.
    If you have an idea...
    regards,
    Jérôme.

    Hi Jérôme (J鲴me ?),
    You cannot directly do that, but you can use @@ instead of @ to run subscripts in the same directory as the superscript
    # head /tmp/tl30/xxx/[xyz].sql                    
    ==> /tmp/tl30/xxx/x.sql <==
    prompt call y
    @y
    prompt call z
    @@z
    quit
    ==> /tmp/tl30/xxx/y.sql <==
    prompt i am in y
    ==> /tmp/tl30/xxx/z.sql <==
    prompt i am in z
    # pwd                                             
    /root
    # sqlplus -s scott/tiger@lsc62 @/tmp/tl30/xxx/x.sql
    call y
    SP2-0310: Datei "y.sql" konnte nicht geöffnet werden
    call z
    i am in zKind regards
    Laurent Schneider
    OCM DBA

  • Problem running SQL PLUS in Oracle 8i and 9i on Windows XP

    I've tried installing both Oracle 8.17 Personal Edition and also 9i in Windows XP Professional (each on a different occassion). I have run into the same problem each time. The installation itself goes fine in both cases, but when I run SQL PLUS, the Log On screen appears for 1-2 seconds then whole thing just closes automatically, so I can't ever access that application which is the only thing I need to work with. Any ideas on what's going wrong? Thanks.

    Patrick,
    Well a few things. Did you try TNSPING to see if the listener is up? If it's ok, can you connect with FREE toad? Download Oracle OEM and install that (the SQL net and sql plus portions). If you can't get tnsping to work, sqlplus isn't going too either. I don't know why the sqplus is actually shutting down, but I'm guessing the TNS NAMES entry isnt there (in the tnsnames.ora file). If the tnsnames entry is there then tnsping should work. Get tnsping to work first.
    Tyler.

  • Execute procedure with out parameter in sql*plus

    HI All,
    I am executing an stored proc with OUT parameter from sql*plus.
    Getting this error message:
    SQL> execute sp1_cr_ln_num('01',0,3);
    BEGIN sp1_cr_ln_num('01',0,3); END;
    ERROR at line 1:
    ORA-06550: line 1, column 7:
    PLS-00306: wrong number or types of arguments in call to
    'sp1_cr_ln_num'
    ORA-06550: line 1, column 7:
    PL/SQL: Statement ignored
    Whereas it works fine using Toad. 4th parameter is for output.
    Thanks.

    then you can see the value either using print :var or execute dbms_output.put_line(:var)

Maybe you are looking for