HELP , SQL-AND

Hi everyone:
Here i have a table:
create table cap_binding (
test_ser_id NUMBER(10) not null,
test_cap_id NUMBER(10) not null,
cap_binding_id NUMBER(10) not null,
constraint PK_CAP_BINDING primary key (cap_binding_id)
insert into cap_binding values(64,21,1);
insert into cap_binding values(64,1,2);
insert into cap_binding values(65,1,3);
now, i want to find out the test_ser_id where the corresponding test_cap_id is 21 AND 1 , and in the given
data, the result should be the first two records.
initially, i write: select y.TEST_SER_ID from cap_binding y where y.test_cap_id in (1,21), but the in operator performs OR logic and i get three records.
I cannot figure out how to write the sql. Could anyone help me?
Thanks.

This will work if you have a unique constraint on test_ser_id, test_cap_id:
with t as (
select 1 col1 from dual UNION ALL
select 21 col1 from dual
select * from (
select test_ser_id,
       test_cap_id,
       cap_binding_id,
       COUNT(*) OVER (PARTITION BY test_ser_id) cnt
from cap_binding)
where cnt = (SELECT DISTINCT COUNT(*) FROM t);
TEST_SER_ID            TEST_CAP_ID            CAP_BINDING_ID         CNT                   
64                     21                     1                      2                     
64                     1                      2                      2                     
2 rows selectedI used a table using a with clause to store the values we are looking for (1, 21), but you could use a pipelined function or a variable as well.

Similar Messages

  • Help:SQL and vb

    hello everyone
    i have a project to make and i want to us Visual Basic as language
    i want to execute some queries in my programme and that needs to connect to an ACCESS database
    how can i connect and what's the generale structure to execute queries in a a VB programme
    thanls for help!

    VB? Access?
    You're in the wrong site dude. Go over to Microsoft Land.

  • HELP - SQL and Select and COUNT

    Hi Anyone or Everyone...
    I have created this SQL Statement in java
    SELECT #PART,#PDESC,COUNT(#PART) AS PCOUNT FROM MYLIB WHERE #PART LIKE 'C%' GROUP BY #PART ORDER BY #PART
    this is the error I get....If I remove the Count(#PART) works fine so the column #PDESC is fine....what is wrong with this?? Thanks in advance!!
    [SQL0122] Column #PDESC or expression specified in SELECT list not valid.

    Hi Anyone or Everyone...
    I have created this SQL Statement in java
    SELECT #PART,#PDESC,COUNT(#PART) AS PCOUNT FROM MYLIB
    WHERE #PART LIKE 'C%' GROUP BY #PART ORDER BY #PART
    this is the error I get....If I remove the
    Count(#PART) works fine so the column #PDESC is
    fine....what is wrong with this?? Thanks in advance!!
    [SQL0122] Column #PDESC or expression specified in
    SELECT list not valid.Hi there
    When you are querying on a table, either you have to specify individual elements (columns) of the table or aggregations of the columns. In your case, the elements you are querying are : #PART, #PDESC and PCOUNT. Here, PCount is an aggregation that is calculated form COUNT(#PART) and #PART is also an aggregation as you are grouping the query results by #PART. But, What bout #PDESC? You are querying as individual column only and doing nothing with it. That was the problem.
    Tip: Try adding "GROUP BY #PDESC" or "COUNT(#PDESC)" to your query and I hope it shud work.
    May be It won't solve your problem and give the result that you need, but you will understand the point I am trying to explain.
    Cheers
    -Uday

  • Help!!!: catalog.sql and catproc.sql damage my db

    after running the file my.sql (see below), i encounter some error:
    when i try to edit the table data, the following error displayed:
    ORA-04045 ... SYS.DBMS_OUTPUT
    ORA-06508 ...
    ORA-06512 ...
    ORA-06508 ...
    ORA-06512 ...
    then i go to the package SYS.DBMS_OUTPUT, the status is "invalid", i try to recompile it, the following error displayed:
    ORA-04045 ... SYS.CDC_ALTER_CTABLE_BEFORE
    ORA-06508 ...
    ORA-06512 ...
    ORA-06508 ...
    ORA-06512 ...
    my db works well before running the file my.sql. it seems the execution of catalog.sql and catproc.sql cause the error. i am using 9i, and the document histories show that the catalog.sql and catproc.sql are last updated in Apr,2001.
    my questions are:
    1.with 9i db, do i need to run the two files?
    2.how can i recover my db?(i don't have backup, can i use redoXX.log?)
    ***my.sql***
    connect sys/change_on_install@orcl as sysdba
    @/opt/oracle/rdbms/admin/catalog.sql
    connect sys/change_on_install@orcl as sysdba
    CREATE database mydb
    @/opt/oracle/rdbms/admin/catproc.sql
    ***my.sql***

    how can i get my db work properly just as it was?
    what do you mean by "create database script"?
    Database configuration assistant allows you to create the database template and then save it as a set of scripts that you
    can later customize and run to create the database. If you created your "create database scripts" using this option then
    these scripts automatically run the catproc.sql and catalog.sql scripts along with several other scripts.
    If you use Database configuration assistant to create such a set of DB creation scripts, than look at the
    CreateDBCatalog.sql script, as you can see it runs both the scripts. so, if you do it this way, you do not need to do any
    extra steps (apart from your custom scripts that may be part of your post install steps).
    A sample of such DB creation script will be as below (for your reference):
    ===================================================================
    connect SYS/change_on_install as SYSDBA
    set echo on
    spool /home/oracle/Ora9i/assistants/dbca/logs/CreateDBCatalog.log
    @/home/oracle/Ora9i/rdbms/admin/catalog.sql;
    @/home/oracle/Ora9i/rdbms/admin/catexp7.sql;
    @/home/oracle/Ora9i/rdbms/admin/catblock.sql;
    @/home/oracle/Ora9i/rdbms/admin/catproc.sql;
    @/home/oracle/Ora9i/rdbms/admin/catoctk.sql;
    @/home/oracle/Ora9i/rdbms/admin/owminst.plb;
    connect SYSTEM/manager
    @/home/oracle/Ora9i/sqlplus/admin/pupbld.sql;
    connect SYSTEM/manager
    set echo on
    spool /home/oracle/Ora9i/assistants/dbca/logs/sqlPlusHelp.log
    @/home/oracle/Ora9i/sqlplus/admin/help/hlpbld.sql helpus.sql;
    spool off
    spool off
    exit;
    ===========================================================================

  • New to PL/SQL and need help on check sum using ASCII function

    Hello,
    Need your expertise to help in figuring out how to write
    code to calculate using ASCII function to return value for a character. For example ASCII('A') is 58. I want to do the check sum to sum-up the value for each character in the name. For example 'Jack'
    Appreciate your help.
    CK

    Hi,
    Please post all the technical queries in the respective forums. For more details and answers in SQL and PL/SQL, use the following forum:
    PL/SQL
    Sample PL/SQL code for your requirement:
    -- make sure you have the serveroutput on using command.
    -- set serveroutput on
    DECLARE
    sumval NUMBER(10);
    tempval NUMBER(10);
    colval VARCHAR2(20);
    BEGIN
    SELECT USER INTO colval FROM dual;
    sumval := 0;
    FOR i IN 1..LENGTH(colval)
    LOOP
    SELECT ASCII(SUBSTR(colval,i,1)) INTO tempval FROM dual;
    sumval := sumval+tempval;
    END LOOP;
    DBMS_OUTPUT.PUT_LINE('sum is: '||to_char(sumval));
    END;
    The output of this pl/sql block will be:
    sum is: 397
    Please note: ASCII('A') is 65 and not 58.
    Hope that helps.
    Savitha.
    http://otn.oracle.com/sample_code/content.html

  • Help me clear the OCP sql and pl/sql exam

    can anybody out there guide me how should i proceed with the preparation and what all should i study to clear the SQL and PL/SQL OCP exam.
    thank you all in advance..

    Try going for the Exam Cram. The exam at the end of the book will definitely help a lot. The rest of the book might help, so just give it a try.
    <BLOCKQUOTE><font size="1" face="Verdana, Arial, Helvetica">quote:</font><HR>Originally posted by Nosferatu:
    Hello people...
    I'm taking a preparation course for the Oracle DBA certification exam. I just finished preparing for the first exam -- SQL and PL/SQL.. The book I used for the course Oracle 8i DBA Certification Exam Guide as well as TEach yourself SQL in 21 days and Teach yourself PL/SQL in 21 days...
    I'd say I'm prepared to pass the exam... Before I make my first attempt, I am thinking of going through the Exam Cram for the first exam. However, judging from the reviews on amazon.com, the book doesn't seem to be helpful...
    Anyone have any tips or recommendations before I take the exam? Should I go through the Exam Cram? If not, are there better books to go through for last minute preparations?
    Also, how many questions on the exam and what percentage do I need to pass?
    Any input would be much appreciated... Thanks for ur help!<HR></BLOCKQUOTE>
    null

  • What is the diffrence between package javax.sql and java.sql

    Is javax designed for J2EE?
    And when to use package javax?

    Hi,
    What is the diffrence between package javax.sql and java.sql?The JDBC 2.0 & above API is comprised of two packages:
    1.The java.sql package and
    2.The javax.sql package.
    java.sql provides features mostly related to client
    side database functionalities where as the javax.sql
    package, which adds server-side capabilities.
    You automatically get both packages when you download the JavaTM 2 Platform, Standard Edition, Version 1.4 (J2SETM) or the JavaTM 2, Platform Enterprise Edition, Version 1.3 (J2EETM).
    For further information on this please visit our website at http://java.sun.com/j2se/1.3/docs/guide/jdbc/index.html
    Hope this helps.
    Good Luck.
    Gayam.Srinivasa Reddy
    Developer Technical Support
    Sun Micro Systems
    http://www.sun.com/developers/support/

  • Dynamic SQL and IN CLAUSE from Pro C code

    Hi Guys,
    Tyring to embed sql in Pro C. Here I don't know in hand how many items will be there in the IN Clause of my dynamic sql. Tried this with a loop and then adding actual values to the stement and then executing it. This worked but as this hard coding makes it literal sql and hence hampers performance. Can any one help me with how to put bind variables where we don't know how many of them will be there in a dynamic sql.
    Thanks,

    Dynamic SQL supports user defined types, try passing a collection and using TABLE(CAST(collection)) in the SQL statement.
    In the current approach (creating IN clause at runtime) keep in mind that in a IN clause you can put a maximum of 255 elements...
    Max

  • Dynamic SQL and Sub Query

    I want need to use dynamic SQL, and include a subquery in the where clause.  However, I am getting a syntax error.
    I have code that looks like this.
        SELECT (p_v_sqlobj_select)
            INTO CORRESPONDING FIELDS OF TABLE <matrix>
          FROM (p_v_sqlobj_from)
          WHERE (p_v_sqlobj_where).
    and I pass it the following bold-faced SQL where clause (please ignore whether the statement makes sense and is the best way to do it - this is just to illustrate).   However, it returns an error.
    select tcode from tstc where tcode in <b>( select min( tcode ) as min from tstc )</b>
    Am I correct in concluding that I cannot pass complex statements, or have I just missed something?
    Thanks for any help.

    Hi,
    Please try with order by clause in select statement and also use descending
          select * from (p_table)
                   into corresponding fields of table <ptab>
                  up to p_rows rows
                  order by <fieldname> descending.
    aRs

  • How to execute PL/SQL and branch in APEX 3.0

    I have written an APEX app with the following pages:
    1 - Main page with a "start" button that navigates to page 2
    2 - Page with a Branch "Branch to function returning a page", which has PL/SQL that returns '3' if successful or '4' if there is an error
    3 - Page with HTML to display "Success"
    4 - Page with HTML to display "Error"
    I wrote this as a very simple test to verify how to implement a button to execute a block of PL/SQL and then go to a results page. So, there is almost nothing to it right now - just the four pages described and a small PL/SQL block that actually will always fail because it SELECTs from a table that does not yet exist. The problem is that when I click the button it goes to page 2 properly (the page displays) but I can't tell if the PL/SQL is executed and it does not leave that page. What am I doing wrong? Any help would REALLY be appreciated!

    That's somewhat more complicated. If you create a Page Process (your 'long running process') that fires On Load - After Footer you won't see anything until it's finished.
    So you need an AJAX function to kick off an Application Process and call this AJAX function in the OnLoad of the BODY... And yes, you can show a progress bar or something similar then by checking if your AJAX function is finished yet.
    If you want to go that way you can search this forum on "AJAX ONLOAD" or something similar (or start a new thread).
    Cheers
    Roel

  • Can't find oe_main.sql and HR_main.sql

    I have download and installed latest oracle database successfully (version 11g). When I followed instruction to install sample schema, I couldn't find hr.main.sql and oe_main.sql.
    I only found hr_code.sql in demo/schema/human_resources directory.
    There are a few sql files under order_entry directory like oe_views.sql. But I can't find oe_main.sql.
    I have been struggle with it for a few days. I couldn't find the script file on Internet either. Please help me identify this problem. Thank you very much.

    It's been some time ago but I encounter terrible problems with companion cd now. I have downloaded the zip file with examples already couple times and always there are crc errors in the archive that corrupt the instalation. I hate it... but I need the examples...
    What should I do?
    Download Companion CD from Oracle 10g. This is gonna take another 2 hours with my connection, but let me see...
    Edited by: prdola on Jul 4, 2009 7:26 AM

  • Guide to differences between SQL Server Transact SQL and Oracle PL/SQL

    Does anyone know of a good book (or online guide) that has an in-depth comparison of the differences between SQL Server Transact SQL and Oracle PL/SQL? (Something more than a beginner's guide)

    Hello,
    Below links will surely be helpful
    Discontinued features in SQL 2012
    Depricated features in SQL Server 2012
    Please mark this reply as the answer or vote as helpful, as appropriate, to make it useful for other readers

  • T-SQL and CLR types for return value do not match

    Hi I am trying to create a CLR function to call a webservice, the CLR function return data type is double, whether I try
    to create this as a table valued funcion or a scalar to return a distance travelled value I am receiving the error below. I've tried changing data types around in the CLR side and the SQL side but keep receiving the same error message, any help would be appreciated,
    Thank you,
    [Microsoft.SqlServer.Server.SqlFunction(Name = "DistanceCalc")]
    public static Double DistanceCalc(Double SrcLat, Double SrcLong,
    Double DestLat, Double DestLong)
    MileageWS ws = new MileageWS();
    ws.Url = "http://test.isp.ca/Distance.asmx";
    int intUom = 0; // 0 = Mile, 1 = KM
    RouteType RouteMethod = RouteType.Practical;
    Requester RequestedFrom = Requester.LinkRoute;
    Double distance;
    distance = ws.GetDistanceInfoForLonLat(SrcLat, SrcLong, DestLat, DestLong, intUom, RouteMethod, RequestedFrom);
    return distance;
    CREATE FUNCTION DistanceCalc
    @SrcLat as float, @SrcLong as float,
    @DestLat as float, @DestLong as float
    RETURNS TABLE (Distance float)
    External NAME CLRfunctions.RIFunctions.DistanceCalc
    GO
    Error received when try to Create function ...
    1, Level 16, State 2, Procedure pcMiler, Line 6
    CREATE FUNCTION for "pcMiler" failed because T-SQL and CLR types for return value do not match.

    You defined at table-valued CLR function, but I think you meant to define a scalar CLR function. That might be the cause of the error.
    RETURNS TABLE (Distance float)
    should be
    RETURNS (Distance float)

  • MS SQL and SP2 for WinXP

    I have installed SP2 for windows XP and since then there is a problem with theMS SQL server. The service manager is running but the default port 1433 for sql server doesn,t listen. I have checked it with an active port utility and I 've noticed that the port is closed.
    Due to this fact a connection with the database fails and I keep receiving the error " Cannot a establish a socket for connection ".
    Thank you

    To open ports in the SP2 Windows Firewall just open "Windows Firewall" configuration window from Control Panel, click on the "exceptions" tab, click "add port", give it a name like "sql" and the port you're having trouble with, and then press ok.
    It will appear in the list of services as whatever name you gave it. Make sure it's box is checked, click ok, and you're laughing.
    If case this doesn't work then it's not just the windows firewall blocking the port that's the problem. In this case you can use the same configuration window to just disable windows firewall completely.
    Hope this helps.
    Robin.

  • Get an error for changing the windows authentication mode to the both SQL and windows authentication mode

    I installed the SQL server Express 2008 R2 and then SQL Server Management Studio 2008 R2 . But during the installation, I could not choose the both SQL and windows authentication mode and an error accrued so I did that just with windows authentication mode. 
    Now, I want to change the windows authentication mode account to the SQL authentication mode but it shows me an error which is you do not have permission (Although I am the administrator in windows), what can I do?
    Following steps are the steps that I went but I got an error:
    Server properties >> security >> choose the option of SQL Server and Windows Authentication mode 
    and the error that I got is attached(access is denied)  
    Can you please help me?

    You can change the setting after you gain admin rights to your SQL Server. You don't admin rights automatically, you have to explicitly add yourself during the install
    Here's a guide on how to (re)gain those rights:
    http://v-consult.be/2011/05/26/recover-sa-password-microsoft-sql-server-2008-r2/

Maybe you are looking for

  • I am trying to set up my Yahoo account on an iPhone 4.  Error comes up "Server Unavailable.  Please try again later."

    I am trying to set up my Yahoo account on my new iPhone 4.  An error message comes up "Server Not Available.  Please try again later."  It worked for my gmail account, but not Yahoo.

  • N95 overheating????

    i am having trouble with my n95 v21.0.016 whenever i use an application which is processer heavy (music player , camera but mainly the web browser on sites that are pic heavy)the phone crashes and tries to re-boot, it used to do it first time or i'd

  • Problem in fetching data from 0025IT

    Hello... Here we are working on One Page Profile and when i had made enteries in dev server  for employee first aparaisal in infotype 25 , it has shown one record correctly.But in the table HRP1001 , it created two records with same  dates and rating

  • Printing CD jewel case inserts problem

    In iTunes I am unable to print a CD jewel case insert from the print menu.  Every theme prints out "blurred" except the Large Playlist (black & white) theme.  Has anyone else had this problem?  I have wasted so much ink trying to get my favorite them

  • Can I sync from my iPhone into iTunes to restore library?

    I've had to reinstall my Windows XP laptop that I use for my iPhone and iTunes library. Unfortunately, I lost everything, but I was hoping to restore my iTunes library from my iPhone (seems logical that I should be able to do so). However, I've only