PL/SQL data input validation

Does anyone have example pl/sql code to validate input of a phone number into a table of, for example, CUSTOMERS ?

Mohit,
To be clear....are you using Application Express, or are you using the PL/SQL toolkit?

Similar Messages

  • JTextfield input Date convert to java.sql.Date

    Hi. I have a textfield for users to input date in 'dd/mm/yyyy' format and I would like to format this input into java.sql.Date to be stored into a database. How should I go about doing that ?
    I did the following:
    SimpleDateFormat formatDate = new SimpleDateFormat("dd/mm/yyyy");
    java.util.Date invoiceDate = formatDate.parse(jTextField3.getText());
    java.sql.Date sqlDate = new java.sql.Date(invoiceDate.getTime());and when I input into jTextField3 the value '28/05/2008' , I found in my database '2008-01-28'. January and May is a few months off and is totally not what I wanted.

    Hi you did you code perfect, but you need to change the pattern for formatting the Date
    dd - date
    mm - minute
    yyyy - year
    here you are parsing month as minute, so the output may wrong..!
    If you need to format properly
    please use the below pattern
    {color:#0000ff}SimpleDateFormat formatDate = new SimpleDateFormat("dd/MM/yyyy");{color}

  • Date and Time Input Validation

    Anyone know a good way to validate date and time that a user is entering on the screen.  Our users want to enter AM and PM time vs. Military time. 
    Also, since Input fields don't have an "onBlur" command, what are other companies using in java script.

    What type of DATE/TIME validation are you looking for?
    If you want to validate the format you could simply set the type to date/time and enable the dovalidate attribute to "TRUE".
    for getting onBlur, onChange, etc for your input field you can use bsp:findandreplace.
       <%
      tmp_string =`<input onBlur="javascript:yourjsfunction();"`.
          %>
          <bsp:findAndReplace find    = "<input"
                              replace = "<%= tmp_string %>" >
            <htmlb:inputField id        = "myInputField2"
                              value     = "12345"
                              alignment = "left" />
          </bsp:findAndReplace>
    (courtesy Ulli Hoffmann)
    Hope this helps.
    Regards
    Raja

  • Input validation in an OO-friendly fashion

    Okay, so "input validation" may sound a bit like an issue for the security division of the forum, but I'm concerned with the most OO way to verify the inputs of users. The situation is that I have about five or six different blanks in a GUI (not that it matters) where a user can input something to change the GUI's model. The GUI's model is, itself, an interface and therefore supports pluggability.
    Now, each of the inputs has potentially different "policies" or business rules for what can be entered. For example, one may be a date, etc. You guys know what I mean. Anyway, I know that I could just have some validation method for every field, but this doesn't seem to be very OO-esque.
    I'd like to have some kind of an interface called "StringValidator" or something that would have a method "validate()," but I don't know how this would play out. Maybe I could have a map in my GUI model where the key is the field name and the associated value is an appropriate implementation of StringValidator? I don't know, though. Even though it would be easier to implement five specific methods, one for each field, I'd rather not.
    If I use some kind of StringValidator, maybe I could require a method that returns an array of Strings with all illegal forms, but then again, that's bad form...
    I really just don't know.
    So, in summary, my two questions are as follows:
    1. What is the best way to implement an OO, easily scalable way to validate Strings in my app?
    2. How do I protect against things like SQL statements, HTML scripts, etc.? I know I should (in many cases), but I don't know how to.
    Thanks for any help, and for wading through that description.
    theAmerican
    PS I just remembered something about some Scanner class or something. Maybe that would help?

    It depends quite what you're doing; if you're working with a db then using prepared statements would handle all the escaping for you, but if you allow the users to input raw SQL then you can't realistically stop them from screwing things up.
    Similarly if you're having the users create html somewhere, then the more flexibility there is the harder it is to control. You don't have to worry about scripting if you're just using JLabel to render the html as it doesn't support it; if you're creating a web UI then you may have to.
    Pete

  • ORA-01820: format code cannot appear in date input format

    I don't understand why I am getting the error below. That should be valid, no?
    TIA for any insight.
    Connected to:
    Oracle9i Enterprise Edition Release 9.2.0.7.0 - Production
    With the Partitioning, OLAP and Oracle Data Mining options
    JServer Release 9.2.0.7.0 - Production
    SQL>
    SQL> select to_date('2004 01 3','yyyy mm w') from dual;
    select to_date('2004 01 3','yyyy mm w') from dual
    ERROR at line 1:
    ORA-01820: format code cannot appear in date input format
    SQL>
    SQL> select to_char(sysdate,'yyyy mm w') from dual;
    TO_CHAR(S
    2008 08 1

    LC,
    ORA-01820:     format code cannot appear in date input format
    Cause:     A date specification contained an invalid format code. Only the following may be specified when entering a date: year, month, day, hours, minutes, seconds, Julian day, A.M./P.M. and B.C./A.D.
    Action:     Remove the invalid format code from the date specification.
    Looking at the cause,you can't use a format code like W in the date format for converting a text to date. To_date doesn't accept it.
    Aman....

  • How to use java.sql.Date ?

    hi there:
    I used
    ps.setDate(27, new java.sql.Date(new java.util.Date().getTime()));
    ps.executeUpdate();
    in my code to insert the current date to the 27th column of one table, this column's type is DATE, the database is ORACLE. However, I got the error like this one: ORA-01843: not a valid month.
    I think I incorrectly used the java.sql.Date API to cause this error. So anyone can tell me how to use it correctly?
    Thanks for the answers,
    Sway

    Other columns are all VARCHAR2 type;
    The oracle error message indicated that this is a
    date-related one. 27th are the only column using DATE
    So I came to draw my conclusion that the SQL might be
    wrong.Except that if, for example, the date column is actually at index 26 then Oracle might try to convert the string being passed in (at 26) as a date. But it isn't a date. So then oracle is going to throw an exception indicating that something is wrong - like that the month is invalid.

  • Error in SQL Date Format Mask

    Hi,
    I am facing problem in validation data in FDQM.
    When I am trying to validate data,I am getting an error as ' An Error occured.Please verify that SQL Date Format Mask is correct'
    The current Date Format in our application is YYYYMMDD.
    I did not have this problem earlier in validating data.This problem is occuring now only and also this error is coming for few entities only.
    Could any one suggest me on how this can be resolved.
    Thanks

    Hi Kelly,
    I checked periods in control tables and there are no duplicates.
    The Period Date Format Mask is MMM-YYYY where as the SQL Date Format Mask is YYYYMMDD.
    These settings are there since the time I created application.Has it got anything to do with database.
    Appreciate your quick response
    Regards,
    Mrudula

  • Mapping SQL data types (especially SMALLINT) to Java classes

    I want to know the reason for a certain pair of exceptions in JDBC�s mapping of SQL data types to Java classes.
    Sun�s web site ( http://java.sun.com/j2se/1.4.2/docs/guide/jdbc/getstart/mapping.html ), Sybase�s site, and other sites contain mappings from SQL data types to Java primitive data types and/or Java classes. On that Sun web page, Section 9.9.1 maps mostly to Java primitive data types, and Section 9.9.3 maps mostly to Java classes. For the SQL data types that map to both primitive data types and classes, the class is typically the wrapper class of the primitive data type. For example, SQL�s DOUBLE data type maps to both the double primitive data type and its wrapper class (Double). However, Section 9.7 of that Sun web page says that there are exceptions for SQL�s TINYINT and SMALLINT. As expected, they map to the byte and short primitive data types, but they map to the Integer class, not the Byte and Short classes (which are the wrapper classes for byte and short). The web page does not state the reason for this pair of exceptions. It seems to me that SMALLINT data would either work for both short and Short or fail for both short and Short. I don�t see why it would work for short but fail for Short (as the web page implies).
    Can anybody think of a reason for the pair of exceptions? Thanks.

    ghs wrote:
    1) If a DBMS deals with the short and byte primitive data types (as the various web pages imply that it does), then why would it not deal with the Short and Byte wrapper classes?As another guess, because conversions get a little weird in java. Or at least they did in the past. As I recall (with not a lot of clarity) it is possible to do something like pass a perfectly valid string value into a short and get an exception. Whereas using Integer and then converting to Short works.
    Keep in mind that these are guesses.
    3) What I really want to know is this: If I use wrapper classes of Short and Byte (instead of Integer), what will be the harmful consequences (IF ANY)? So far, I have done some trivial testing with a Short for a SMALLINT column (I have not yet tried any TINYINT columns), and it seems to be working.I considered it risky to not test all target databases and drivers.
    Obviously testing will reveal problems.
    If you don't want to test then you might want to stick with integers.

  • Exporting SQL data to Excel 2010 files - Excel sets all columns to DT_WSTR, ignores numeric or currency

    It looks like this has been a problem since forever, but I'm hoping someone has a solution.  I'm exporting SQL data to an .xlsx file.  I have the columns in my query set to the appropriate values, e.g. SELECT Cast(column1 AS nvarchar()) 'column1',
    Cast(column2 as currency) 'column2'.  I have a spreadsheet and I've set the data type for each column.  I have an OLEDB connection manager with the connection string of
    Data Source=C:\MyFile.xlsx;Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties="Excel 12.0;";  When I look at the Advanced Editor of my OLE DB Destination Component, I see that all the Input Columns are of the correct datatype, but
    all the External Columns are of datatype DT_WSTR.  
    How can I get my numeric, currency, date fields to be written to Excel as numeric, currency, date?  Right now they all get written as text, any numbers get single quotes put in front of them so they are treated as text.  
    I'm using SSIS 2008 R2.
    I don't get it, SQL and Excel are both Microsoft, why is it so hard to get them to work together?!

    Hi,
    converting to DT_WSTR because you are converting this into nvarachar in your select statement in oledb source.
    are you looking into the oledb destination or Excel destination for data types.
    please remove the casting from your select and create the new table as showing in the following snapshot:
    http://zaimraza.wordpress.com/

  • Error IllegalArgumentException in java.sql.Date used PreparedStatement

    I'm found bug (probably). I have a table with column DATA type. Now I connect do database use JDBC in Java, and create PreparedStatement:
    PreparedStatement stmt = conn.prepareStatement("insert into \"Appuser\" (\"IDUser\", \"createAccountDate\") values (?,?)");
    Column createAccountDate is a DATA type. And now I invoke:
    stmt.setInt(1, 1);
    stmt.setInt(2, new java.sql.Date(-2508265596206959779));
    stmt.execute();
    and last line return exception:
    java.lang.IllegalArgumentException
    at sun.util.calendar.ZoneInfo.getOffset(ZoneInfo.java:368)
    at oracle.jdbc.driver.DateCommonBinder.zoneOffset(OraclePreparedStatement.java:15423)
    at oracle.jdbc.driver.DateCommonBinder.setOracleCYMD(OraclePreparedStatement.java:15561)
    at oracle.jdbc.driver.DateBinder.bind(OraclePreparedStatement.java:15641)
    at oracle.jdbc.driver.OraclePreparedStatement.setupBindBuffers(OraclePreparedStatement.java:2866)
    at oracle.jdbc.driver.OraclePreparedStatement.processCompletedBindRow(OraclePreparedStatement.java:2151)
    at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3280)
    at oracle.jdbc.driver.OraclePreparedStatement.execute(OraclePreparedStatement.java:3390)
    at // line stmt.execute();
    Another values of Data are OK. Probably value -2508265596206959779 cause that error.
    It's a bug? Better will be SQLException if it is a bug.
    My configuration:
    Oracle Database 10g Express Edition Release 10.2.0.1.0 - Product
    PL/SQL Release 10.2.0.1.0 - Production
    CORE     10.2.0.1.0     Production
    TNS for 32-bit Windows: Version 10.2.0.1.0 - Production
    NLSRTL Version 10.2.0.1.0 - Production
    Windows XP SP3, Java 1.6.0_20,
    ojdbc14.jar, Oracle JDBC Driver version - "10.2.0.1.0XE

    Probably value -2508265596206959779 cause that errorMaybe, whatever that .date( -ReallyLotsOfmSec ) date values is, pretty sure its outside the valid values for a date column, 4712BC to 9999AD is the min/max.
    Perhaps the java code can handle it, an oracle date type can not.

  • Calling Stored Procedure with a DATE input parameter

    Hi. A question about Date input parameters when calling a stored procedure...
    I have a procedure that takes a DATE parameter as input. I would like that DATE value to include a Time element.
    My Application Module method takes an input parameter as java.util.Date (myParamDate) - which will preserve a time element(?).
    However when I create the CallableStatement, I'm trying to set the parameter using setDate like this (for param 5):
                st = getDBTransaction().createCallableStatement("begin cs_my_pck.request_values(?,?,?,?,?,?,?,?); end;", 0);           
                Connection myConn = st.getConnection();
                ArrayDescriptor myArrDesc  =  ArrayDescriptor.createDescriptor("CS_FIELD_TABT", myConn);
                Array sqlParamNameArray = new oracle.sql.ARRAY(myArrDesc, myConn, paramNames.toArray());
                Array sqlParamValueArray = new oracle.sql.ARRAY(myArrDesc, myConn, paramValues.toArray());
                Array sqlFilterNameArray = new oracle.sql.ARRAY(myArrDesc,myConn,filterNames.toArray());
                st.setString(1, repType);
                st.setObject(2, sqlParamNameArray);
                st.setObject(3,sqlParamValueArray);
                st.setObject(4,sqlFilterNameArray);
                java.sql.Date myRepDate = new java.sql.Date(myParamDate.getTime());
                st.setDate(5,myRepDate);
                System.out.println("Report Date = " + myRepDate.toString());
                st.setString(6,repUser);
                st.setString(7,repAttach);
                // set out param
                st.registerOutParameter(8, Types.NUMERIC);
                st.execute();I understand java.sql.Date does NOT include a Time element. But setDate() accepts only a java.sql.Date so my procedure parameter ends up with a zero time element.
    How do I call this procedure retaining the Time element?
    Thanks.

    It includes time element, if you want more precision go with timestamp.
    http://docs.oracle.com/javase/6/docs/api/java/sql/Date.html

  • Put java.sql.Date in correct format

    I need to put java.sql.Date in correct format to query an Oracle database.
    Here is my code:
            SimpleDateFormat formatter = new SimpleDateFormat("dd-MMM-yy");
            java.util.Date dateChosen = jXDatePicker1.getDate();
            String strDate = formatter.format(dateChosen);
            System.out.println("Date Chosen: " + strDate); // output is: 11-Feb-00
            java.util.Date parserDate = null;      
            try {
                parserDate = formatter.parse(strDate);
            } catch (ParseException re) {
                System.err.println("Exception caught: " + re.getMessage());
            // create java.sql.Date object
                java.sql.Date oraDate = new java.sql.Date(parserDate.getTime());
            System.out.println(oraDate);  // date is in this format: 2000-02-11
            System.out.println("formatted oraDate: " + formatter.format( oraDate ) ); // no good, stringIf I use formatter.format( oraDate ) I get the correct format (11-Feb-00) BUT it is no longer a sql Date, it is a String which can't be use.
    I have looked at the API and many other forum threads on this, any help would be greatly appreciated!

    In the class with the PreparedStatement, I pass the date like this:
    public class report extends javax.swing.JDialog {
         java.sql.Date newDate;
        public report(java.sql.Date passedOraDate, String passedtxtDate) {
            super();
            initComponents();
            setTitle("Report");
            setModal(true);
            newDate = passedOraDate;
            statusLabel.setText(passedtxtDate);
            System.out.println("passedtxtDate: " +passedtxtDate);       
            System.out.println("newDate: " +newDate);      
        }Here is the code that uses the actual PreparedStatement:
            try {
                // In my actual code I have all columns listed in query
                String query = "SELECT * FROM report WHERE repdate = ?";
                ps = conn.prepareStatement(query); // create a statement
                           ps.setDate(1, newDate); // set input parameter
                rs = ps.executeQuery();
                // extract data from the ResultSet
                ResultSetMetaData md = rs.getMetaData();
                int columns = md.getColumnCount();This is greatly edited to show relevant code!

  • Java, access database( mdb) and java.sql.date

    I having a problem querying my access database with user specified date the code is as follows
    //get results of income from database with respectto dates
         //so u first create the sql.date instances
         private void getResults(){
         String text1=from.getText();//text input is like this 01-01-2005
              String text2=to.getText();
         Date d1=new Date(Integer.parseInt(text1.substring(6)),Integer.parseInt(text1.substring(3,5)),Integer.parseInt(text1.substring(0,2)));
         JOptionPane.showMessageDialog(this,d1.toString());//traces date with 1900 added to year and 1 added to month
         try{
              //custom class DataSource used to connect to database
              Connection conn=DataSource.getConnection("RealFotoInc");
              PreparedStatement ps=conn.prepareStatement("select * from Members where date=?");
              ps.setDate(1,d1);
              ResultSet rs=ps.executeQuery();
              while(rs.next()){
                   System.out.println("going");
                   System.out.println("trial"+rs.getString(3));
         }catch(Exception se){
              JOptionPane.showMessageDialog(this,se);
         }and it prints out nothing I dont know what is wrong

    Whoever put that comment in there about "1900" and so on knew what had to be done. That "Date" class must be "java.sql.Date"; go and read the API documentation of that constructor you are using there. Then adjust the parameters you are passing to it accordingly.

  • SQL Server 2000 - Valid Binary datatype and valid character datatype:

    SQL Server 2000 - Valid Binary datatype and valid character datatype:
    Which is not a valid binary datatype :
    BIT , IMAGE, TMESTAMP
    Which is not a valid Character datatype :
    VARTEXT , BLOB , TEXT

    BOL 2014: "
    Data Types (Transact-SQL)
    SQL Server 2014 
    Data Type Categories
    Exact Numerics
     bigint
     numeric
     bit
     smallint
     decimal
     smallmoney
     int
     tinyint
     money 
    Approximate Numerics
     float
     real
    Date and Time
     date
     datetimeoffset
     datetime2
     smalldatetime
     datetime
     time
    Character Strings
     char
     varchar
     text
    Unicode Character Strings
     nchar
     nvarchar
     ntext 
    Binary Strings
     binary
     varbinary
     image
    Other Data Types
     cursor
     timestamp
     hierarchyid
     uniqueidentifier
     sql_variant
     xml
     table
     Spatial Types "
    LINK: http://msdn.microsoft.com/en-us/library/ms187752.aspx
    Kalman Toth Database & OLAP Architect
    SQL Server 2014 Database Design
    New Book / Kindle: Beginner Database Design & SQL Programming Using Microsoft SQL Server 2014

  • SQL date format

    Hi,
    Assume the records in a legacy oracle data base have an attributes called date which has the format as 'Dy DD-Mon-YYYY HH24:MI:SS' (e.g. 21-Apr-1998 21:18:27).
    In my Java application, assume that I provide a GUI for users to input date as
    "DD-MM-YYYY" (e.g. 21-04-1998).
    How can I make a SQL statement to find all records of the date "21-Apr-1998"?
    Regards,
    Pengyou

    Hi,
    I would like to clarify my question
    The oracle table that I have has a date column of the
    format (oracle default one)
    as 'DD-Mon-YYYY HH24:MI:SS' (e.g. 21-Apr-1998
    21:18:27).Just to be sure.....
    The type of the column is "date". It is NOT "varchar", "varchar2", "char" or something else.
    If so then the the column does not have a format. It is value that does not change regardless of format. What you see is the result of an oracle tool (probably sqlplus) converting it to that format.
    And as discussed you use prepared statement.
    However you MUST use a range check since you have a timestamp (not a date) and you want to compare it to a date.
    So the java would look something like this....
      String sql = "select field1 from mytable where adate >= ? and adate < ?";
      SimpleFormatDate dt = ....
      java.util.Date d = dt.parse("...");
      java.sql.Date t1 = new java.sql.Timestamp(d.getTime());
      java.sql.Date t2 = // Use calendar to add one day
      PreparedStatement ps = ...(sql)
      ps.setDate(t1);
      ps.setDate(t2);
      ResultSet rs = ps.executeQuery();Note that you MUST use exclusion and inclusion at either end (">=" and "<"). If you don't then you run the risk of including something twice or excluding something.
    And the above is explained in numerous other posts.

Maybe you are looking for

  • Primary Key Constraint missing in Oracle Standard Tables OE_ORDER_HEADERS_ALL

    Dear Legends, In our Production and Test Environment R12.1.3 HP-UX 64bit While checking some of the constraints and doing for an ALTER Table add foreign key we came to know that the HEADER_ID primary constraint(OE_ORDER_HEADERS_ALL_PK) is missing for

  • Uploading password protected site

    December 18th...need some help folks. I have a pretty big site: monmouthboatclub.org which I update daily for my boat club..... I have a members only, password protected site, where I put my membership directory with telephone numbers, etc. as well a

  • Order Entry Schema for 10G Express Edition

    I cannot find the schemas for the tutorial Order Entry - I did find the 8i version from several years ago but they do not seem to work - Where can I find the SQL script for installing OE schemas for 10G Express Edition Thanks

  • How to move channel calibration to another PC

    Hello NI fans, it's possible to move channel calibration data from one computer to another one? I mean some export and import configuration data. I really need this feature, because for now I have whole system for calibration on my desk in the lab, w

  • How do I delete Facebook contacts

    I'm trying to get rid of Facebook birthdays and contacts on both my iPhone 4S and ipad. Settings- FB- Allow these Apps to use your account is turned off and updated but nothing changes