Shorter way to construct sql statement

How can I compact the following sql statement:
select course_c, course_code from idps where
course_c!= 'A' and course_c != 'M' and
course_c != 'O'
I would like to shorten it to something like
select course_c, course_code from idps where
course_c != ('A' and 'M' and 'O')
but it didnt seem to work. I used & and | operators in place of "and" but still doesnt work. What is the easy way so I dont have to type the same variable so many times? Tx for the help.
Enis

You may try :
select course_c, course_code from idps where
course_c not in ('A','M','O')
null

Similar Messages

  • Problem constructing SQL statement dynamically

    One of our system requirements is to generate a report dynamically based on certain search crieria. I implemented the report by creating a dynamic page. The dynamic page receive the search criteria as page parameters.
    Inside the dynamic page, I have an oracle (PL/SQL) section where I built the SQL statement dynamically based on the criteria.
    The opening of the cursor, selecting and displaying of the data works fine - no problem there. The only problem I have is with the construction of the where-clause. It almost seems as if the "if-statements" are completely ignored!!
    Take for example the following extract that makes use of the page parameter "pSDate" that contains the start date:
         whereClause := 'where claimant.kUserName = Claims.fClaimantUserName';
         if rTrim(ltrim(to_char(:pSDate))) = '' then
         whereClause := whereClause||' and Claims.CaptureDate >= to_date('''||:pSDate||''')';
         end if;
    After execution of the above the value of "whereClause" is always "where claimant.kUserName = Claims.fClaimantUserName" ... regardless of whether pSDate is populated or not. In other words, I can't get the "then" part of this statement to execute!
    By printing out the value of pSDate I verified that it indeed contains/not contains a value. I experimented with various functions (ltrim, to_char...) without any success. I even changed the operator in the condition to <> and it still does not work. I find this really weird.
    This is probably something really stupid but being new to PL/SQL I am missing it. Is there anybody out there that knows how I can solve this?

    Tried it and unfortunatly it does not work.
    By specifying the ":" you inform the compiler that it's a parameter to the "dynamic page". As a result it's added as a bind variable of the page. That is visible on the "Customization Form Display Options"-tab.
    The dynamic page is "called" from a stored procedure which "pass" values to these parameters. The passing seems to work fine since, when I "print" the parameter value in the page e.g.
    htp.p('pSDate: '||:pSDate)
    the correct value is displayed.
    The question remains, why does it not work when I use this parameter/bind variable in a condition that forms part of a if-statement?
    I have tried to assign the parameter to a tmp variable of type varchar2(100) just before the if-statement. Using the tmp variable in the if-statement makes no difference.
    Pleeeease can someone help me

  • Urgent ==can somebody help in constructing SQL statement

    Hi,
    I have a table called cgryrel with data and fieldnames like below:
    CGRYREL
    ======
    crpcgnbr crccgnbr
    502 510
    502 511
    502 512
    510 515
    511 516
    512 517
    515 518
    516 519
    517 520
    503 540
    503 541
    I am trying to get a count of rows that are related to crpcgnbr=502.
    To get this information I tried with below SQL statement and ,I get only top level.
    select count(*) from cgryrel where crpcgnbr=502
    result : 3
    I want all rows that are connected to 502?
    can somebody in the forum tell me,what I am doing wrong???
    Thanks
    Jack

    Hi limeybrit9,
    Lluis ...Doesn't that method sort of require that you already know how
    many indentation levels there are if you want all numbers related to
    502?Yes, it does. I already said that in my post. I understand that making a select with, lets say, 100 tables supporting 100 indentation levels might be, at least, ugly to see. But it works and it's fast enough.

  • SQL statement in Drill-Through

    Hi, when you make a drill-through in excel add-in, is some way to get sql statement in excel? without open the EIS console.
    I need this because Drill-through don't work well in a metaoutline with filter IN, so the user can use the query to execute the sql statement directly in the database.

    there is no functionality to get the SQL that is about to be executed in Excel. There is a way to edit the columns or add filtering, but you really don't get the SQL statement.
    You would have to design it yourself. You could grab the sql statement that is generated in the metaoutline and bring it into excel and have a macro that does the replacements.

  • Using SQL Statements in Error Exceptions

    Is there any way to include SQL statements within my catch routines (i.e.
    catch (java.io.IOException ex) {
    System.out.println("An error occurred whilst writing to the message buffer: " + ex);
    #sql { INSERT INTO DEBUG_TBL(CURRENT_DT,PROGRAM_ID,DEBUG__MESG) VALUES (SYSDATE,'TEST',:ex) };
    #sql { COMMIT };
    As it stands I get the following error upon compile:
    Error: Unsupported Java type for host item (at position#1): java.io.IOException
    Any help would be greatly appreciated.
    Thx,
    Boybles
    null

    You can use SQL statements in your catch blocks, just not SQL statements that use Java types which do not map to SQL.
    You cannot pass exceptions from Java to SQL. You can catch a SQL exceptions as a SQLException in Java. However, any exception that is thrown by a Java Stored Procedure (including SQLException) is rendered as an "Uncaught Java exception" in SQL.
    When you receive a SQLException there is information about the originator, the error message, etc. in the exception object. See:
    http://technet.oracle.com/docs/products/oracle8i/doc_library/817_doc/java.817/a83723/keyprog5.htm#1004462
    While you cannot insert a Java exception per se into a table, you can extract the message string(s)/code and insert that in a table.

  • Retrieve Crystal SQL statements without first submitting parameter values?

    Hi,
    I am retrieving SQL statements for Crystal reports without issue, but a large number of our reports have parameters and for these the following error is thrown when I try to retrieve the SQL statement via RAS using getSQLStatement():
    com.crystaldecisions.sdk.occa.report.lib.ReportSDKServerException: Missing parameter values.---- Error code:-2147217394 Error code name:missingParameterValueError
    I have a large number of reports I'd like to pull SQL for, so it's not feasible to have my script push parameter values to each and every report.  Is there a way to retrieve SQL statements without first pushing parameter values?
    Thanks

    Hello Jeremy.
    I found a Knowledge Base article that deals with the "Error code:-2147217394 Error code name:missingParameterValueError" error that you mention.  Perhaps you could take a look at the following KBase Article in the Service MarketPlace and see if any of it applies to your situation:
    KBase number: 1420593
    I also found KBase number "1420501 - Report parameters ignored when set by Java post processing code" that seems to deal with the same problem.
    Regards.
    - Robert

  • Cost of sql statement

    Hi all.
    Database is oracle 9i server ibm-aix
    Is there any way to analyze sql statement cost before apply it in to production system.
    Like developers wrote some sql statements ..now before release them in to production ..i need to check
    these..and take cost of the sql statement …like these are good one or badly written ... how to check it …any way any tool ..?
    any idea...

    Database is oracle 9i server ibm-aix
    Is there any way to analyze sql statement cost before apply it in to production system. Run the query on your dev/test systems?
    Run an explain plan?
    Read Jonathan Lewis' book on Cost Based Oracle - the Fundamentals?
    Christopher Lawson's book? Cary Millsap's book? Gaja Krishna Vaidyanatha & al's book?
    Like developers wrote some sql statements ..now before release them in to production ..i need to check
    these..and take cost of the sql statement …like these are good one or badly written ... how to check it …any way any tool ..?There's an excellent tool - with proper use, there's virtually no problem it cannot
    solve in an Oracle system (or any other one for that matter!), it's called
    a brain - with knowledge of how Oracle works and a bit of study, it
    really is pretty cool.
    HTH,
    Paul...
    When asking database related questions, please give other posters
    some clues, like OS (with version), version of Oracle being used and DDL.
    Other trivia such as CPU, RAM + Disk configuration might also be useful.
    The exact text and/or number of error messages is useful (!= "it didn't work!"). Thanks.
    Furthermore, as a courtesy to those who spend time analysing and attempting to help,
    please do not top post and do try to trim your replies!

  • Parsing a sql statement without executing it

    Hello everybody,
    I'd like to know a way of parsing sql statements in order to validate them, thus I'd get the error messages beforehand without executing them.
    Here we have the hard task of analyzing several sql scripts and then sending corrections to the development team and thirty party companies before applying them in our production databases. I'm willing to create a web/pl sql program that does such hard task, at least a program that identify basic errors such as missing table owner, non-existing tables, sintax errors and so on...
    Any tip will be of great help!
    Thanks in advance.

    Doing an explain plan will parse the statement prior to calculating the plan. Eg:
    SQL> explain plan for select * dual;
    explain plan for select * dual
    ERROR at line 1:
    ORA-00923: FROM keyword not found where expectedEven easier if you use Toad or some other GUI front end where the explain plan is a click of a button (or a keyboard shortcut) away!

  • Retrieve SQL Statement from Transaction_ID

    Hi,
    Is there any way to retrieve SQL Statement for LOCAL/SOURCE_TRANSACTION_ID listed in DBA_APPLY_ERROR ?
    Database version: 11.2.0.2
    Thanks,
    BSS.

    Hi,
    I am not sure if you can get that sql_id but if you use LOGMINER can get the SQL Text (ie.V$LOGMNR_CONTENTS.SQL_REDO) for a given transaction id.
    hth,
    Pradeep

  • Short dump in SAP R/3: SQL statement buffer overflow?

    Hello,
    I hope someone can help us with the following problem:
    A short dump in SAP R/3 (DBIF_RSQL_INVALID_RSQL, CX_SY_OPEN_SQL_DB)
    occurred during a delta load, which worked fine for several month.
    The custom code crashes at a FETCH NEXT CURSOR statement.
    I assume, it might be a SQL statement buffer overflow in SAP R/3?
    The problem can be reproduced by RSA3, and is therefore not time-dependent.
    The problem did not occur before or on the quality assurance system.
    Cursor code:
          Read all entries since last transfer (delta mechanism)
            OPEN CURSOR WITH HOLD s_cursor FOR
              SELECT * FROM ekko
                WHERE ebeln IN t_selopt_ekko.
    t_selopt_ekko has up to 60.000 data sets, which worked fine in the past.
    It is very likely that the amount of data during the first crash did not exceed this.
    SQL-Trace of RSA3 call:
    It seems that 25150 data set can be processed via fetch before the short dump occurs
    After that object SNAP is written:
    "...DBIF_RSQL_INVALID_RSQL...dynpen00 + 0xab0 at dymain.c:1645 dw.sapP82_D82
    Thdyn...Report für den Extraktoraufruf...I_T_FIELDS...Table IT_43[16x60]TH058FUNCTION=
    RSA3_GET_DATA_SIMPLEDATA=S_S_IF_SIMPLE-T_FIELDSTH100...shmRefCount  = 1...
    ...> 1st level extension part <...isUsed       = 1...isCtfyAble   = 1...> Shareable Table Header Data
    <...tabi         = Not allo......S_CURSORL...SAPLRSA3...LRSA3U06...SAPLRSA3...
    During dump creation the following occurs:
    "...SAPLSPIAGENTCW...CX_DYNAMIC_CHECK=...CRSFH...BALMSGHNDL...
    DBIF_RSQL_INVALID_RSQL...DBIF_RSQL_INVALID_RSQL...DB_ERR_RSQL_00013...
    INCL_ABAP_ERROR...DBIF_INCL_INTERNAL_ERROR...INCL_INTERNAL_ERROR...
    GENERAL_EXC_WITHOUT_RAISING...INCL_SEND_TO_ABAP...INCL_SEARCH_HINTS...
    INCL_SEND_TO_SAP...GENERAL_EXC_WITHOUT_RAISING...GENERAL_ENVIRONMENT...
    GENERAL_TRANSACTION...GENERAL_INFO...GENERAL_INFO_INTERNAL...
    DBIF_INCL_INTERNAL_CALL_CODE..."
    Basis says, that the Oracle data base works fine. The problem seems to be a SAP R/3 buffer.
    Does anyone had a similar problem or knows where such a buffer might be or how it can be enlarged?
    Best regards
    Thomas
    P.S.
    Found a thread that contains part of the dump message "dynpen00 + 0xab0 at dymain.c:1645":
    Thread: dump giving by std prg contains -> seems not to be helpful
    Found a similar thread:
    Thread: Short dump in RSA3 --Z Data Source -> table space or somting else?
    Edited by: Thomas Köpp on Apr 1, 2009 11:39 AM

    Hi Thomas,
          Its due to different field length.
    Just check it out in code after FETCH NEXT CURSOR what internal table you have mention.
    that internal table shoul deffined by taking refrence of ekko, because your code is
    OPEN CURSOR WITH HOLD s_cursor FOR
    SELECT * FROM ekko
    WHERE ebeln IN t_selopt_ekko.
    hope you got solution.
    Regards,

  • The best way to do paging and get total rows count given a sql statement

    Hi,
    Just got a quick question.... what is the best way to do paging as well as the total rows count given by a sql statement.
    e.g. "select * from emp"
    1. I need to know the total row count for this statement.
    2. I also need to do a 10 rows per page....
    Is there a way to do it in a SINGLE statement for best performance?
    Thanks experts.

    Sounds more like a "formatting" problem...
    If Sql*plus is your reporting tool, check out the guide:
    http://download-west.oracle.com/docs/cd/B10501_01/server.920/a90842/toc.htm

  • Is there a way to excute a Native SQL statements simply?

    I heard that there is a standard transaction code to test a Native SQL statement.
    Please let me know if you are know that.
    Thank you!

    hi,
    Try this in SE38.
    data: itab type mara-matnr.
    exec sql performing a1.
    select matnr from mara into :itab
    endexec.
    form a1.
    write:/ itab.
    endform.
    Note: The sql stmt with in exec sql  and endexec
    'll not be checked.
    Thanks.
    Arunprasad.P

  • Using a string variable as a query SQL statement

    I want to construct a custom SQL statement in a string var, then use that var in the cfquery statement.  What is the proper syntax?  Here is my feeble attempt:
      <cffunction ...>
      <cfset var sql_txt="">
            <cfquery name="qSBJs" datasource="cfBAA_odbc">
                "#sql_txt#"
            </cfquery>
        <cfreturn qSBJs>
    I've tried using no " or # or just # or just " but nothing works.
    what about:
            <cfquery name="qSBJs" datasource="cfBAA_odbc" sql="#sql_txt#">
            </cfquery>
    nope.  I wish there was a sql property I could fill *before* the execution of the query.  Any suggestions?

    Hi Adam, and/or anyone who may have a few minutes to check this... I got the following code to work.  It calls the getSBJs function from Flash Builder 4.  I get the correct result set back.  Long table names are replaced with short abreviations.  Note that some local vars are declared but not used in the following example. I will use them in the future versions of this same code.  Since I will in the future, like a donkey, mindlessly use this same method for all my queries, it would be much appreciated if I could get a guru to check this code for:
    -Pure idiocy
    -Mild insanity
    -SQL injection vulnerability
    -Memory leakage
    -Scope dangers
    (ignore emoticons, see the underlying text)
        <cffunction name="AbrvTblNms" output="false" returntype="string" >
            <cfargument name="txt" type="string" required="true" />
            <cfset var qAbrvs="">
            <cfset var output_str="#ARGUMENTS.txt#">
            <cfquery name="qAbrvs" datasource="cfBAA_odbc" result="rsltAbrvs">
                SELECT TBL_NM, ABRV FROM BAA_TBL_ABRV ORDER BY 1
            </cfquery>
        <cfloop query="qAbrvs">
                <cfset output_str = Replace(output_str, '[' & qAbrvs.TBL_NM & ']', qAbrvs.ABRV, "ALL")>
        </cfloop>
            <cfreturn output_str>
        </cffunction>
        <!--- Fetch a list photo subjects whose records contain the given search word(s) --->
        <cffunction name="getSBJs" output="false" access="remote" returntype="any" >
            <cfargument name="srch_val" type="string" required="true" />
            <cfset var qSBJs="">
            <cfset var sql_txt="">
            <cfset var whr=""> 
            <cfset var b=False>
            <cfset var in_txt="">
            <cfset var fm_dt="">
            <cfset var to_dt="">
            <cfset var on_dt="">
            <cfset var pht="">
            <cfset var srch_str="">
            <cfset var srch_trm="">
            <!--- Transfer the srch_val to a local variable for further manipulation --->
            <cfset srch_str = "#ARGUMENTS.srch_val#">
            <!---
                An empty search term argument is handled by the BAA FlashBuilder front end.  We test for it again here,
                and substitute a dummy value, in case this function is called by something other than the intended
                FlashBuilder front end, and that front end doesn't protect us from an empty search term argument.
                Remember that we must still "hand back" a valid query structure to avoid causing a data type error
                in the calling function, so we search for a dummy value that will allow the query to proceed but is
                guaranteed to return an empty result set.  If the srch_val argument is not empty, transfer the value of
                the srch_str local variable to the srch_trm local variable.
            --->
            <cfif Not (Len(srch_str))>
                <cfset srch_str = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX">
            </cfif>
            <cfset srch_trm = "#srch_str#">
            <cfset sql_txt =
                "SELECT DISTINCT
                  [BAA_SBJ].SRC_SYS_NM, [BAA_SBJ].SRC_SYS_GUID, [BAA_SBJ].OBJ_GUID, [BAA_SBJ].SBJ_NM, [BAA_SBJ].SBJ_DOB, [BAA_SBJ].SBJ_ID, [BAA_SBJ].NOTE, [BAA_SBJ].CDT, [BAA_SBJ].CTM, [BAA_SBJ].CBY, [BAA_SBJ].MDT, [BAA_SBJ].MTM, [BAA_SBJ].MBY
                FROM
                  BAA_SBJ [BAA_SBJ]
                  LEFT JOIN BAA_SES [BAA_SES] ON [BAA_SES].PAR_GUID = [BAA_SBJ].OBJ_GUID
                  LEFT JOIN BAA_IMG [BAA_IMG] ON [BAA_IMG].PAR_GUID = [BAA_SES].OBJ_GUID
                WHERE [WHERE_CLAUSE] ORDER BY [BAA_SBJ].SBJ_NM">
            <cfset whr = "([BAA_SBJ].SBJ_NM CONTAINING TRIM( rm_srch_trm1 ) OR " &
                    "[BAA_SBJ].NOTE CONTAINING TRIM(:prm_srch_trm2 ) OR " &
                    "[BAA_SBJ].SBJ_DOB CONTAINING TRIM(:prm_srch_trm3 ) OR " &
                    "[BAA_SES].SES_TYP CONTAINING TRIM(:prm_srch_trm4 ) OR " &
                    "[BAA_SES].NOTE CONTAINING TRIM(:prm_srch_trm5 ) OR " &
                    "[BAA_IMG].NOTE CONTAINING TRIM(:prm_srch_trm6 ))">
            <cfset sql_txt = Replace(sql_txt,"[WHERE_CLAUSE]", "#whr#", "ALL")>
            <cfset sql_txt = AbrvTblNms(sql_txt)>
        <!--- Through experimentation, I learned that each occurance of a param must be uniquely named.
                  It would be very handy, if the param value was applied to *all* occurances of the param.
                        That way, I could get away with using one .addParam line instead of 6 --->
            <cfscript>
            queryService = new query();
            queryService.setDatasource("cfBAA_odbc");
            queryService.setName("qSBJs");
            queryService.setAttributes(sql="#sql_txt#");
            queryService.addParam(name="prm_srch_trm1", value="#srch_trm#", cfsqltype="VARCHAR");
            queryService.addParam(name="prm_srch_trm2", value="#srch_trm#", cfsqltype="VARCHAR");
            queryService.addParam(name="prm_srch_trm3", value="#srch_trm#", cfsqltype="VARCHAR");
            queryService.addParam(name="prm_srch_trm4", value="#srch_trm#", cfsqltype="VARCHAR");
            queryService.addParam(name="prm_srch_trm5", value="#srch_trm#", cfsqltype="VARCHAR");
            queryService.addParam(name="prm_srch_trm6", value="#srch_trm#", cfsqltype="VARCHAR");
            result = queryService.execute();
            qSBJs = result.getResult();
            </cfscript>       
            <!--- <cfquery name="qSBJs" datasource="cfBAA_odbc">
            </cffunction>
            </cfquery> --->
            <cfreturn qSBJs>
        </cffunction>
    THANKS TO ADAM AND DAN FOR HELPIMG ME GET THIS FAR!  Now, don't let me embarass you by doing something dum and giving you "credit", if you see me doing something dum above.  Thanks!

  • Can I change sql statement for some query runtime?

    Hi All!
    The problem that I have to implement report with query like this: select * from a where b in (?,?,?). The number of parameters depends on user choice. On the client side it will be a list of check boxes. Is there any way to implement such report? I can see just one way so far - to modify sql statement runtime.
    Thanks!

    hello,
    create a user-parameter myListe or myWhere (wee examples below) and change your query to
    select ... from ... where b in (&<myList>)
    or even better
    select ... from ... &<myWhere>
    now you can pass in the constructed list or where clause. you can also construct the values in the afterParameterform-Trigger
    regards,
    philipp

  • How can I execute Dynamic SQL statement in Forms?

    Hi All,
    I have to execute dynamic SQL statement from Forms
    Below statement I have to execute
    "EXECUTE IMMEDIATE v_stmt INTO v_return;".
    Googled for the same got results saying, Better use Database function or procedures to execute these Dynamic Statements but We want to execute in forms only.
    Can any one help me..
    Thanks,
    Madhu

    So in short you are trading code obfuscation for maintainability and the ability to share code between tools? If from somewhere else you need a procedure already implemented in database PL/SQL (and now ported to forms) this would mean you'd need to implement it in every other tool. In times where you might want to integrate your forms with $other_technology and putting stuff on the database is the first step to share functionality you just go the opposite way? And all that because someone is afraid that somebody might steal your source code? I am sorry to be blunt, but this is just plain stupid.
    Leaving aside that some things like Analytic Functions, Bulk processing or execute immediate are not even available in forms your software consists of how many LOC? How long does it take to bring a new developer up to speed with your source code? Imagine how long that would take for a developer who doesn't have coleagues who know their way around.
    And just so you know: I work for a ISV selling a closed-source product as well. We have 200+ customers all over the planet. We are well aware that wrapped packages can be reverse engineered. The premise is: stored procedures can be reused in every tool we have, if it makes sense to put stuff on the database by all means do it. If someone would want to reverse engineer our software I'd wish him good luck as some parts are implemented in such a hilarious complicated way I have troubles understanding them (and quite frankly I refuse to understand certain parts, but that's another story). I do work for almost 10 years for that ISV.
    In any case the possible solutions have already been mentioned: you have exec_sql, create_group_from_query and forms_ddl to execute dynamic SQL in forms whereas forms_ddl is a one way street and most certainly not the thing you need or want. Take a look at the documentation for the other 2 things.
    cheers

Maybe you are looking for

  • New Macbook, bringing in for repair

    Hi, My Macbook is less than a month old and I'm having problems with it (sometimes doesn't turn on, potential logic board problems etc) I'm planning to take it to a Authorized Apple Servicer, but would it cause any problems that my HD is partionally

  • I went to bed and in the next morning my mac just didnt turn on

    I used to leave my macbook black downloading a lot of stuff in the night, so i leave it downloading a lot of programs and i went to sleep, in the next morning i woke up and i realized that my mac didnt turn on. why???? I went to the mac workshop and

  • Non cumulative key figure and fiscal period 13

    Hi, We have defined a non cumulative key figure. In the cube, the non cumulative characteristic is the fiscal period (0FISCPER). This non cumulative key figure works fine from period 1 to 12, but displays nothing for period 13 (and 14, 15, 16). We wa

  • How to close open cursors in a forms app

    All, I'm not a forms developer. I'm a database administrator so I'm asking this question from that perspective. I know nothing about forms development. We have several forms applications that appear to hold many SELECT cursors open when they run. I'v

  • How to create an audit trail report in SAPB12007

    Hello, I been looking for some ways to make an Audit Trail Report for our System Audit. Could anyone help me with this? I would like to generate a report that will list all the BP and ITem master data. the date its created and modified and if its mod