Add string  in sql statement

hi
i want to add one string in a output of the sqlstatemnt.below is my sql statement
select
XMLELEMENT ("DATABASE_OBJECTS",xmlagg(
XMLFOREST (owner,
object_type,
object_name,
object_user_name,
physical_name
).getClobVal()
FROM xxhex_custom_objects;
the string whic i want to add in output is:
'<?xml version="1.0" encoding="UTF-8"?>'.
i tried the below query but it is giving me an error.
select '<?xml version="1.0" encoding="UTF-8"?>',
XMLELEMENT ("DATABASE_OBJECTS",xmlagg(
XMLFOREST (owner,
object_type,
object_name,
object_user_name,
physical_name
).getClobVal()
FROM xxhex_custom_objects;

>
i want to add one string in a output of the sqlstatemnt.below is my sql statement
select
XMLELEMENT ("DATABASE_OBJECTS",xmlagg(
XMLFOREST (owner,
object_type,
object_name,
object_user_name,
physical_name
).getClobVal()
FROM xxhex_custom_objects;
the string whic i want to add in output is:
'<?xml version="1.0" encoding="UTF-8"?>'.
>
Unless the result of your XMLELEMENT query is valid XML adding that string won't accomplish anything. The result will NOT be valid XML.
See my replies in this thread
Re: expression must have same datatype
If your query result is a string then you use || to concatenate strings so just do that in your query.
SELECT 'abc' || 'def' FROM DUAL;
select '<?xml version="1.0" encoding="UTF-8"?>' || XMLELEMENT . . .

Similar Messages

  • String in SQL Statement

    Hello All!
    Please help me how I can put in SQL statement string.
    For now, I have in data in field 9985. I need 99.85.
    Thank you in advance.

    Hi,
    In general, where do you want the '.' to go?
    After the first 2 characters?
    Before the last 2 characters?
    Directly in the middle (if possible)?
    Something else?
    This expression adds a '.' before the last 2 charachters:
    REGEXP_REPLACE ( s,
                   , '(..$)'    -- '.' means "any character" here
                   , '.\1'      -- '.' has no special meaning here
                   )If s is only 1 character long, the expression above will not add a '.'.

  • Using a string as sql statement in PL/SQL

    Hi there,
    I have a function which returns a part of a query depending on some conditions.
    FUNCTION GET_REPORT_TYPE(in_report_type IN NUMBER)
    RETURN VARCHAR2
    AS
    reporttype varchar2(50);
    BEGIN
    CASE in_report_type
    WHEN 0 THEN
    reporttype := 'C1.DATE_CLOSED != NULL';
    WHEN 1 THEN
    reporttype := 'C1.DATE_CLOSED := NULL';
    WHEN 2 THEN
    reporttype := '';
    END CASE;
    RETURN reporttype;
    END GET_REPORT_TYPE;
    Now in my procedure I would like to put this returned value in an AND clause of my query:
    procedure get_cpl(p_cursor OUT rst_cur, searchcode IN VARCHAR2, reporttype IN VARCHAR2)
    is
    begin
    open p_cursor for
    SELECT C1.CIPIDI_NR,
    C1.CIPIDI_NAME,
    C2.TEAM_MEMBER
    FROM TBL_CIPIDI C1, TBL_TEAM_MEMBERS C2
    WHERE C1.CIPIDI_NR LIKE searchcode
    AND C1.CIPIDI_NR = C2.CIPIDI_NR (+);
    AND reporttype; -- HERE I WOULD LIKE TO USE WHAT THE FUNCTIONS RETURNED
    end get_cpl;
    How can I can I use reporttype to function as a part of the query? Thanks a lot
    Chris

    scott@ORA92> -- test data:
    scott@ORA92> SELECT * FROM tbl_cipidi
      2  /
    CIPIDI_NR CIPIDI_NAME DATE_CLOS
             1 name1       30-MAY-05
             1 name2
    scott@ORA92> SELECT * FROM tbl_team_members
      2  /
    CIPIDI_NR TEAM_MEMBER
             1 team1
    scott@ORA92> -- function:
    scott@ORA92> CREATE OR REPLACE FUNCTION GET_REPORT_TYPE
      2    (in_report_type IN NUMBER)
      3    RETURN            VARCHAR2
      4  AS
      5    reporttype       varchar2(50);
      6  BEGIN
      7    CASE in_report_type
      8        WHEN 0 THEN reporttype := 'C1.DATE_CLOSED IS NOT NULL';
      9        WHEN 1 THEN reporttype := 'C1.DATE_CLOSED IS NULL';
    10        ELSE reporttype := '1 = 1';
    11    END CASE;
    12    RETURN reporttype;
    13  END GET_REPORT_TYPE;
    14  /
    Function created.
    scott@ORA92> SHOW ERRORS
    No errors.
    scott@ORA92> -- packaged with procedure:
    scott@ORA92> CREATE OR REPLACE PACKAGE your_pkg
      2  AS
      3    TYPE rst_cur IS REF CURSOR;
      4    procedure get_cpl
      5        (p_cursor   OUT rst_cur,
      6         searchcode IN  VARCHAR2,
      7         reporttype IN  VARCHAR2);
      8  END your_pkg;
      9  /
    Package created.
    scott@ORA92> SHOW ERRORS
    No errors.
    scott@ORA92> CREATE OR REPLACE PACKAGE BODY your_pkg
      2  AS
      3    procedure get_cpl
      4        (p_cursor   OUT rst_cur,
      5         searchcode IN  VARCHAR2,
      6         reporttype IN  VARCHAR2)
      7    is
      8    begin
      9        OPEN p_cursor FOR
    10        'SELECT C1.CIPIDI_NR,
    11             C1.CIPIDI_NAME,
    12             C2.TEAM_MEMBER
    13         FROM      TBL_CIPIDI C1, TBL_TEAM_MEMBERS C2
    14         WHERE  C1.CIPIDI_NR = :b_searchcode
    15         AND      C1.CIPIDI_NR = C2.CIPIDI_NR (+)
    16         AND ' || get_report_type (reporttype)
    17        USING searchcode;
    18    end get_cpl;
    19  END your_pkg;
    20  /
    Package body created.
    scott@ORA92> SHOW ERRORS
    No errors.
    scott@ORA92> -- tests:
    scott@ORA92> VARIABLE g_ref REFCURSOR
    scott@ORA92> SET AUTOPRINT ON
    scott@ORA92> EXECUTE your_pkg.get_cpl (:g_ref, 1, 0)
    PL/SQL procedure successfully completed.
    CIPIDI_NR CIPIDI_NAME TEAM_MEMBER
             1 name1       team1
    scott@ORA92> EXECUTE your_pkg.get_cpl (:g_ref, 1, 1)
    PL/SQL procedure successfully completed.
    CIPIDI_NR CIPIDI_NAME TEAM_MEMBER
             1 name2       team1
    scott@ORA92> EXECUTE your_pkg.get_cpl (:g_ref, 1, 2)
    PL/SQL procedure successfully completed.
    CIPIDI_NR CIPIDI_NAME TEAM_MEMBER
             1 name1       team1
             1 name2       team1
    scott@ORA92>

  • Add hour in sql statement

    I need to add hour in a timestamp field. How can i do that?

    Here's an example
    select to_char(sysdate,'hh24:mi:ss') Curr_TIme,
    to_char(sysdate + (60/1440) , 'hh24:mi:ss') Curr_Time_Add_1 from DUAL
    CURR_TIM CURR_TIM
    07:17:53 08:17:53
    I need to add hour in a timestamp field. How can i do that?

  • Java.beans.Statement & java.sql.Statement

    My old code from jdk1.3.1 throws the ambiguous class thingie-mo-bob. Why did they implement the new java.beans.Statement, and is there anyway to make it default to the old java.sql.Statement without having to go through all the old code and add import java.sql.Statement. I have like 200 jsp files 'n it will take a loooong time!
    Pete

    There r two ways to do this.
    (i) One is Implement the java.sql.Statement
    like
    package java.beans;
    public interface Statement implements
    java.sql.Statement {
    }What? Are you suggesting he edit the source code for java.beans.Statement and make it implement java.sql.Statement?? I would most certainly not suggest that solution- beside violating the licensing agreement, it has troubling consequences since you are basically redefining the structure of a class in a way that makes no functional sense- that is, there is no reason for java.beans.Statement to implement methods like getConnection() and the other signatures of java.sql.Statement.
    I'm not sure if I'm reading your response correctly or not, but I would definitely not refactor java.beans.Statement just to get this problem solved with out editing files ... ... since java.sql.Statement is used so widely, perhaps they should have considered a different name for java.beans.Statement , although you hate to base a name off of what's going to cause the least problems, rather then what makes the most sense ... ... any way, I guess it doesn't matter now: the name has been selected .... I'd be interested to hear how you solved the problem.

  • 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!

  • Multiple Oracle SQL statements in one Add Command

    I am creating a report that needs a bunch of processing(SQL DDL statements) before the final select statement is generated for the report.
    I am connecting to Oracle database however Crystal Report only allows me to give one SQL statement in one Add Command.
    Is there a way to give multiple statements in one "Add Command" for the report ?
    Thanks.

    you can add more than one "Add Command" in the same report, and you can also treat them as views or table, so you can link them to each others and so on
    good luck

  • Connecting strings for execution as SQL-Statement

    Hello to all.
    I've the problem, that I want to write a package which handels occuring erros as far as possible automatically.
    One part is to recompile invalid objects.
    I can find all these objects by useing the following cursor:
    CURSOR curInvalidObjects
    IS SELECT OBJECT_TYPE, OWNER, OBJECT_NAME
              from dba_objects a
              where STATUS = 'INVALID' and
              OWNER = 'BESECKE' AND
              OBJECT_TYPE in ( 'PACKAGE BODY',
    'PACKAGE', 'FUNCTION', 'PROCEDURE',
    'TRIGGER', 'VIEW' )
              order by OWNER, OBJECT_TYPE, OBJECT_NAME;
    After opening the cursor I can go trough the records and recompile the objects with something like this:
    alter || recInvalidObjects.OBJECT_TYPE || ' '
    || recInvalidObjects.OWNER || '.' ||
    recInvalidObjects.OBJECT_NAME || compile;
    But that does not work. In this way I can't get any executable SQL-Statement. It just becomes a string, but it's not executable.
    I think it's a simple problem, but I tried to find anything about executable stings in the documentation I have, and I could not find anything. So can anybody give me a short hint, how to create an executable statement?
    Thanks a lot.
    Susanne Saalmann

    If you just recompile without taking the correct order of compilation into account, you will have to run your statement a couple of times. This script solves that:
    SET HEADING OFF
    SET FEEDBACK OFF
    SET PAGES 9999
    SET TIMING OFF
    SET TERMOUT ON
    COLUMN noprn NOPRINT
    SPOOL comp.sql
    SELECT 'ALTER '||
    DECODE( o.object_type, 'PACKAGE BODY', 'PACKAGE', o.object_type)||
    ' '||decode(o.object_type,'JAVA CLASS','"',null)||
    o.object_name || decode(o.object_type,'JAVA CLASS','"',null)||
    ' COMPILE '||
    DECODE( o.object_type, 'PACKAGE BODY', 'BODY;', ';'),
    COUNT( d.name ) noprn
    FROM user_objects o,
    user_dependencies d
    WHERE o.object_name = d.referenced_name(+)
    AND o.object_type = d.referenced_type(+)
    AND o.status = 'INVALID'
    GROUP BY o.object_name, o.object_type
    ORDER BY noprn DESC
    SPOOL OFF
    SET HEADING ON
    SET FEEDBACK ON
    SET PAGES 14
    START comp.sql
    SHOW USER
    SELECT object_type, status, count(*)
    FROM user_objects
    GROUP BY object_type, status

  • Add sql statements in SGA

    select a.address address,
    s.hash_value hash_value,
    s.piece piece,
    s.sql_text sql_text,
    u.username parsing_user_id,
    c.username parsing_schema_id
    from v$sqlarea a,
    v$sqltext_with_newlines s,
    dba_users u,
    dba_users c
    where a.address=s.address
    and a.hash_value=s.hash_value
    and a.parsing_user_id=u.user_id
    and a.parsing_schema_id=c.user_id
    and exists (select 'x'
    from v$sqltext_with_newlines x
    where x.address=a.address
    and x.hash_value=a.hash_value
    and upper(x.sql_text) like '%UNION%')
    order by 1,2,3
    On executing the above statement the server display list of sqltext present in sga. We know that the server first search for the record in sga and if it is not
    present in SGA it searches in data files.
    My question is ,adding all the sql statements in sga manually is advisable? will that improve the performance?

    Vinodh2 wrote:
    In production the users uses some sql statement frequently. So those statements should be in the sga for better performance. The dbms package said by you takes object as input. What is object here?
    Did you check the last line I pasted from document?
    The value for this identifier is the concatenation of the address and hash_value columns from the v$sqlarea view.Each SQL in SQL AREA has a hash_value to identify it. You can use this hash value to decide which SQL want to keep in shared pool.
    Having Dynamic sql statements(records fetched based on varying filter condtion) called from interfaces will not help.
    But having static sql statements helps.
    In that case how to include those sql.Like said, you are introducing some more problems instead of any real gain by trying to micro manage how shared pool work. You should let Oracle take care it with it's own algorithm. Unless some rare cases, that you have limited shared pool and super busy system you want to pin some SQL in the shared pool with provide package.

  • Can someone help me correct this sql statement in a jsp page?

    ive been getting the java.sql.SQLException: Incorrect syntax error for one of my sql nested statements. i cant seem to find similar egs online, so reckon if anyone here could help, really appreciate it.
    as im putting the nested sql in jsp page, it has to be with lots of " " n crap. very confusing if there are nested.
    heres the sql statement without those "" that i want to use:
    select top 5 * from(
    select top+"'"+offset+"'"+" * from prod where cat=" +"'" cat "'"+"
    )order by prodID desc
    when i put this in my jsp pg, i had to add "" to become:
    String sql = "select top 5 * from("+"select top"+"'"+offset+"'"+" * from prod where cat=" +"'" +cat+ "'"+")order by prodID desc";cat=" +"'" cat "'"+")order by prodID desc";
    all those "" are confusing me to no end, so i cant figure out what should be the correct syntax. the error says the syntax error is near the offset.

    If offset is, say, 10, and cat is, say, "new", then it looks like you're going to produce the SQL:
    select top 5 * from(
      select top '10' * from prod where cat='new'
    )order by prodID descThat looks exactly like incorrect syntax to me... top almost certainly can't handle a string literal as its operand... you almost certainly would want "top 10" instead of "top '10'"...
    If you use PreparedStatement, you don't have to remember what you quote and what you don't and you can have your SQL in a single static final string to boot...

  • Adding a field to an sql statement in Oracle Reports error ORA-00933

    We have been requested to add a field that already exists in the table referred to by the sql statement in Oracle Reports Builder. The report was set up by a consultant about 3 yrs ago and we don't really have much skill in this area. What is happening when I try to modify the SQL statement, either adding a field or deleting a field to the SELECT statement, causes an error message preventing the statement from being saved. The only way out of the error message is to click Cancel. The error message is
    ORA-00933:SQL command not properly ended
    ORDER BY Program ==> NAME
    Even adding or deleting a space anywhere in the SQL statement causes the error (not adding any new fields). A coworker found that if we comment out the ORDER BY, the statement will accept the new field in the SELECT section, however then we lose the order by functionality. I would like to add one additional field before the FROM. Not sure if any additional data are needed. Thank you.
    SELECT p.person_uid PIDM_KEY, p.id_number ID,
                   p.full_name_lfmi name,            
                    p.BIRTH_DATE, p.GENDER Sex,
                    Decode(a.residency,'D',p.Primary_ethnicity,'F')  Ethn,
                    a.academic_period TERM,        
                    CASE WHEN :p_group_by = 'PROGRAM' THEN a.program
                                 ELSE ' '
                    END AS Program,
                    a.COLLEGE, a.degree, a.major, ' ' rule,
                    a.STUDENT_POPULATION,a.STUDENT_LEVEL,    a.application_status Status,  a.application_status_date app_sts_dte,
                    ad.decision_date1 Last_Dec_Date,
                    ad.decision1||' '||ad.decision2||' '|| ad.decision3||' '|| ad.decision4||' '|| ad.decision5 Decisions,
                    /*  Deposit Date uses the last term entered in :p_term parameter string */
                    (SELECT MAX(deposit_effective_date) FROM usf_as_deposit WHERE account_uid = a.person_uid &term_clause group by account_uid)   AS "DEPOSIT DATE",     
                    ph.phone as PHONE,
                    CASE WHEN PS.FIRST_CONTACT IN ('NET','PAP','COM','COP') THEN PS.First_Contact
                     ELSE CASE WHEN ps.latest_contact IN ('NET','PAP','COM','COP') THEN PS.Latest_Contact
                                ELSE '  '
                                END
                    END AS FIRST_CONTACT,
                    DECODE(:p_address,'Y',REPLACE(adr.street1||' '||adr.street2||' '||adr.street3||' '||adr.city||','||adr.state||' '||adr.nation||' '||adr.zip,'  ',' '),' ') as  address, adr.nation, adr.state,
                    goremal_email_address email, a.residency, a.application_date, p.primary_ethnicity, c.cohort
    FROM MST_ADMISSIONS_APPLICATION A,
               MST_PERSON p,mst_pre_student PS,  Admissions_Cohort c, usf_v_phone_pr_ma ph,
               MST_admissions_decision_slot AD, usf_v_email, usf_v_address_dr_lr_ma_pr adr
    WHERE a.PERSON_UID = p.person_uid
            AND a.curriculum_priority  = 1
            AND a.person_uid = ps.person_uid
           AND a.person_uid = ad.person_Uid(+)
           AND a.person_uid = goremal_pidm(+)
           AND a.person_uid = adr.pidm(+)
           AND a.person_uid = ph.pidm(+)
           AND ph.rnum(+) = 1
           AND a.person_uid = c.person_uid(+)
           AND a.academic_period = c.academic_period(+)
      &Where_Clause
           /*    TAKE OUT FOLLOWING LINE AFTER DATA IS CLEANED UP  */
            AND NOT(p.id_number = '00000000'   OR SUBSTR(p.id_number,1,1) = 'B'  OR UPPER(p.full_name_lfmi)  LIKE '%TESTING%')
           AND  a.application_status_date >= NVL(:p_as_of_date,sysdate-8000)
           AND a.academic_period = ad.academic_period(+)
            AND a.application_number = ad.application_number(+)
            AND a.degree <> 'ND'    /*   AND a.college <> 'LW'                         --  Does not need non-degree and law students    */
           &Cohort_Clause 
    ORDER BY Program  &ORDER_CLAUSE

    Hi Denis,
    I tried your suggestion. The good thing is that adding the comma allowed me to be able to add a.campus to the select statement, unfortunately, another error message happened.
    ORA-00936: missing expression SELECT p . person_uid PIDM_KEY ,
    p . id_number , p . full_name_lfmi name , p . BIRTH_DATE , p . GENDER Sex ,
    Decode ( a . residency , 'D' , p . Primary_Ethnicity , 'F' ) Ethn , a . academic_period TERM ,
    CASE WHEN : P_group_by = 'PROGRAM THEN a I started over and tried only putting in the comma and get the same message even though I didn't add campus. After that, removed the comma which led to the ORA-00933 error message. So once again, I had to close the file without saving, in order for the report to run at all.

  • SQL statement in servlet giving error

    Please let me know if I need to post this on a different forum, but I thought it was applicable to here.
    First, let me preface this post by saying I've inserted hardcoded values at the DB (Oracle) level and it worked just fine, so most of the statement is sound. All the values inserted properly when testing it that way. Also, I've printed the SQL statement to the console and all looks ok there, too.
    Out of this, I'm getting an error citing the following:
    java.lang.ArrayIndexOutOfBoundsException
    also occasionally getting the following error:
    java.sql.SQLException: [Microsoft][ODBC Driver Manager] Invalid cursor state
    In my servlet, I'm attempting the following:
    prior to the insert statement, I'm retrieving the last row number to start the increment from as in:
    Statement stmt = connection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
    ResultSet rst = stmt.executeQuery("select CHANGE_CTRL_ID from CHANGE_CONTROL_USER order by CHANGE_CTRL_ID");
         rst.last();
         int lastRowNum = Integer.valueOf(rst.getString("CHANGE_CTRL_ID")).intValue();
         rst.close();
         stmt.close();
    ------------ then ------------------------------------------------
    String preparedQuery = "INSERT ALL " +
    "INTO CHANGE_CONTROL_USER " +
    "(CHANGE_CTRL_ID,REQUESTOR_NAME,REQUESTOR_EMAIL,BUS_CONTACT,DEPT,LOCATION,PHONE_NUM,DATE_REQ," +
    "BUSVP,VP_PHONE,VP_DATE,BRANCH,PRIORITY,OPS_MAN_CHG,OPS_MAN_PPCHAP,TRAIN_REQ," +
    "EXIST_SYS_FLD_CHG,BUS_RULES_CHG,NEW_CODING,NEW_BUS_RULE,NEW_SYS_FIELD,REQ_TYPE_OTHER,REQ_OTHER_SPECIFY,IMPACT_RE_COLL," +
    "IMPACT_DEF_LM,IMPACT_DEF_REC_NRE,IMPACT_AUDIT,IMPACT_PERS_COLL,IMPACT_DEF_FCL,IMPACT_BUS_TECH,IMPACT_LEGAL,IMPACT_PRIV_COLL," +
    "IMPACT_DEF_BKRUP_RE,IMPACT_DEC_SUPT,IMPACT_RISK_MGT,IMPACT_DEF_REO,IMPACT_DEF_BKRUP_NRE,IMPACT_QUALSVCS,IMPACT_INTERNAL_CTRL,IMPACT_DEF_WKFL," +
    "IMPACT_DEF_WKOUT,IMPACT_TRAIN_TPI,IMPACT_OTHER,IMPACT_DEF_MGT,IMPACT_DEF_TAX,IMPACT_VEND_MGT,IMPACT_DEF_CTRL,IMPACT_DEF_REC_RE," +
    "IMPACT_BUS_ADMIN,IMPACT_OTHER_SPECIFY,CHANGE_IN_KPMG,CHANGE_IN_OTS,CHANGE_IN_NFR,CHANGE_IN_ARR,CHANGE_IN_BRR, CHANGE_IN_PROC_IMP," +
    "CHANGE_IN_INT_CITI_POL,CHANGE_IN_OTHER,CHANGE_IN_OTHER_SPECIFY, CHANGE_INIT_DETAILS,REQ_INFO_DESCRIPT,REQ_INFO_EXPLAIN_CURRBUS,REQ_INFO_EXPLAIN_PROPOSED,REQ_BEN_PROP_BENEFIT,REQ_BEN_FIN_IMPLEMENT," +
    "REQ_BEN_OPS_IMPLEMENT,YES_FORM,VULN_ASSESS, CBA_CHG, RISK_ACCEPT,MARSITEM, GCCRFP, APP_COMPL_QUES,CAP_EXPEND)" +
    " VALUES (changecontrol_user_seq.nextval,?,?,?,?,?,?,to_date(?,'YYYY-MON-DD HH:MI:SS'),?,?,to_date(?,'YYYY-MON-DD HH:MI:SS'),?,?," + "?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,"
    + "?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"
    + "INTO CHANGE_CONTROL_ADMIN "
    + "(AID,CHANGE_CTRL_ID,ADMNAME,CLOSEDATE,ACTIVE)"
    + "VALUES (changecontrol_admin_seq.nextval, changecontrol_user_seq.currval,NULL, NULL, -1)"
    + "SELECT object_name AS REQUESTOR_NAME FROM all_objects where rownum <= 1;";     
    also I've declared all the respective strings for the PreparedQuery statement.
    If you need to see those, here they are:
    PreparedStatement pstmt = connection.prepareStatement(preparedQuery);
                   // stmt = connection.stmt("INSERT INTO RMIS_USER VALUES (?,?,?,?,to_date(?,'YYYY-MON-DD HH:MI:SS'),?,?,?,?,to_date(?,'YYYY-MM-DD HH:MI:SS')");
              pstmt.setInt(1,++lastRowNum);
              pstmt.setString(2,reqName);
              pstmt.setString(3,reqemail);
              pstmt.setString(4,buscont);
              pstmt.setString(5,reqDept);
              pstmt.setString(6,reqLocale);
              pstmt.setString(7,phone_num);
              pstmt.setDate(8,dtreq);
              //pstmt.setCalendar(8,rtnow);
              pstmt.setString(9,busvp_email);
              pstmt.setString(10,vpphone);
              pstmt.setDate(11,dt);
              pstmt.setString(12,branch);
              pstmt.setString(13,priority);
              pstmt.setString(14,opsmanchg);
              pstmt.setString(15,opsmanppchap);
              pstmt.setString(16,train_req);
              pstmt.setString(17,reqexist_sys_fld_chg);
              pstmt.setString(18,reqbus_rules_chg);
              pstmt.setString(19,reqnew_coding);
              pstmt.setString(20,reqnewbus_rule );
              pstmt.setString(21,reqnew_sys_fld);
              pstmt.setString(22,reqother);
              pstmt.setString(23,req_other_specify);
              pstmt.setString(24,imp_recoll);
              pstmt.setString(25,imp_deflm);
              pstmt.setString(26,imp_defrecnre);
              pstmt.setString(27,imp_audit);
              pstmt.setString(28,imppers_coll);
              pstmt.setString(29,imp_deffcl);
              pstmt.setString(30,imp_bustech);
              pstmt.setString(31,imp_legal);
              pstmt.setString(32,imp_privcoll);
              pstmt.setString(33,imp_defbkre);
              pstmt.setString(34,imp_decsupt);
              pstmt.setString(35,imp_riskmgt);
              pstmt.setString(36,imp_defreo);
              pstmt.setString(37,imp_defbknre);
              pstmt.setString(38,imp_qualsvc);
              pstmt.setString(39,imp_intlctrl);
              pstmt.setString(40,imp_defwkfl);
              pstmt.setString(41,imp_defwkout);
              pstmt.setString(42,imp_trtpi);
              pstmt.setString(43,impact_other);
              pstmt.setString(44,imp_defmgt);
              pstmt.setString(45,imp_deftax);
              pstmt.setString(46,imp_vendmgt);
              pstmt.setString(47,imp_defctrl);
              pstmt.setString(48,imp_defrecre);
              pstmt.setString(49,imp_busadm);
              pstmt.setString(50,impact_other_specify);
              pstmt.setString(51,change_in_kpmg);
              pstmt.setString(52,change_in_ots);
              pstmt.setString(53,change_in_nfr);
              pstmt.setString(54,change_in_arr);
              pstmt.setString(55,change_in_brr);
              pstmt.setString(56,change_in_proc_imp);
              pstmt.setString(57,change_inter_citpol);
              pstmt.setString(58,change_in_other);
              pstmt.setString(59,change_in_other_specify);
              pstmt.setString(60,change_init_details);
              pstmt.setString(61,req_info_descript);
              pstmt.setString(62,req_info_explain_currbus);
              pstmt.setString63,req_info_explain_proposed);
              pstmt.setString(64,req_ben_prop_benefit);
              pstmt.setString(65,req_ben_fin_implement);
              pstmt.setString(66,req_ben_ops_implement);
              pstmt.setString(67,projyes);
              pstmt.setString(68,vulnass);
              pstmt.setString(69,cbachg);
              pstmt.setString(70,riskacc);
              pstmt.setString(71,marsitem);
              pstmt.setString(72,gccrfp);
              pstmt.setString(73,applcomp);
              pstmt.setString(74,capexpend);
              pstmt.executeUpdate();
    if anyone sees anything flawed here, please let me know!
    Thanks!
    Message was edited by:
    bpropes20
    Message was edited by:
    bpropes20
    Message was edited by:
    bpropes20

    What a mess. First off, the line pstmt.setInt(1,++lastRowNum); just needs to go away. You're already using a sequence to set the value for the primary keys, you don't need to add a mistake like this.
    I then count 73 question marks (you can verify, I'm not counting again.) That would mean that your indices are off by one, and the ArrayIndexOutOfBounds is probably coming from pstmt.setString(74,capexpend); Dump the ++lastRowNum line, change all of your indices (after verifying the bind count!) and try it again.
    You can see an inherent weakness in the PreparedStatement clauses - one change means manually rewriting all of the indices. A solution is dumping all of your bind values into a List, then loop through the list to do your setXXX statements. If all binds are not of the same type, you can bind the values to some object that identifies type and use those objects in the list instead of the values. A little more complex, but easier to maintain in my opinion.

  • SQL statement with Function returns slow in Interactive Report

    I have an Interactive Report that returns well but when I add in a function call in the where clause that does nothing but return a hard coded string of primary keys and is compared to a table's primary key with a like operator the performance tanks. Here is the example:
    get_school2_section(Y.pk_id,M.pk_id,I.section,:P577_SECTION_SHUTTLE) LIKE '%:' || I.pk_id || ':%'
    I have the values hard coded in the return of the function. There are no cursors run in the function, there is no processing done in the function. It only declares a variable. Sets the variable, and returns that variable back to the SQL statement.
    I can hard code the where clause value to look like this:
    ':90D8D830A877CCFFE040010A347D1A50:8ED0BBFDEAACC629E040010A347D6471:9800B8FDBD22B761E040010A347D0D9A:' LIKE '%:' || I.pk_id || ':%'
    This returns fast. When I add in the function call which returns the same hard coded values, the page goes from returning in 1 to 2 seconds to 45 or more seconds.
    Why does adding a simple function call into the where clause cause such a deterioration in performance.
    Edited by: alamantia on Aug 17, 2011 7:39 AM
    Edited by: alamantia on Aug 17, 2011 7:40 AM

    So you are telling me that the where clause with a function call will NOT run the function on every row? Please explain that to me further?
    if you have code that is the following:
    select a,b,c from a_table where a > 2 and b < 3 and function_call(c) > 0You are telling me that Oracle will NOT call that function on EVERY row it tries to process in the select?
    Thank you,
    Tony Miller
    Webster, TX
    I cried because I did not have an office with a door until I met a man who had no cubicle.
    -Dilbert
    If this question is answered, please mark the thread as closed and assign points where earned..

  • Setting column names in a sql statement

    hello everyone i hope someone can help me.
    i want a sql statement that gets the column names from a arraylist for example
    String sql = ("INSERT INTO Cust (and i want this part to get what is in the arraylist) values (?, ?, ?)");
    is there any way i can do this?
    thanks for your time
    loftty

    hello again
    well when i try to compile it i get an error saying [ODBC SQL server driver] COUNT field incorrect or syntax error.
    what is the problem here?
    and regarding my previous question my arraylist holds three names (firstname, lastname and postcode) now i want to be able to add 10 values to the column name firstname, then i want to add 8 values to the column name lastname and then 9 values to column name postcode.
    i hope this is a better understanding if not let me know and i will try and explain again.
    thanks for your time
    loftty
    StringBuffer sb = new StringBuffer("INSERT INTO Cust (");
                                                 Iterator it = arr.iterator();
                                                 while (it.hasNext())
                                                      String col = (String) it.next();
                                                      sb.append(col);
                                                      if (it.hasNext())
                                                           sb.append(',');
                                                      sb.append(") values (?, ?, ?)");
                                                      String sql = sb.toString();
                                                 PreparedStatement prepStmt = con.prepareStatement(sql);
                                                           prepStmt.setString(1, "hello");
                                                           prepStmt.setString(2, "hi");
                                                           prepStmt.setString(3, "bye");
                                                           prepStmt.executeUpdate();
                                                           prepStmt.close();

  • Setting the sql statement

    http://www.egbolig.dk/drift_bo_syd.rpt (HERE IS THE REPORT)
    We are using SAP Crystal Report .NET Runtime files (http://scn.sap.com/docs/DOC-7824 newest version 13.0.9.1312) in our web asp.net application. Everything have been working fine, but we have can into problems when showing the certain kinda reports.
    In our code get the reports sql statement using getSQLStatement.
    Dim gp As New GroupPath() Dim sql As String = report.ReportClientDocument.RowsetController.GetSQLStatement(gp)
    This will get the sql, and we use this sql (getSqlStatement) and attach a sql WHERE clause from the code to only get a certain number of records.
    The report Drift_bo_syd.rpt has 5 tables, and the following sql statement. 
    Database/Show Sql Statement
    SELECT "rekvstam"."Sel", "rekvstam"."Afd", "rekvstam"."Levadresse", "rekvstam"."Rekvisition", "rekvstam"."Lejemaal", "rekvstam"."Lejer", "rekvstam"."Udfoertaf", "rekvstam"."Udfoertdato", "rekvstam"."Krit", "Selskab"."Adresse", "Selskab"."Postby", "Selskab"."Tlf", "Selskab"."Fax", "rekvstam"."Kontor", "rekvstam"."Hjemme", "rekvstam"."Rekvdato", "rekvstam"."Aftale", "rekvstam"."InitialRet", "rekvstam"."Arbejde", "kreditor"."Att", "rekvstam"."Konto", "Selskab"."Navn", "Selskab"."Email", "Interessentadresse"."Navn", "Interessentadresse"."Adresse", "Interessentadresse"."Postby", "Interessentadresse"."Email1", "Interessentadresse"."Telefon_Fax", "Interessentadresse"."Type", "Interessentadresse"."Tlf1", "rekvstam"."tlfLejer", "kreditor"."Kred", "Interessentadresse"."Interessentnr" FROM  (("Rekvstam" "rekvstam" INNER JOIN "Selskab" "Selskab" ON "rekvstam"."Sel"="Selskab"."Sel") LEFT OUTER JOIN "Kreditor" "kreditor" ON "rekvstam"."Kred"="kreditor"."Kred") INNER JOIN "Interessentadresse" "Interessentadresse" ON "kreditor"."Interessentnr"="Interessentadresse"."Interessentnr" WHERE  "Interessentadresse"."Type"='K' 
    But if we run the report from our asp.net code, we get the following error: 
    Cannot determine the queries necessary to get data for this report. Failed to retrieve data from the database. Error in File Drift_Bo_Syd {97FED382-1BAC-4DB1-970F-9E098ECE28F1}.rpt: Failed to retrieve data from the database.
    After a long time searching for a solution, we found out that if we place the column kred from the kreditor table on the report, the report will work. (field explorer / database fields / kreditor (table) / kred (column)
    Very important is that the field "kreditor.kred" is a primary key of the table kreditor, and also used in the linking.!
    (We can get the report to work if we call the sql statement with the "kreditor"."kred" in the SELECT statement.
    SELECT "kreditor"."kred", "rekvstam"."Sel", "rekvstam"."Afd", "rekvstam"."Levadresse", "rekvstam"."Rekvisition", "rekvstam"."Lejemaal", "rekvstam"."Lejer", "rekvstam"."Udfoertaf", "rekvstam"."Udfoertdato", "rekvstam"."Krit", "Selskab"."Adresse", "Selskab"."Postby", "Selskab"."Tlf", "Selskab"."Fax", "rekvstam"."Kontor", "rekvstam"."Hjemme", "rekvstam"."Rekvdato", "rekvstam"."Aftale", "rekvstam"."InitialRet", "rekvstam"."Arbejde", "kreditor"."Att", "rekvstam"."Konto", "Selskab"."Navn", "Selskab"."Email", "Interessentadresse"."Navn", "Interessentadresse"."Adresse", "Interessentadresse"."Postby", "Interessentadresse"."Email1", "Interessentadresse"."Telefon_Fax", "Interessentadresse"."Type", "Interessentadresse"."Tlf1", "rekvstam"."tlfLejer", "kreditor"."Kred", "Interessentadresse"."Interessentnr" FROM  (("Rekvstam" "rekvstam" INNER JOIN "Selskab" "Selskab" ON "rekvstam"."Sel"="Selskab"."Sel") LEFT OUTER JOIN "Kreditor" "kreditor" ON "rekvstam"."Kred"="kreditor"."Kred") INNER JOIN "Interessentadresse" "Interessentadresse" ON "kreditor"."Interessentnr"="Interessentadresse"."Interessentnr" WHERE  "Interessentadresse"."Type"='K'
    But it should not be necessary to include this field (which is the primary key and used in linking the report) in the sql statement,
    BECAUSE it is not used in the report. So maybe this is a bug?
    It has not been necessary in RDC Crystal Report or RAS Crystal Report in a classic asp envoriment.
    Here is the code we use to set the reports SQL Statement)
    Try
    Dim conn As New SqlConnection(connString)
    conn.Open()
    Dim sd As New SqlDataAdapter(New SqlCommand(nySQL, conn))
    Dim ds As New Data.DataSet()
    Dim navn As String = report.Database.Tables.Item(0).Name
    sd.Fill(ds, navn)
    report.SetDataSource(ds)
    conn.Close()
    Catch ex As Exception
    Throw
    End Try

    Hi Jan
    I understand your problem completely but we have asked  R&D to be able to edit the SQL and they explained due to how the report Engine works it's simply not possible anymore. It would take a complete rewrite in all of our DB drivers and query dll's to be able to allow it. They did that in CR 9 when they rewrote the DB drivers and removed the SQL part of the code into separate dll's and that is when the ability was removed, it's been that way ever since.
    One possibility is to get the SQL from the Report and then connect to your DB using a .NET and if the results from the SQL is less than 5K rows and not too many columns you could then set the Report data source to a Dataset.
    As long as all of the field names are the same CR will run the report using this work flow.
    For data larger than 5K rows, limit is due to memory resources, you could save the DS to an XML file and then set the reports data source to the XML file. We've seen 100meg XML's used so the amount of data should not be a problem, but of course there are limits to everything so test...
    This should not affect performance much.
    So the work flow would be:
    Load the report
    Get the SQL Statement
    Paste it into a Dataset Query
    Something like this should get you started:
    //string connString = "Provider=SQLOLEDB;Data Source=MySQLServer;Database=xtreme;User ID=sa;Password=pw";
    string connString = "Provider=SQLNCLI10;Server=MySQLServer;Database=xtreme;User ID=sa;Password=pw";
    Detail"".""Quantity"" FROM   ""xtreme"".""dbo"".""Orders Detail"" ""Orders Detail""";
    string sqlString = @"SELECT top 10*  FROM  ""xtreme"".""dbo"".""Financials"" ""Financials""";
    System.Data.OleDb.OleDbConnection oleConn = new System.Data.OleDb.OleDbConnection(connString);
    System.Data.OleDb.OleDbCommand cmd = oleConn.CreateCommand();
    cmd.CommandText = sqlString;
    System.Data.DataSet ds = new System.Data.DataSet();
    OleDbDataAdapter oleAdapter = new OleDbDataAdapter(sqlString, oleConn);
    //OleDbDataAdapter oleAdapter2 = new OleDbDataAdapter(sqlString2, oleConn);
    DataTable dt1 = new DataTable("Financials");
    //DataTable dt2 = new DataTable("Orders Detail");
    oleAdapter.Fill(dt1);
    //oleAdapter2.Fill(dt2);
    ds.Tables.Add(dt1);
    //ds.Tables.Add(dt2);
    ds.WriteXml("c:\\reports\\sc2.xml", XmlWriteMode.WriteSchema);
    // as long as the field names match exactly Cr has no problems setting report to a DS.
    try
        rpt.SetDataSource(ds.Tables[0]); // incremtent [0] for more than 1 table.
        rpt.SetDataSource(ds);
    catch (Exception ex)
        MessageBox.Show("ERROR: Schema Mismatch. Error reported by CR: " + ex.Message);
    //Now check for subreport and set to same DS
    foreach (CrystalDecisions.CrystalReports.Engine.Section section in rpt.ReportDefinition.Sections)
        foreach (CrystalDecisions.CrystalReports.Engine.ReportObject reportObject in section.ReportObjects)
            if (reportObject.Kind == ReportObjectKind.SubreportObject)
                CrystalDecisions.CrystalReports.Engine.SubreportObject subReport = (CrystalDecisions.CrystalReports.Engine.SubreportObject)reportObject;
                CrystalDecisions.CrystalReports.Engine.ReportDocument subDocument = subReport.OpenSubreport(subReport.SubreportName);
                subDocument.SetDataSource(ds);
    And for XML it would use this part, not above I am saving the data and structure in the XML file so it should match what is in the report:
    foreach (CrystalDecisions.CrystalReports.Engine.Table rptTable in rpt.Database.Tables)
        try
            rptTable.Location = btrDataFile.ToString(); // @"D:\Atest\" + rptTable.Location + ".xml";
        catch (Exception ex)
            MessageBox.Show("ERROR: " + ex.Message);
    Only issue you may run into is sometimes XML does not have a direct field type and your original data source but you'll get an error if that happens which could be trapped and handled.
    If you have a report that only uses 2 tables I do have code that will convert it to use a Command Object. That is the limit the engine is capable of, there is a lot of logic to be able to do this in CRD and the SDK so that is all we could get for now.
    I hope that helps
    Don

Maybe you are looking for

  • Two  different ways of closing Input/Ouput streams

    OK, the Sun tutorial on Exceptions [http://java.sun.com/docs/books/tutorial/essential/exceptions/putItTogether.html] shows an example where a PrintWriter is closed within a finally block. Now, the tutorial on bute streams [http://java.sun.com/docs/bo

  • Infinite Supply and ATP calculations

    Hi, We are using an Unconstrained plan which is ATP enabled.We have setup ATP rule where the Infinite Supply option is set as Cum Total Lead time. Now, we have Purchase Orders that are placed both within and beyond the Cum Total Lead Time. For exampl

  • Selection of criteria to Create Average demand report

    Hi SAP master, I'm doing the functional spec for Average demand analysis report. This report will grab all the material that have been issue out from plant (mov 601) for the past 3 month periods. I already know which table can be use to build-up this

  • Load balancing http server

    Hi There, I want to implement a load balancer (linux virtual server) into our htmldb configuration. We currently run the http server on the same machine running oracle/htmldb. I want to split this out and use 2 seperate machines running http server b

  • Outbound queues are in ready status

    Hi, In our system outbound queue are getting stuck in READY status. They are not getting executed automtically from READY status we have to manually exceute them in SMQ2. How i can clear the queue which are in  READY status. Thanks & Regards, Koushal