SQL problem

I've got a problem with a servlet I'm writing. Here's a code snippet:
if(operation.equals("Lookup details"))
          {     //get customer details
               String Hnum = req.getParameter("HouseNum");
               String Pcode = req.getParameter("PostCode");
              String sql = "SELECT * FROM Customer WHERE house_num = " Hnum " AND postcode = '" Pcode "'";
              String url = "jdbc:pointbase:server://localhost:9092/projectdb";
              Connection con;
              Statement stmt;
              ResultSet rs;
               try {
                    Class.forName("com.pointbase.jdbc.jdbcUniversalDriver");
               catch(ClassNotFoundException ex) {
                    out.println("Failed to find driver");
               try {
                    con = DriverManager.getConnection(url, "PBPUBLIC", "PBPUBLIC");
                    stmt = con.createStatement();
                    //execute query
                    rs = stmt.executeQuery(sql);
               catch(SQLException ex) {
                    out.println("SQL Exception");
                    out.println("" + ex);
          }When it comes to actually executing the sql command I get the following error:
SQL Exception
java.sql.SQLException: Expected to find "end of SQL command" instead found "POSTCODE" at position 46.
I can't quite see whats wrong with my SQL string, its probably something simple tho. Any ideas?

For sure (200%) your request does not contain HouseNum parameter.
You should check presence of HouseNum parameter for instance like:
String hnum=req.getParameter("HouseNum");
if(hnum==null || hnum.trim().length()==0)
   //do something here - for instance put default HouseNum value like:
   hnum="1"
}

Similar Messages

  • Two SQL problems

    First problem...
    SQL root will not access all databases...
    If I try to access al databases using SQL Administrator the connection is refused even if I use root.
    all databases are accessable va individual username and password..
    Tried changing root password with GUI but makes no difference...
    Second SQL problem...
    10.4.11 server failed all raid volumes so corrupted no rescue was possible on any volume reinstall failed as well...
    Have rebuilt the server using 10.5.6 I will have to manually import the SQL databases from the old server... what do I do ??? I cannot boot the old server so cannot do an SQL export or anything...
    Thanks...

    Hi Jun,
    Can i contribute a little for ur 2nd problem.
    This error is coz, If u are using a filter against a File "data store" u can't test it, only against RDBMS query will be tested at data store level.
    Well, for using that filter and make sure its working, drag and drop the source file in the interface (u can get the filter) and make it to execute on STAGING.
    Thanks,
    Guru

  • Small SQL problem

    Hello,
    I have a small SQL problem...
    I am designing an online bank using servlets for a university project and it allows customers to view their statements. They select which of their account numbers they want to view the statement for and the start and end date of the statement.
    The problem lies with the dates. Here is the SQL:
    SELECT date, details, amount, balance
    FROM HISTORY
    WHERE bankaccnumber=13494925 And date>=1/1/01 And date<=31/1/01;
    All of the books I have looked at show dates in '1/1/01' format but whenever I try it this way I get a 'Data type mismatch in criteria expression' error (the 'date' field in the Database IS a Date type).
    Although, whenever I run the query in Access and prompt the user to enter the start and end date, it works fine.
    I have spoken to a few people and no-one seems to know why it is not working.
    Any ideas???
    Thanks

    If your database is MS Access and you don't expect to switch to something else, then write this:
    SELECT date, details, amount, balance
    FROM HISTORY
    WHERE bankaccnumber=13494925 And [date]>=#1/1/01# And [date]<=#1/31/01#
    Note that you MUST format your dates as MM/DD/YY and not as DD/MM/YY, that's an Access rule, and that you will probably have to "quote" your column name "date", which I think is a reserved word in SQL and hence a bad choice for column name.
    Personally I always use PreparedStatements. That way my SQL would look like this:
    SELECT date, details, amount, balance
    FROM HISTORY
    WHERE bankaccnumber=13494925 And date>=? And date<=?
    and I would use the setDate() method to fill in the parameters. Since this method uses a Date as a parameter, I don't need to fight with date formats, the JDBC driver handles that for me.

  • Sql problem, pivot question?

    Hi guys,
    I have an interesting problem and do not manage to find a sollution.
    I need to create a report, and we call it variance/trending report. let me explain.
    I have a table that holds all employess with their salaries, every month.
    currenly my selects gets all employess with their salaries from current and previous month. and the result looks like:
    Employee_iD| Salary| month
    1          |500   |   C
    2          |100   |   P
    1          |650   |   P
    3          |100   |   p
    3           |180   |   C
    how can I do my select so I can see the result, in different columns, in a manner in which I can compare the salaries between them (from current and previous month):
    Employe_iD| current_month| previous_month | variance
    1        |500                 | 650                 | -150
    2        |                      | 100                 |
    3        |180                 |100                   |80you can see that C, measn current month, and P measn previous month.
    I think I will have data in my select for both, previous and current. If not, I will treat it as zero.
    I gave a simple exemple . My select is a little more complex.
    any help is appreciated.
    Thanks

    May be..
    SQL> WITH tbl AS (SELECT 1 empid,500 sal,'C' mon FROM DUAL UNION ALL
      2               SELECT 2 empid,100 sal,'P' mon FROM DUAL UNION ALL
      3               SELECT 1 empid,650 sal,'P' mon FROM DUAL UNION ALL
      4               SELECT 3 empid,100 sal,'P' mon FROM DUAL UNION ALL
      5               SELECT 3 empid,180 sal,'C' mon FROM DUAL
      6               )
      7  SELECT empid,NVL(MAX(DECODE(mon,'P',sal)),0) previous_sal
      8              ,NVL(MAX(DECODE(mon,'C',sal)),0) current_sal
      9              ,NVL(MAX(DECODE(mon,'P',sal)),0)- NVL(MAX(DECODE(mon,'C',sal)),0)
    10                var
    11  FROM tbl
    12  GROUP BY empid          
    13               ;
         EMPID PREVIOUS_SAL CURRENT_SAL        VAR
             1          650         500        150
             2          100           0        100
             3          100         180        -80

  • PL/SQL problem in portal

    hello all,
    PROBLEM :
    I followed this thread Copying data from one field to another on a form
    but unfortunately..encountered with d following error...
    Any PL/SQL coding is throwing such errors on my portal..
    I have to install any additional tools or configure something..( I done executed the provsyns.sql for myschema)
    Someone please suggest me..
    ERROR :
    Internal error (WWC-00006)
    An unexpected error occurred: ORA-01001: invalid cursor (WWV-16016)
    Error displaying form : ORA-01001: invalid cursor (WWV-16408)
    Error running user PL/SQL code: ORA-01001: invalid cursor (WWV-16403)
    ORA-06550: line 5, column 7:
    PLS-00201: identifier 'P_SESSION.GET_VALUE_AS_VARCHAR2' must be declared
    ORA-06550: line 5, column 1:
    PL/SQL: Statement ignored
    ORA-06550: line 8, column 9:
    PLS-00201: identifier 'P_SESSION.GET_VALUE_AS_VARCHAR2' must be declared
    ORA-06550: line 8, column 1:
    PL/SQL: Statement ignored
    ORA-06550: line 11, column 1:
    PLS-00201: identifier 'P_SESSION.SET_VALUE' must be declared
    ORA-06550: line 11, column 1:
    PL/SQL: Statement ignored
    ORA-06550: line 15, column 1:
    PLS-00201: identifi (WWV-11230)
    Failed to parse as PORTAL_PUBLIC - BEGIN declare
    id varchar2(20);
    name varchar2(20);
    begin
    id := p_session.get_value_as_VARCHAR2(
    p_block_name => 'DEFAULT',
    p_attribute_name => 'EMP_ID');
    name := p_session.get_value_as_VARCHAR2(
    p_block_name => 'DEFAULT',
    p_attribute_name => 'EMP_NAME');
    p_session.set_value(
    p_block_name => 'DEFAULT',
    p_attribute_name => 'ID',
    p_value => id);
    p_session.set_value(
    p_block_name => 'DEFAULT',
    p_attribute_name => 'NAME',
    p_value => name);
    end; END; (WWV-08300)
    The preference path does not exist: ORACLE.WEBVIEW.PARAMETERS.1668713167 (WWC-51000)
    Many Thanks In Advance :-)

    hi Pappu
    if you have used the same exact code as given in the message you have mentioned, then please correct one variable's name. the reply I gave in that thread has a typo. in suggesting a solution to that question, I had tried it with a different set of variables on my system and in replying back, i mistakenly left one such variable in that thread.
    try it and see if you still get errors.
    AMN
    declare
    v_address1 varchar2(20);
    begin
    v_address1 := p_session.get_value_as_VARCHAR2(
    p_block_name => 'DEFAULT',
    p_attribute_name => 'A_ADDRESS1');
    p_session.set_value(
    p_block_name => 'DEFAULT',
    p_attribute_name => 'A_LOCATION1',
    p_value => v_address1);
    end;

  • PL/SQL- Problem in creating a partitioned fact table using select as syntax

    Hi All,
    I am trying to create a clone(mdccma.fact_pax_bkng_t) of existing fact table (mdccma.fact_pax_bkng) using dynamic pl/sql. However, pl/sql anonymous block errors out with following error:
    SQL> Connected.
    SQL> SQL> DECLARE
    ERROR at line 1:
    ORA-00911: invalid character
    ORA-06512: at "SYS.DBMS_SYS_SQL", line 1608
    ORA-06512: at "SYS.DBMS_SQL", line 33
    ORA-06512: at line 50
    Here is pl/sql block:
    -- CREATING FPB_T
    DECLARE
    v_owner VARCHAR2(32) := 'MDCCMA';
    v_table_original VARCHAR2(32) := 'FACT_PAX_BKNG';
    v_table VARCHAR2(32) := 'FACT_PAX_BKNG_T';
    v_tblspc VARCHAR2(32) := v_owner||'_DATA';
    CURSOR c_parts IS SELECT TABLESPACE_NAME, PARTITION_NAME,HIGH_VALUE, ROW_NUMBER() OVER (ORDER BY PARTITION_NAME) AS ROWNUMBER
    FROM USER_TAB_PARTITIONS
    WHERE TABLE_NAME = v_table_original
    ORDER BY PARTITION_NAME;
    v_cmd CLOB := EMPTY_CLOB();
    v_cmd3 varchar2(300) := 'CREATE TABLE ' ||v_owner||'.'||v_table||' TABLESPACE '||v_tblspc
    ||' NOLOGGING PARTITION BY RANGE'||'(' ||'SNAPSHOT_DTM '||')' ||'(';
    v_part VARCHAR2(32);
    v_tblspc_name VARCHAR2(32);
    v_row number;
    v_value LONG;
    v_tmp varchar2(20000);
    v_cur INTEGER;
    v_ret NUMBER;
    v_sql DBMS_SQL.VARCHAR2S;
    v_upperbound NUMBER;
    BEGIN
    v_cmd := v_cmd3;
    OPEN c_parts;
    FETCH c_parts INTO v_tblspc_name, v_part,v_value, v_row;
    WHILE c_parts%FOUND
    LOOP
    IF (v_row = 1) THEN
    v_tmp := ' PARTITION '||v_part||' VALUES LESS THAN ' ||'('|| v_value||')'||' NOLOGGING TABLESPACE '||v_tblspc_name;
    ELSE
    v_tmp := ', PARTITION '||v_part||' VALUES LESS THAN ' ||'('|| v_value||')'||' NOLOGGING TABLESPACE '||v_tblspc_name;
    END IF;
    v_cmd := v_cmd || v_tmp;
    -- DBMS_OUTPUT.PUT_LINE(v_cmd);
    FETCH c_parts INTO v_tblspc_name, v_part,v_value, v_row;
    END LOOP;
    -- DBMS_OUTPUT.PUT_LINE('Length:'||DBMS_LOB.GETLENGTH(v_cmd));
    v_cmd := v_cmd||')'||' AS SELECT ' || '*'||' FROM ' || v_owner||'.'|| v_table_original ||' WHERE '||'1'||'='||'2'||';';
    v_upperbound := CEIL(DBMS_LOB.GETLENGTH(v_cmd)/256);
    FOR i IN 1..v_upperbound
    LOOP
    v_sql(i) := DBMS_LOB.SUBSTR(v_cmd
    ,256 -- amount
    ,((i-1)*256)+1 -- offset
    END LOOP;
    v_cur := DBMS_SQL.OPEN_CURSOR;
    DBMS_SQL.PARSE(v_cur, v_sql, 1, v_upperbound, FALSE, DBMS_SQL.NATIVE);
    v_ret := DBMS_SQL.EXECUTE(v_cur);
    CLOSE c_parts;
    DBMS_OUTPUT.PUT_LINE(v_cmd);
    -- EXECUTE IMMEDIATE v_cmd ;
    END;
    The above pl/sql creates a DDL for partitioned fact table(new) based on an existing fact table and get executes through CLOB.
    Please look into the issue and let me know any changes or modifications/suggestions that are required to fix the issue. Any help is appreciated.
    Thank You,
    Sudheer

    Think this is your problem:
    v_cmd := v_cmd||')'||' AS SELECT ' || '*'||' FROM ' || v_owner||'.'|| v_table_original ||' WHERE '||'1'||'='||'2'||';';Remove the SQL terminator ';' ... dynamic SQL doesn't require it, try this instead:
    v_cmd := v_cmd||')'||' AS SELECT ' || '*'||' FROM ' || v_owner||'.'|| v_table_original ||' WHERE '||'1'||'='||'2';Thanks
    Paul

  • Sql Problems, Same Field Names In Multiple Mysql Tables?

    I have a keyword search that searches multiple DB tables for thumbnail images using UNION ALL. I have two pages, results.php, and view.php.  My goal is to able to click a thumbnail image on results.php and be directed to a larger version of that same image on view.php. The problem is each image in all my tables uses the field name "id" so when I click a thumbnail on results.php I get two different images with the same id from different tables.  I tried changing the id's to different names, but when it was time to pass url parameters I can only choose 1 value. (if you can choose more than 1 I don't know how).  So my question is why are my id's from different tables being grouped together, and how can I change this?
    Image Results Page (which works perfect):
    SELECT *
    FROM table1
    WHERE keyword LIKE %colname% OR id  LIKE %colname% 
    UNION ALL
    SELECT *
    FROM table2
    WHERE keyword LIKE %colname% OR id  LIKE %colname% 
    View Image Page (having problems here):
    SELECT *
    FROM table1
    WHERE id = colname
    UNION ALL
    FROM table2
    WHERE id = colname

    Yes, that is going to be a problem - and it's just the beginning of your problems when you do not normalize your data. Your data model is not correct. You should not be storing similar data in 15 tables - it's a really big mistake.
    To solve your current problem you would need to include a table identifier in the query results in the Image results page, and pass that to the view page and then use PHP to dynamically create the SQL with the correct table....ugh!

  • Java.sql problem

    Hi,
    I have a problem with "import java.sql.*".
    When a try to compile i get the error:
    "package java.sql does not exist"
    I've tried everything, classpath, add JAR/Libraries, install CDC tools, looked into hundred forums and can't solve the problem.
    I'm using NetBeans 5.5 with Mobility Pack.
    If anybody have any idea about what can I do, I'll appreciate it a lot.
    Thank You!
    If you need me to be more specific, please let me know

    I just start the application with
    import java.sql
    an then the rest of the applicationIf you want to import all the classes from the java.sql package, the correct import statement is:import java.sql.*;� {�                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Oracle-PHP PL/SQL Problem

    Dear,
    I have this situation:
    Inside PHP I call this statement:
    $usr_stmt = oci_parse($conn, "begin PKG_USERBEHEER_TEST.user_insert(PKG_USERBEHEER_TEST.user_create_type(:usr_id,:usr_naam,:usr_vnaam,:usr_email,:usr_pass,SYSDATE,NULL),:p_exusr_id); end;");
    binding the variables
    oci_bind_by_name($usr_stmt, ':usr_id', $USR_ID);
    oci_bind_by_name($usr_stmt, ':usr_naam', $USR_NAAM);
    oci_bind_by_name($usr_stmt, ':usr_vnaam', $USR_VNAAM);
    oci_bind_by_name($usr_stmt, ':usr_pass', $USR_PASS);
    oci_bind_by_name($usr_stmt, ':usr_email', $USR_EMAIL);
    oci_bind_by_name($usr_stmt, ':p_exusr_id', $EXEC);
    INSIDE MY PACKAGE:
    FUNCTION user_create_type(usr_id users.usr_id%TYPE, usr_naam users.usr_naam%TYPE, usr_vnaam users.usr_vnaam%TYPE, usr_email users.usr_email%TYPE, usr_pass users.usr_pass%TYPE, usr_start_datum users.usr_pass%TYPE, usr_eind_datum users.usr_eind_datum%TYPE) return user_rec is
    v_rec user_rec;
    Begin
    v_rec.usr_id := usr_id;
    v_rec.usr_naam := usr_naam ;
    v_rec.usr_vnaam:=usr_vnaam;
    v_rec.usr_email:=usr_email;
    v_rec.usr_pass :=usr_pass;
    v_rec.usr_start_datum := usr_start_datum;
    v_rec.usr_eind_datum := usr_eind_datum;
    return v_rec;
    end user_create_type;
    PROCEDURE user_insert(r IN OUT user_rec, p_exusr_id IN users.usr_id%TYPE) IS
    BEGIN
    --check if allowed
    IF(NOT checkallowedactions(p_exusr_id, 117)) THEN
    raise_application_error(-20999, 'User is not allowed executing this action');
    END IF;
    --end check if allowed
    SELECT seq_users.nextval
    INTO r.usr_id
    FROM dual;
    SELECT sysdate
    INTO r.usr_start_datum
    FROM dual;
    INSERT
    INTO users(usr_id, usr_naam, usr_vnaam, usr_email, usr_pass, usr_start_datum)
    VALUES(r.usr_id, r.usr_naam, r.usr_vnaam, r.usr_email, cryptit.encrypt(r.usr_pass), r.usr_start_datum);
    END user_insert;
    When I excecute my statement I get this error:
    Warning: oci_execute() [function.oci-execute]: ORA-06550: line 1, column 39: PLS-00363: expression 'PKG_USERBEHEER_TEST.USER_CREATE_TYPE' cannot be used as an assignment target ORA-06550: line 1, column 7: PL/SQL: Statement ignored in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\add_user.php on line 22
    But I need the out parameter, because I need my generated ID (Sequence) for futher use in my script.
    I'm not able to edit the pl/sql script because an other application is using it.
    Somebody can help me?
    Thx
    Davy

    The call to PKG_USERBEHEER_TEST.user_insert needs to pass a single PL/SQL variable as the first argument so that user_insert can return an update record. The OUT declaration of 'r' in user_insert is throwing the error. To that point, the problem is not due to PHP. You would get the same error in SQL*Plus.
    But, because you can't bind a record in PHP, you need to create a new PL/SQL function that calls PKG_USERBEHEER_TEST.user_create_type putting the returned record into a PL/SQL variable, and then calls user_insert. PHP would call the wrapper PL/SQL function.
    -- cj

  • Report SQL problem

    hi all,
    need some help in oracle report 6i, I have a SQL statement like
    SQL> select p.person_id, p.person_name, p.birth_date,max(cg.effective_start_date) "Last Concession",
    add_months(max(effective_start_date),24) "Next Concession"
    from person p, conc_given cg
    where p.person_id = cg.person_id
    group by p.person_id, p.person_name, p.birth_date
    p.person_id p.person_name p.birth_date Last Concession Next concession
    1234 peter scott 01/06/1967 05/07/00 05/07/02
    1489 smith bratt 09/04/1958 07/10/01 07/10/03
    The p.person_id I am selecting in my SQL statement do have some relationship
    with some other non-clients. Its all in relationship table...and person_id is a foreign key in that table..
    I want the results like as follows:
    p.person_id p.person_name p.birth_date relationship.person_id related person_name Last Concession Next concession
    1234 peter scott 01/06/1967 05/07/00 05/07/02
    1584 anita scott 07/09/01 07/09/03
    1897 david scott NULL NULL
    1489 smith bratt 09/04/1958 07/10/01 07/10/03
    1354 sonia bratt 09/06/1998 09/06/2000
    I can attach the related person_ID and his name with the p.person_id but the problem I am having
    I don't know how the relationship_ID and name can appear in the next line and their conc_dates as well...
    pls help
    Thanks

    Hi,
    Please run this sql statement in the SQL session. This way you will get the line number where the problem is happening.
    The error seems to be because the column in the select is not in the group by clause.
    Thanks,
    Sharmila

  • SQL problem with JSP

    In sql statements with JSP. Heres the deal:
    Access database:
    Tablename: EVENT
    FieldName: event_id
    DataType: Number
    I want to compare the event_id to an integer variable called "var" in a WHERE clause in an SQL statement through a JSP.
    String query = "SELECT * FROM EVENT WHERE EVENT.event_id = 'var' ";
    It says "Data type mismatch in criteria expression."
    Any Suggestions? I thought this should be straight forward! am i missing something?

    if i am reading correctly "var" is an int variable correct? If this is the case then the following will work;
    String query = "SELECT * FROM EVENT WHERE EVENT.event_id = " + Interger.toString(var) ;
    Hope that helps ( and i hope i read your problem correctly)

  • Reports Printing Dupes but not a SQL Problem

    I have a query that is not linked to any other query or group in my Data Model view. I ran the same query in TOAD and the correct results printed, however, when, I put the same query in the Data Model view it prints dupes. I have a repeating frame around the columns so that the entire recordset will print. Has anyone ever seen this before? I do not know what to look at because the SQL is running fine agains the database and there are no links that could cause the data output to have problems. There are multiple frames with separate queries, but they are not above and under this particular group. This group is the only one that is printing dupes. The frames are not overlapping or anything like that.

    Every group can have 3 lines only;
    Length(Detail01:A000001)<=16
    indicate:
    select Length('Detail01:'||'A000001') into d_len_1 from dual;
    d_len_1 must <=16
    Length(Detail02:A0002 A00003)<=22
    indicate:
    select Length('Detail02:'||'A0002'||' '||'A00003') into d_len_2 from dual;
    d_len_2 must <=22
    Length(Detail03:A00004 A00005)<=22
    indicate:
    select Length('Detail03:'||'A00004'||' '||'A00005')<=22 into d_len_3 from dual;
    d_len_3 must <=22
    Every record in this table can be used for one times;

  • Strange SQL problem (order by fieldname@text)

    Hi all,
    I 'm taking a strange problem in Oracle 9i.
    Why does this query work correctly? (look the order by clause)
    SELECT foo1,
    FROM vw_prat_vend1
    WHERE 1=1
    AND (ce_vcod = '30888.03P34')
    AND (TRIM (ce_piva) = '01931450363')
    AND ( ce_dofl IN ('VAR') )
    ORDER BY cd_prat@text
    It seems that Oracle ignores it.
    In the 11g version the same query goes wrong.
    Thank you.

    Indeed, very strange.
    I cannot come up with an explanation
    SQL> Select distinct object_type from user_objects Order by object_type@foofoo desc
    OBJECT_TYPE       
    VIEW              
    TYPE BODY         
    TYPE              
    TRIGGER           
    TABLE             
    SYNONYM           
    SEQUENCE          
    SCHEDULE          
    RULE SET          
    RULE              
    QUEUE             
    PROCEDURE         
    PACKAGE BODY      
    PACKAGE           
    LOB               
    JOB               
    JAVA SOURCE       
    JAVA CLASS        
    INDEX             
    FUNCTION          
    EVALUATION CONTEXT
    DATABASE LINK     
    22 rows selected.
    BANNER                                                                         
    Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production   
    1 row selected.

  • Strange SQL Problem

    I'm having a really strange problem and I hope someone here can explain why this is happening:
    I run this query, it should only return segment2 if the first character is alpha and the 2nd character is number.
    SELECT
    gcc.segment2
    ,SUBSTR(apps.gl_flexfields_pkg.get_description_sql( gcc.chart_of_accounts_id,2,gcc.segment2),1,40) segment2_desc
    FROM gl_code_combinations gcc
    WHERE (REGEXP_LIKE(substr(segment2, 1,1), '^[a-zA-Z]*$') AND
    SUBSTR(segment2, 2,1) NOT LIKE '%[^a-zA-Z]%');
    So it returns the correct results segment along with the description:
    X01234
    X12345
    X54321
    etc.
    Run same query with enabled _flag added to where clause and expressions don’t work:
    SELECT
    gcc.segment2
    ,SUBSTR(apps.gl_flexfields_pkg.get_description_sql( gcc.chart_of_accounts_id,2,gcc.segment2),1,40) segment2_desc
    FROM gl_code_combinations gcc
    WHERE (REGEXP_LIKE(substr(segment2, 1,1), '^[a-zA-Z]*$') AND
    SUBSTR(segment2, 2,1) NOT LIKE '%[^a-zA-Z]%')
    AND gcc.enabled_flag = 'Y';
    Returns a list of just one segment value with it's description:
    DT101
    DT101
    etc.
    Why is this happening? I'm intending to use this query in a value set. Just trying it out in Toad and SQL Developer right now.

    Hi,
    MinnieB wrote:
    I'm having a really strange problem and I hope someone here can explain why this is happening:
    I run this query, it should only return segment2 if the first character is alpha and the 2nd character is number.
    SELECT
    gcc.segment2
    ,SUBSTR(apps.gl_flexfields_pkg.get_description_sql( gcc.chart_of_accounts_id,2,gcc.segment2),1,40) segment2_desc
    FROM gl_code_combinations gcc
    WHERE (REGEXP_LIKE(substr(segment2, 1,1), '^[a-zA-Z]*$') AND
    SUBSTR(segment2, 2,1) NOT LIKE '%[^a-zA-Z]%');
    So it returns the correct results segment along with the description:
    X01234
    X12345
    X54321
    etc.
    Run same query with enabled _flag added to where clause and expressions don’t work:
    SELECT
    gcc.segment2
    ,SUBSTR(apps.gl_flexfields_pkg.get_description_sql( gcc.chart_of_accounts_id,2,gcc.segment2),1,40) segment2_desc
    FROM gl_code_combinations gcc
    WHERE (REGEXP_LIKE(substr(segment2, 1,1), '^[a-zA-Z]*$') AND
    SUBSTR(segment2, 2,1) NOT LIKE '%[^a-zA-Z]%')
    AND gcc.enabled_flag = 'Y';
    Returns a list of just one segment value with it's description:
    DT101
    DT101
    etc.
    Why is this happening? The value you're displaying is not the same as the value used in the regular expressions. The function get_description might return 'DT101' when its 3rd argument (segement2) is something like 'T101'.
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables involved, CREATE FUNCTION statements for any functions needed, and also post the results you want from that data.
    Feel free to simplify the problem. It looks like this whol;e question hinges on gcc.enabled_flag, gcc.segment2 and the value that get_description returns when that segment2 is an argument. In that case, you can post CREATE TABLE and INSERT statements for a single table with 3 columns: enabled_flag, segment2, and f (which is the same as your function results).
    Explain, using specific examples, how you get those results from that data.
    Always say which version of Oracle you're using (e.g., 11.2.0.2.0).
    See the forum FAQ {message:id=9360002}
    Edited by: Frank Kulash on Mar 1, 2013 11:19 AM
    Apparantly, I mis-read the problem. The reply above is appropriate for a question that makes sense, not what was posted. My apologies.

  • PL/SQL :: Problem With Large Number Computation.

    Greetings Experts,
    I am relatively new to Oracle-DB. And I have a question regarding PL/SQL. I was trying to find the factorial of a number 100 as this is the most common programming problem for the beginners. But when I tried to execute the same, I was getting weird result(~) instead of actual value, i. e. 100!. I would highly appreciate if you experts can guide me in this regard. I have posted the program herewith for your reference.
    SQL&gt; DECLARE
    2 X NUMBER := 100;
    3 INDX NUMBER := 1;
    4 BEGIN
    5 INDX := X;
    6 WHILE X &gt; 1
    7 LOOP
    8 X := X - 1;
    9 INDX := INDX * X;
    10 END LOOP;
    11 DBMS_OUTPUT.PUT_LINE('The Factorial of 100 is : '
    12 || INDX || '.');
    13 EXCEPTION
    14 WHEN OTHERS THEN
    15 RAISE_APPLICATION_ERROR(-20156,SUBSTR(SQLERRM,1,500));
    16 END;
    17 /
    The Factorial of 100 is : ~.
    PL/SQL procedure successfully completed.
    TIA.
    Hex.

    This is PL/SQL and works up to 1463:
    SQL> CREATE OR REPLACE FUNCTION factorial(
      2     pNumber   IN   NUMBER)
      3     RETURN VARCHAR2
      4  IS
      5     f   VARCHAR2(32767);
      6
      7     FUNCTION multiply(
      8        pX   IN   VARCHAR2,
      9        pY   IN   VARCHAR2)
    10        RETURN VARCHAR2
    11     IS
    12        xManLength   PLS_INTEGER;
    13        yManLength   PLS_INTEGER;
    14     BEGIN
    15        xManLength := LENGTH(RTRIM(pX, '0'));
    16        yManLength := LENGTH(RTRIM(pY, '0'));
    17        RETURN    TO_CHAR(TO_NUMBER(SUBSTR(pX, 1, xManLength)) * TO_NUMBER(SUBSTR(pY, 1, yManLength)))
    18               || RPAD('0', LENGTH(pX) - xManLength + LENGTH(pY) - yManLength, '0');
    19     END multiply;
    20  BEGIN
    21     f := 1;
    22
    23     FOR n IN 1 .. pNumber LOOP
    24        f := multiply(f, n);
    25     END LOOP;
    26
    27     RETURN f;
    28  END factorial;
    29  /
    Funktion wurde erstellt.
    SQL>
    SQL> SELECT 1463, factorial(1463) AS fact
      2    FROM DUAL;
          1463
    FACT
          1463
    229804713272032214845417447319796313384000000000000000000000000000000000000000000000000000000000000000000000000000000000
    000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
    000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
    000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
    000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
    000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
    000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
    000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
    000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
    000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
    000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
    000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
    000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
    000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
    000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
    000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
    000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
    000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
    000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
    000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
    000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
    000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
    000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
    000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
    000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
    000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
    000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
    000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
    000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
    000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
    000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
    000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
    000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
    00000000000000000000000000000000000000

Maybe you are looking for