NOT IN SQL statement

Hello

I have this SQL statement like below:

Select the data for the customer whose name = "John" and customer_id NOT IN (SELECT customer_id customer where customer_id = '111');

Is it possible to do or should I change it?

Hello

SELECT c.data
  FROM customer c,
       orders   o
 WHERE c.NAME = 'John'
   AND c.customer_id = o.customer_id
   AND o.customer_id != '111';

Kind regards

Tags: Database

Similar Questions

  • Game of demand does not pick up the good period open to active fixed from the SQL statement

    Hello

    We have a demand that could kick off the simultaneous application of the value: Ixr: list of asset by period and Ixr: reserve book report.


    ON overall demand, we set the parameter: default period based on a SQL = select period_name from FA_DEPRN_PERIODS where book_type_code = 'PER2011' and period_close_date is null


    The query runs with the good period, until we open the new period, the game application will still come closed period.

    When I run this script on the database, it gives the correct name of the open period.


    Why all the demand does not pick up the open period?


    Rock


    Hello

    When planning, the parameter values that you gave when planning will not change.

    For the test, for a simultaneous program, I create a parameter and has given the value 100 tank and default type sql statement and the value as below.

    Select to_char (sysdate, 'dd-mon-yyyy hh24:mi:ss') of double

    If, at the time of the program, it shows a default value such as the date and time with seconds. Then I planned it for every minute.

    When you check in for each race it is seen the first time only, it does not.

    so in your case, you must plan its new after change of period.

    Hope this will help you...

  • Vo SQL statement will not use aliases

    Hello!

    When I tried to enter the following code in the SQL statement in my definition of VO, it gave me an error in column ambiguously defined:

    SELECT a.PERSON_ID,

    a.EFFECTIVE_START_DATE,

    a.EFFECTIVE_END_DATE,

    a.EFFECTIVE_START_DATE,

    a.EFFECTIVE_END_DATE,

    a.EMPLOYEE_NUMBER,

    a.FULL_NAME

    OF PER_ALL_PEOPLE_F one

    I need to put an alias because I need to refer to one of its columns inside the place where the condition. What is supposed to be the right way to set it?

    Thank you.

    whatever the dynamic where clause you add with setwhereclause, it is added on top of the query you mentioned in the original Version, so your alias doesn't work

    Now if you look at the care of error fully you can see you are querying VO got closed in support () and another alias has been given by the framework (OAF) so all adding the whereclause by setwherelcause dynamically delete pls the 'a'., of the Sub statement

    setWhereClause ("a.employee_number =: 1 and a.effective_end_date = (select max (effective_end_date) in the per_all_people_f where employee_number = a.employee_number) '");

    ratther write like

    setWhereClause ("employee_number =: 1 and effective_end_date = (select max (effective_end_date) in the per_all_people_f b where b.employee_number =: 2)" ");

    setWhereClauseParams (null); Always reset

    setWhereClauseParam (0, EmpNumber);

    setWhereClauseParam (1, EmpNumber);

    I hope that is clear, if not please let me know.

    Kind regards

    Hemant

  • 12 c call Webservice JDeveloper get "SQL string is not a DML statement" as a SQLException exception

    Hi guys,.

    I developed a java class to access the database using the OracleDataSource class and run a SQL query with a select statement. It works very well. I have built a wrapper class and as a Web service. I get "SQL string is not a DML statement" as a SQLException exception when I run as a Web service, but it works very well as an application.

    No idea why I get this error? Not sure why WebSercie is having a problem while this works as an application.

    Thank you and best regards,

    Srini Mel

    Solved the problem by myself.

    The first release "SQL string is not a DML statement" is due to an additional line (pstmt2.executeUpdate ()) in the code.

    Second question, receives not the query response is due to bad user input. I walked into 13.21651 instead of 31.21651.

    Thank you!

    Srini

  • ORA-13780: SQL statement does not exist

    Hello
    on the 11g R2, I get the following message:
    SQL> variable stmt_task VARCHAR2(64);
    SQL> EXEC :stmt_task := DBMS_SQLTUNE.CREATE_TUNING_TASK(sql_id => 'gh9p77g1fr0kd');
    BEGIN :stmt_task := DBMS_SQLTUNE.CREATE_TUNING_TASK(sql_id => 'gh9p77g1fr0kd'); END;
    
    *
    ERROR at line 1:
    ORA-13780: SQL statement does not exist.
    ORA-06512: at "SYS.DBMS_SYS_ERROR", line 79
    ORA-06512: at "SYS.PRVT_SQLADV_INFRA", line 125
    ORA-06512: at "SYS.DBMS_SQLTUNE", line 655
    ORA-06512: at line 1
    Any idea?

    Thank you.

    Sql and the sql_id execution plan has been emptied out of the shared pool, so oracle could not find it.

    -Thank you

  • Question of SQL statement

    I have this PreExpression at a stage of SQL statement:

    Locals.SQL_LatestResult = "SELECT UUT_RESULT.ID, UUT_RESULT. UUT_SERIAL_NUMBER, UUT_RESULT. START_DATE_TIME UUT_RESULT WHERE (((UUT_RESULT. UUT_SERIAL_NUMBER) =------"' + Locals.serial + ' \ ') AND ((UUT_RESULT." START_DATE_TIME) = (SELECT MAX (UUT_RESULT2. START_DATE_TIME) OF UUT_RESULT AS UUT_RESULT2 WHERE UUT_RESULT. UUT_SERIAL_NUMBER = UUT_RESULT2. UUT_SERIAL_NUMBER))); »

    Locals.SQL_LatestResult has this value after the PreExpression:

    SELECT UUT_RESULT.ID, UUT_RESULT. UUT_SERIAL_NUMBER, UUT_RESULT. START_DATE_TIME UUT_RESULT WHERE (((UUT_RESULT. UUT_SERIAL_NUMBER) = "15514011") AND ((UUT_RESULT. START_DATE_TIME) = (SELECT MAX (UUT_RESULT2. START_DATE_TIME) OF UUT_RESULT AS UUT_RESULT2 WHERE UUT_RESULT. UUT_SERIAL_NUMBER = UUT_RESULT2. UUT_SERIAL_NUMBER)));

    I get the number of records = 0, if I run the sequence.

    If I copy the exact same SQL query in access I get what I want to know a record.

    If I remove that part of the query:

    ((UUT_RESULT. UUT_SERIAL_NUMBER) =------"" + Locals.serial + "\") "

    I get 388 records which is correct and it run directly in access.

    What's not here?

    I was too fast for this post... it's my fault, the database link was wrong, so data were there...

    Statements are very good!

  • With the help of a number variable in a SQL statement

    Hello

    I am trying to use a variable in a sql statement, and I ran into problems when the variable is a number. The following line of code works if the variable is a string, but not if it is a number.

    "SELECT PAGE 1 UUT_STATUS OF UNIT_UUT_RESULT WHERE UnitID = '" + Locals.LocalUnitID + "' ORDER BY DESC START_DATE_TIME.

    Is there a difference in the use of single and double quotes and the sign for numbers variables +?

    Thank you

    Stuart

    Jervin is almost correct in the post above.

    While it is correct that numbers in SQL are not enclosed in single quotes ('), we still need the entire expression to a string.  If Locals.LocalUnitID is stored as a number to TestStand, you will need to cast to a string so that the string concatination works properly.

    I believe that the correct form is as follows:

    "SELECT PAGE 1 UUT_STATUS OF UNIT_UUT_RESULT WHERE UnitID ="+ Str (Locals.LocalUnitID) + 'ORDER BY DESC START_DATE_TIME'

  • Partitions don't synchronize only not - Oracle SQL Developer 4.1.3.20

    Hello

    First of all, thanks a lot for developers for this great tool.

    I use the Data Modeler which comes with Oracle SQL Developer 4.1.3.20.

    In the 12 c database, I created the following table:

    CREATE

    TABLE MMOURA. TEST_TABLE

    (

    NUMBER OF ID_TEST_TABLE (10) NOT NULL

    DATE_TEST_TABLE DATE NOT NULL

    )

    ORGANIZATION HEAP PCTFREE 10

    LOGGING NOCOMPRESS NO INMEMORY

    NOCACHE NOPARALLEL NOROWDEPENDENCIES DISABLE THE MOVEMENT OF THE LINE;

    I import with Data Modeler and add the partition:

    CREATE

    TABLE MMOURA. TEST_TABLE

    (

    NUMBER OF ID_TEST_TABLE (10) NOT NULL

    DATE_TEST_TABLE DATE NOT NULL

    )

    ORGANIZATION HEAP PCTFREE 10 TABLESPACE SYSTEM NOT LOGGING NOCOMPRESS NO INMEMORY RANGE PARTITION

    (

    DATE_TEST_TABLE

    )

    INTERVAL OF

    (

    NUMTOYMINTERVAL (1, 'MONTH')

    )

    (

    PARTITION P_BEFORE_2010 VALUES LESS THAN (TO_DATE (JANUARY 1, 2010 ',' DD/MM/YYYY "")) NOCOMPRESS

    )

    NOCACHE NOPARALLEL NOROWDEPENDENCIES DISABLE THE MOVEMENT OF THE LINE;

    So I can create a partition and generates the correct code.

    I click on "Synchronize data dictionary with model" and see the differences with the model and the database.

    In the models 'compare', 'Physical Details' is red. 'Partition' is red, "Selected" are marked, "Source table: TEST_TABLE ' is YES and" target Table: TEST_TABLE "is no.

    "Partitioning" is marked, and I can see the new partition "P_BEFORE_2010."

    teste_partition_chamado_oracle.png

    But when I click on 'Overview of DOF', theres no changes:

    -Generated by Oracle SQL Developer Data Modeler 4.1.3.901

    -in: 2016-01-14 14:19:50 BRST

    -site: database Oracle 12 c

    -type: Oracle Database 12 c

    -Oracle SQL Developer Data Model Summary Report:

    --

    -CREATE TABLE 0

    -CREATION OF INDEX 0

    ...

    ...

    In the tool preferences, model, synchronization, it is marked:

    FUNCTION

    PACKAGE

    PROCEDURE

    ROLE

    SEQUENCE

    SYNONYM

    TABLESPACE

    In "Import Options", it is marked:

    Partitions

    Triggered

    What I am doing wrong? Is this some sort of bug?

    Hi Marcio,

    I'm afraid that data Modeler does not "DOF Preview" statements for changes in the distribution.

    Kind regards

    David

  • will not appear sql statemnt in shell script

    Hello

    I have a shell script with an unfavourable sql she calls another script where I connect to dabase.

    In the journal of the script, I see the sql statement and I wish that that do not show me anything. How I make these?

    Thank you

    Hello

    2650697 wrote:

    Hello

    I have a shell script with an unfavourable sql she calls another script where I connect to dabase.

    In the journal of the script, I see the sql statement and I wish that that do not show me anything. How I make these?

    Thank you

    Your postal code.  It is very difficult to tell what you're doing wrong without knowing what you are doing.

    You can have SQL statements directly in your shell script.  They must be in a script by themselves, said fubar.sql, and shell script must contain

    @fubar

    instead of real SQL statements.

  • How can I pass a condition of the table in the sql statement?

    For example, in the table in the COND Varchar2 column (200) there is the value ' VAR > 10'.

    | COND |

    |' VAR > 10' |

    where VAR is the name of the table column. I would like to make statement CASE WHEN VAR > 10 AND 0... I tried with as subquery

    WHEN BOX (SELECT COND FROM TABLE WHERE...) THEN 0, but it does not work.

    Hello

    You can do this by using dynamic SQL.

    that is to say:

    declare
      v_stm      varchar2(4000);
      v_cond      varchar2(100);
      v_result    integer;
    begin
      select cond
        into v_cond
        from yourtable
      where a=1;
    
      v_stm := 'select case when '||v_cond||' then 0 ...';
    
      -- dynamic sql
      execute immediate v_stm
        into v_result;
    
    end;
    /
    

    Remember that, in general, dynamic SQL has a performance degradation that SQL static and should be avoided when possible.

    Storage condition or the SQL statements in the tables is not a good practice.

    Kind regards.

    Alberto

  • Identify the SQL statements that are executed frequently

    I would like to identify SQL statements that are executed may times (e.g., > 1000 times) during an interval AWR.

    I am aware of coloring a SQL_ID with exec ('...') dbms_workload_repository.add_colored_sql; but then the SQL ID must be known.

    Is it also possible to do the same for the (not yet known) SQL statements that are executed > 1000 times? I think that the SQL statements that run very quickly (for example 1 s <) won't be captured automatically in a CWA even if those statements are frequently performed.

    Version 11.2.0.4 on SLES11

    Try this...

    fixed lines 155

    execs from collar to 999 999 999

    Col min_etime to 999,999.99

    Col max_etime to 999,999.99

    Col avg_etime to 999,999.999

    Col avg_lio to 999,999,999.9

    Col norm_stddev to 999,999.9999

    Col begin_interval_time to a30

    node of col to 99999

    break on plan_hash_value on startup_time skip 1

    Select * from)

    Select sql_id, sum (execs), min (avg_etime) min_etime, max (avg_etime) max_etime stddev_etime/min (avg_etime) norm_stddev

    de)

    Select sql_id, execs, plan_hash_value, avg_etime,

    StdDev (avg_etime) on stddev_etime (sql_id partition)

    de)

    Select sql_id, plan_hash_value,.

    Sum (NVL(executions_delta,0)) execs,

    (sum (elapsed_time_delta) /decode (sum (nvl(executions_delta,0)), 0.1, sum (executions_delta)) / 1000000) avg_etime

    -sum ((buffer_gets_delta/decode (nvl(buffer_gets_delta,0), 0.1, executions_delta))) avg_lio

    DBA_HIST_SQLSTAT s, DBA_HIST_SNAPSHOT SS

    where ss.snap_id = S.snap_id

    and ss.instance_number = S.instance_number

    and executions_delta > 0

    Group of sql_id, plan_hash_value

    )

    )

    Group of sql_id, stddev_etime

    )

    where norm_stddev > nvl (to_number('&min_stddev'), 2)

    and max_etime > nvl (to_number('&min_etime'),.1)

    order of norm_stddev

    /

  • Get the SQL statement error programmatically

    Hello

    error SQL in the FORMS, you can display the erroneous SQL statement pressing (shift) (Ctrl) E on the screen. Is there a way to get the text of the SQL statement in a PL/SQL function for logging purposes?

    I get the error using SQLERRM, it's not a problem. But how can I get the SQL text of the statement?

    Thanks and regards,

    Sascha

    Sascha,

    You should be able to use the: SYSTEM. System LAST_QUERY variable forms.

    Craig...

  • Several SQL statements with zero executions in the region of SQL

    Hello

    one of my databases has a large number of statements in the SQL box with zero executions. Some of them analyzed several times without a single run. Why the database stores these statements and how to avoid or reduce them?

    My problem is that the only time or zero time sql statements take the largest part of the area of sql:

    -sql statement and only once and without executing sql statements

    Select

    Count (1) num_sql_total,.

    sum (decode (executions, 1, 1, 0)) num_one_use_sql,.

    sum (decode (executions, 0, 1, 0)) num_no_use_sql,.

    Sum (RUNTIME_MEM) / 1024/1024 mb_used,.

    sum (decode (executions, sharable_mem, 1, 0)) / 1024/1024 mb_for_one_use_sql,.

    sum (decode (executions, 0, sharable_mem, 0)) / 1024/1024 mb_for_no_use_sql

    Of

    GV$ sqlarea

    where

    RUNTIME_MEM > 0;

    NUM_SQL_TOTAL NUM_ONE_USE_SQL NUM_NO_USE_SQL MB_USED MB_FOR_ONE_USE_SQL MB_FOR_NO_USE_SQL

    23318

    8739

    8027

    1420,95619106293

    381,41183757782

    530,999855041504

    Concerning

    Thomas

    This is not unusual. Another app could analyze for example hard the most often used SQLs in upstairs app - making benefit of further processing (in theory) of sweet analysis when you use these SQLs.

    In fact, I remember reading something to this effect as a performance for some factor or another Oracle document or note?

    So unless you have serious questions of shared pool, why bother with these sliders? What would be the problem?

  • Order of execution of SQL statements

    Hello

    I have two SQL statements where the first statement executes on a table with more than 40 million lines, the second statement is running on a table more 6 million lines.  When they are running their own each take about 0.15 seconds to run, but when combined they take 20 minutes to run, (the second SQL statement is inserted in the WHERE clause of the statement of first).  It would seem that after combining these statements, the first statement goes through all 40 million lines before it performs the SELECT in the WHERE clause.  I think that what is necessary is to ensure the SELECT in the WHERE clause is executed first... or something like that!  Anyone has any ideas on how to combine these statements but not suffer from the performance impact?

    The first statement is:

    Select csi.instance_id,

    OEL.ordered_item

    of apps.csi_item_instances csi,.

    Apps.oe_order_lines_all oel

    where csi.instance_id in

    (1718000,3698000,48740202)

    and csi.last_oe_order_line_id = oel.line_id;

    The second statement is:

    Select / * + INDEX (IEA (attribute_id)) * /.

    IEA.instance_id

    apps.csi_iea_values do

    where iea.attribute_id = 10004

    and iea.attribute_value is not null;

    The joint return is:

    Select csi.instance_id,

    OEL.ordered_item

    of apps.csi_item_instances csi,.

    Apps.oe_order_lines_all oel

    where csi.instance_id in

    (select / * + INDEX (IEA (attribute_id)) * /)

    IEA.instance_id

    apps.csi_iea_values do

    where iea.attribute_id = 10004

    and iea.attribute_value is not null)

    and csi.last_oe_order_line_id = oel.line_id;

    Thanks for any help,

    Mike

    Your subquery returns probably just two values that you did originally as constants - but the optimizer thinks that you're going to get 564 K lines.  This is why the indicator for the simple query has a beneficial effect, it forces the Oracle to use an index when it would otherwise make a search.

    When the subquery is incorporated, however, the optimizer uses its cardinality expected to decide whether to use a nested loop join or the hash join to CSI_ITEM_INSTANCES, since the large enough estimate, he uses the hash with a join analysis complete.  That's why I pointed out that the fact to tell the optimizer to how many lines outside the subquery should make a difference.

    Have you tried the "common table expression" approach, rather than approach no_merge, but it would not help because it does not change the optimizer for cardinality estimate.  If you want to repeat the method CTE adding boards / * + materialize cardinality (2) * / to the query in the WITH clause, you should get the desired result.

    Concerning

    Jonathan Lewis

  • Copy SQL statement to another database with the same SQL_ID

    Is there a reliable way to copy a sql statement in a database to another preserving the formatting so it ends with the same SQL_ID.

    I want to copy a statement of the shared pool to a test database to develop a plan to import sql database in production.

    In the past, I just did ' select sql_fulltext from v$ sql "in SQL Developer and pasted the result into a spreadsheet SQL Developer and run it.   The statement is now in the pool shared with the correct sql_id.

    This does not work for instruction, I am currently in train.  It ends with a different id of sql.

    I know it's probably a problem of formatting, but the statement is 1000 characters and a manual check will take forever.

    You could put in a SQL Tuning Set and transfer it.

Maybe you are looking for

  • Compatible motherboards for a Satellite 1800

    My motherboard is out and I'm looking to replace it. Anyone know if it is posible, and what are some other compatible cards puts. I bought a CPU but it's a small pin 478 in the 1800s is a big... I want a Board that will work with the new processor, I

  • I5 Dell with Windows 7 does not support some games like Winning Eleven

    I am so deppressed * original title - I bought Dell i5 with geniune windows 7 installed (64-bit), but it can not support the games as winning eleven... etc... pls advice *.

  • My Alfa wireless network card device not show my D-link Access Point

    Hello world I point to access Dlink DWL 3200 & connected with several computers laptops & mobile but in my office with Alfa wireless adaptor, it does not show the access point.Could you get it someone please let me know where is the problem. Thank yo

  • non-rechargeable batteries

    I like sandisc is that you can use at high altitude. I am looking for a new and they all seem to have rechargeable batteries which is difficult to do a long trip. Are there other options of battery?

  • Capacity lost to play iTunes

    I believe that I have can I have deleted a particular file in Windows to allow iTunes to operate.  The error message is "The procedure entry that point adadppolicyhengine_didenterstation could not be located in the dynamic link library iAdCore.dll".