Date in apex

The below given function gives result as 1 in apex when the max_date and min_date are same. But when run on toad it gives result 0.
CREATE  FUNCTION D_DIFF (max_date STRING, min_date STRING)
RETURN PLS_INTEGER IS
BEGIN
  RETURN TO_DATE(max_date) - TO_DATE(min_date);
EXCEPTION
  WHEN OTHERS THEN
  RETURN NULL;
END d_diff;Please advise.
Sanjay

Hi Sanjay,
The main problem is with date handling. Following are the two suggestions to follow:
1) Pass date in particular format in STRING parameters (say 'DD-MON-RR'), then the function will be:
create or replace FUNCTION D_DIFF (max_date STRING, min_date STRING)
RETURN PLS_INTEGER IS
BEGIN
  RETURN TO_DATE(max_date,'DD-MON-RR') - TO_DATE(min_date,'DD-MON-RR');
EXCEPTION
  WHEN OTHERS THEN
  RETURN NULL;
END d_diff;2) Directly pass date as parameters to the function, then the function will be:
create or replace FUNCTION D_DIFF (max_date DATE, min_date DATE)
RETURN PLS_INTEGER IS
BEGIN
  RETURN (max_date - min_date);
EXCEPTION
  WHEN OTHERS THEN
  RETURN NULL;
END d_diff;REMEMBER: TO_DATE(str,fmt)
1) TO_DATE converts str of CHAR, VARCHAR2, NCHAR, or NVARCHAR2 datatype to a value of DATE datatype. The fmt is a datetime model format specifying the format of str. If you omit fmt , then str must be in the default date format.
2) The default date format is determined implicitly by the NLS_TERRITORY initialization parameter or can be set explicitly by the NLS_DATE_FORMAT parameter.
Hope it helps!
Regards,
Kiran

Similar Messages

  • Using htp.p for print dynamic data in apex region make my page slow?

    Hi, everyone!!! My name is Rafael, and...
    I search in the web and in this forum but i can´t find a answer for my doubt.
    Using the procedure htp.p for print dynamic data in apex region through on demand process , this will leave my webpage slow to load when the user access?
    Example:
    For build a menu in my webpage, it´s read a function in the database that returns variable string, so by a demand process this string is obtain and print in a web page using htp.p.
    I notice that this practice causes slow to load the data on the page.
    This is it...
    If someone help me, thanks...
    bye and Happy new Year!!!
    Edited by: user9518141 on 26/12/2009 17:19

    Hi,
    Try commenting out the function call and print some sample text in the htp.p like htp.p('Hello world..');
    I think the function call is probably taking a lot of time .. not htp.p.
    I have used htp.p to print out values dynamically in a lot of situations and have not ever come across any performance issues.It could be a problem with the function you are calling.
    Thanks,
    Rajesh.

  • Re: Problem providing download link for BLOB data in apex report

    Hi Don,
    Your solution below worked but in the download option i only see save but not open for PDf file in the blob. Please let me know if you have any suggestion to achieve it
    Thanks
    Jo
    Problem providing download link for BLOB data in apex report 
    591953 Nov 19, 2008 1:55 PM (in response to 660436)
    Currently Being Moderated
    Good morning,
    Here is how I have solved this problem.
    1. The select statement in the sql for the report should not include the BLOB column. I decided to select only 2 columns, the column that has the key and the column with the filename.
    2. On the first column ( the primary key ) I put in the format statement that was simply DOWNLOAD:TABLENAME:BLOB_COLUMN:PRIMARY_KEY
    This works. I believe that the Oracle error I was getting was because I was trying to apply this format statement to the actual BLOB column.
    So, it appears that you can use any of the columns in the report to hold the DOWNLOAD format statement since in the format statement, you are defining the BLOB table, BLOB column and the primary key into that column.
    Hope this helps,
    Don.

    Branched out from a years old thread.
    user3003326 Don't post to old threads, please.

  • Release date for apex 4.2?

    Does anyone know the release date of Apex 4.2?
    I've tested the new mobile features in apex.oracle.com and I'm looking forward to getting them into our production system.
    Regards.
    Carlos.

    Hold your breath through OOW, then let go & be patient.
    Dates never seem to be announced until it happens. My guess is it isn't far
    http://www.grassroots-oracle.com/2012/07/thursdays-thought-apex-42.html

  • How to import legacy data into apex tables

    Hi All,
    Please tell me How to import legacy data into apex tables.
    Thanks&Regards,
    Raghu

    SQL WorkshopUtilitiesData Workshop...
    you can import the data from already exported as (text/csv/xml) data
    Note: the table name and column name should be equal if the table already Existing table.

  • Unable to load CSV data using APEX Data Load using Firefox/Safari on a MAC

    I have APEX installed on a Windows XP machine connected to an 11g database on the same Windows XP machine.
    While on the windows XP, using IE 7, I am able to successfully load a CSV spreadsheet of data using the APEX Data Load utility.
    However, if I switch to my MacBook Pro running OS X leopard, then login into same APEX machine using Firefox 2 or 3 or Safari 3, then try to upload CSV data, it fails on the "Table Properties" step when it asks you for the name of the new table and then asks you to set table properties, the table properties just never appear (they do appear in IE 7 on Windows XP) and if you try to hit the NEXT button, you get error message: "1 error has occurred. At least one column must be specified to include in new table." and of course, you can't specify the any of the columns because there is nothing under SET TABLE PROPERTIES in the interface.
    I also tried to load data with Firefox 2, Firefox 3 (beta), and Safari 3.1, but get same failed result on all three. If I return to the Windows XP machine and use IE 7.0, Data Load works just fine. I work in an ALL MAC environment, it was difficult to get a windows machine into my workplace, and all my end users will be using MACs. There is no current version of IE for the MAC, so I have to use Firefox or Safari.
    Is there some option in Firefox or Safari that I can turn on so this Data Load feature will work on the MAC?
    Thanks for your help. Any assistance appreciated.
    Tony

    I managed to get this to work by saving the CSV file as Windows CSV (not DOS CSV), which allowed the CSV data to be read by Oracle running on Windows XP. I think the problem had to do with different character sets being used for CSV on MAC versus CSV on Windows. Maybe if I had created my windows XP Oracle database with Unicode as the default character set, I never would have experienced this problem.

  • How to insert data from APEX form into two tables

    Hi,
    I'm running APEX 4.1 with Oracle XE 11g, having two tables CERTIFICATES and USER_FILES. Some of the (useless) fields are cut to reduce information:
    CREATE TABLE CERTIFICATES
    CERT_ID NUMBER NOT NULL ,
    CERT_OWNER NUMBER NOT NULL ,
    CERT_VENDOR NUMBER NOT NULL ,
    CERT_NAME VARCHAR2 (128) ,
    CERT_FILE NUMBER NOT NULL ,
    ) TABLESPACE CP_DATA
    LOGGING;
    ALTER TABLE CERTIFICATES
    ADD CONSTRAINT CERTIFICATES_PK PRIMARY KEY ( CERT_ID ) ;
    CREATE TABLE USER_FILES
    FILE_ID NUMBER NOT NULL ,
    FILENAME VARCHAR2 (128) ,
    BLOB_CONTENT BLOB ,
    MIMETYPE VARCHAR2 (32) ,
    LAST_UPDATE_DATE DATE
    ) TABLESPACE CP_FILES
    LOGGING
    LOB ( BLOB_CONTENT ) STORE AS SECUREFILE
    TABLESPACE CP_FILES
    STORAGE (
    PCTINCREASE 0
    MINEXTENTS 1
    MAXEXTENTS UNLIMITED
    FREELISTS 1
    BUFFER_POOL DEFAULT
    RETENTION
    ENABLE STORAGE IN ROW
    NOCACHE
    ALTER TABLE USER_FILES
    ADD CONSTRAINT CERT_FILES_PK PRIMARY KEY ( FILE_ID ) ;
    ALTER TABLE CERTIFICATES
    ADD CONSTRAINT CERTIFICATES_USER_FILES_FK FOREIGN KEY
    CERT_FILE
    REFERENCES USER_FILES
    FILE_ID
    NOT DEFERRABLE
    What I'm trying to do is to allow users to fill out all the certificate data and upload a file in an APEX form. Once submitted the file should be uploaded in the USER_FILES table and all the fields along with CERT_ID, which is the foreign key pointing to the file in the USER_FILES table to be populated to the CERTIFICATES table. APEX wizard forms are based on one table and I'm unable to build form on both tables.
    That's why I've created a view (V_CERT_FILES) on both tables and using INSTEAD OF trigger to insert/update both tables. I've done this before and updating this kind of views works perfect. Here is where the problem comes, if I'm updating the view all the data is updated correctly, but if I'm inserting into the view all the fields are populated at CERTIFICATES table, but for USER_FILES only the fields FILE_ID and LAST_UPDATE_DATE are populated. The rest three regarding the LOB are missing: BLOB_CONTENT, FILENAME, MIMETYPE. There are no errors when running this from APEX, but If I try to insert into the view from SQLDeveloper, I got this error:
    ORA-22816: unsupported feature with RETURNING clause
    ORA-06512: at line 1
    As far as I know RETURNING clause in not supported in INSTEAD of triggers, although I didn't have any RETURNING clauses in my trigger (body is below).
    Now the interesting stuff, after long tracing I found why this is happening:
    First, insert is executed and the BLOB along with all its properties are uploaded to wwv_flow_file_objects$.
    Then the following insert is executed to populate all the fields except the BLOB and it's properties, rowid is RETURNED, but as we know RETURNING clause is not supported in INSTEAD OF triggers, that's why I got error:
    PARSE ERROR #1918608720:len=266 dep=3 uid=48 oct=2 lid=48 tim=1324569863593494 err=22816
    INSERT INTO "SVE". "V_CERT_FILES" ( "CERT_ID", "CERT_OWNER", "CERT_VENDOR", "CERT_NAME", "BLOB_CONTENT") VALUES (:B1 ,:B2 ,:B3 ,:B4, ,EMPTY_BLOB()) RETURNING ROWID INTO :O0
    CLOSE #1918608720:c=0,e=11,dep=3,type=0,tim=1324569863593909
    EXEC #1820672032:c=3000,e=3168,p=0,cr=2,cu=4,mis=0,r=0,dep=2,og=1,plh=0,tim=1324569863593969
    ERROR #43:err=22816 tim=1324569863593993
    CLOSE #1820672032:c=0,e=43,dep=2,type=1,tim=1324569863594167
    Next my trigger gets in action, sequences are generated, CERTIFICATES table is populated and then USER_FILES, but only the FILE_ID and LAST_UPDATE_DATE.
    Finally update is fired against my view (V_CERT_FILES), reading data from wwv_flow_files it populates BLOB_CONTENT, MIMETYPE and FILENAME fields at the specific rowid in V_CERT_FILES, the one returned from the insert at the beginning. Last, file is deleted from wwv_flow_files.
    I'm using sequences for the primary keys, this is only the body of the INSTEAD OF trigger:
    select user_files_seq.nextval into l_file_id from dual;
    select certificates_seq.nextval into l_cert_id from dual;
    insert into user_files (file_id, filename, blob_content, mimetype, last_update_date) values (l_file_id, :n.filename, :n.blob_content, :n.mimetype, sysdate);
    insert into certificates (cert_id, cert_owner, cert_vendor, cert_name, cert_file) values (l_cert_id, :n.cert_owner, :n.cert_vendor, :n.cert_name, l_file_id);
    I'm surprised that I wasn't able to find a valuable source of information regarding this problem, only MOS note about running SQLoader against view with CLOB column and INSTEAD OF trigger. The solution would be to ran it against base table, MOS ID 795956.1.
    Maybe I'm missing something and that's why I decided to share my problem here. So my question is how do you create this kind of architecture, insert into two tables with a relation between them in APEX ? I read a lot in the Internet, some advices were for creating custom form with APEX API, create a custom ARP, create two ARP or create a PL/SQL procedure for handing the DML?
    Thanks in advance.
    Regards,
    Sve

    Thank you however I was wondering if there was an example available which uses EJB and persistence.

  • Backing up Data in Apex

    Hello,
    Please does anyone knows how I could back up vital data in my application. How can I set up back up process whenever a user wants to close/log out from the application.
    Is it possible in Apex
    Thanks

    Chariot,
    All of the data is in your database, so regular backups of your database are all that is needed to protect your data. You could also have your database in archivelog mode so that your data is protected pretty much up to the minute so than with just cold backups. Which is about as close as you can get to "as when the user logs out"
    On a side note users, do not always log out of apps, they sometimes just simply close the browser window which you cannot protect against.
    Justin

  • How to fetch data to APEX Report using stored procedure?

    hi all,
    i am making a report in APEX. user selects two dates and clicks GO button - i have a Stored Procedure linked to that result region so Stored Procedure gets called.
    my stored procedure does the following -
    using specified dates (IN) i do query and put data into a table (this table has been created only for this report) -
    i want to show all these data i entered into the table on my APEX report in the same procedure call. can i use ref cursor to return? how to do that?
    currently, i use another button in APEX which basically fetches all data from table. basically, user clicks one button to generate report and then another button to get report. which is not desirable at all :(
    i m using APEX      3.1.2.00.02 and Oracle 10 database.
    pls let me know if you need further clarification of the problem. thanks in advance.
    regards,
    probashi
    Edited by: porobashi on May 19, 2009 2:53 PM

    Thanks Tony.
    I am not sure what you meant by >> change the report to be based off of a query returning sql statement, no need to keep that table around.... >>
    Here's my stored procedure
    create or replace
    PROCEDURE ABC_PROC (
    START_DATE IN DATE,
    END_DATE IN DATE
    AS
    RULE_REC MTG_OFFICER_FORECAST%ROWTYPE;
    TYPE REF_CURSOR IS REF CURSOR;
    TCUR REF_CURSOR;
    BEGIN
    DELETE FROM ABC_REPORT;
    OPEN TCUR FOR
    SELECT ABC_FORECAST.*
    from MTG_OFFICER_FORECAST , MTG_USERS
    WHERE MTG_OFFICER_FORECAST.NBR_OFFICER = MTG_USERS.NBR_OFFICER AND
    MTG_OFFICER_FORECAST.NBR_INSTITUTION = MTG_USERS.NBR_INSTITUTION;
    LOOP
    FETCH TCUR INTO RULE_REC;
    EXIT WHEN TCUR%NOTFOUND;
    INSERT INTO ABC_REPORT( NBR_OFFICER, OFFICER_NAME, FORECAST_NBR_LOANS, FORECAST_LOAN_AMT, FORECAST_FEES,
    ACTUAL_NBR_LOANS, ACTUAL_LOAN_AMT, ACTUAL_FEES, RATIO_NBR_LOANS, RATIO_LOAN_AMT, RATIO_FEES, NBR_INSTITUTE )
    VALUES ( RULE_REC.NBR_OFFICER, RULE_REC.NAME_LOAN_OFFICER, RULE_REC.NBR_LOANS, RULE_REC.AMT_LOAN, RULE_REC.AMT_FEES,
    ACTUAL_NBR_LOANS, ACTUAL_LOAN_AMOUNT, ACTUAL_FEES, SUCCESS_RATIOS_NBR_LOANS_PERC, SUCCESS_RATIOS_LOAN_AMT_PERC, SUCCESS_RATIOS_FEES_PERC, RULE_REC.NBR_INSTITUTION );
    END LOOP;
    CLOSE TCUR;
    END ABC_PROC;
    Thanks,
    Probashi
    Edited by: porobashi on Jun 2, 2009 11:43 AM

  • Export and Import data in APEX

    I would like to know how to export the data from a table (6000 rows) and then I would like to import the data to another table. So I need to know how to do that process.. it's like to take a picture of the data in the old table and put them into the new table which it has new data.... so I can't just copy and paste...
    Thanks for your help... regards

    Dates do not have formats in the database(they are NOT saved as strings in the DB), but when you display them as string or export them then it has a format(coz its just a bunch of characters).
    The problem that you are facing is that the _date string in the csv file could not be converted by the database automatically into a date with its current date format settings(of the session).
    You need to set the date format of the session before you do the csv file import to the date format of the any date column strings in the file OR better match it with the date format of the client with which you exported the data.
    Set the same Date format before exporting as well as before importing.
    If its SQL Developer, you should be able to set it in Preferences(think its shown in that demo video)
    Do the same before importing too.
    Make sure that the datafile date column strings match the format of the importing session.
    If you want to pro grammatically set the date format use something like
    ALTER SESSION SET NLS_DATE_FORMAT = 'DD-MON-YY HH24.MI.SS';By the way, I think you should have asked this question in the SQL PLSQL forum, since it isn't particularly related to the Apex.
    Pls update your forum handle to something more friendlier than "user13344939"

  • Translate daynumber to date in APEX calendar

    Hello all,
    I've got a problem with a query for a calendar.
    My current customer has two tables to see wether or not an employee is available.
    One to see if an employee has parttime hours.
    EMP_CALENDAR
    - empno number
    - day_name varchar2(24)
    - day_number number
    - work_hours number
    - non_work_hours number
    Each employee gets 5 rows. One for each workday of the week showing 0 to 8 in the work_hours and non_work_hours column.
    And one to see if an employee has time-off.
    EMP_NON_AVAILABILITIES
    - empno number
    - start_date date with timestamp
    - duration number
    - description varchar2(255)
    My predicament is that I have to build screens with monthly calendars and week calendars to show both data.
    A query for the non-availabilities is easy enough, because I have a date field available. Using the timestamp I can show it correctly in a week calendar. But showing the part-time hours is a bit more challenging.
    Can anybody help me with this? I don't have a clue how to transform the EMP_CALENDAR data to integrate with the EMP_NON_AVAILABILITIES data when using an APEX calendar.
    The trouble is that I can translate a single date to a workday without a problem, but the APEX calendar only gives me 1 date; the CALENDAR_DATE. The other days of the week aren't available in an ITEM as far as I know.

    I've found a solution myself. I don't think it's very pretty, but it does the trick.
    select empno display_value
         , start_date return_value
      from emp_non_availabilities
    where empno = :APP_USER
    union all
    select empno display_value
         , dd.return_date return_value
      from emp_calendar
         , (SELECT (to_date(:P110_CALENDAR_DATE,'YYYYMMDD') + (LEVEL-7)) return_date
              FROM DUAL
           CONNECT BY LEVEL < 14) dd
    where day_number = to_char(dd.return_date,'D')
       and empno = :APP_USERI have to select 14 days from 7 days before :P110_CALENDAR_DATE until 7 days after, so I can get all data for my weekcalender. I don't know in advance which day of the week my CALENDAR DATE will be.

  • Importing Data into Apex 3.0.1

    I know that this question has a simple answer, but here goes. I know how to import data into oracle using sql loader and sql insert commands but can Apex import data into a blank application form with multiple rows of data to import.
    Like:
    U_Id L_Name F_Name City State zip
    15 Taylor Joe Atown Mi 42333
    16 Jones Jim NewT Ky 43211
    and 200 or 500 or more columes
    Again I know how to import into Apex to create a new form from a spreadsheet or access, but I don't know how to move raw data from a text file into Apex.
    Can this task be done.
    Thanks,
    Tim

    Tim,
    When an application is first created the developer has to specify the schema that will be used to parse (compile) all the code against. All you need to do is to use your existing knowledge of importing data into Oracle and import the data you want into the Parsing Schema of the application. Use Application Definition to find the parsing schema for your application.
    Sima

  • Change Color on selected date in APEX calendar

    Hello all,
    Does anyone know that how to change the background color of the date once it has been clicked?

    Swetha
    I created an application using Apex. It is a calendar application to show events that are happening. I ran into an issue with it
    If there is an event that occurs during an interval like August15 - August22, the event is shown only on August15, which is the first day of the event. I would like to show it in all days from August15-22.
    Here are the items coming from the page
    event_id number,
    employee_id number
    date_from date,
    date_to date,
    due_date date,
    act_id number,
    act_loc varchar2,
    reminder varchar2,
    frequency varchar2,
    division varchar2,
    event_status varchar2
    I am looking to write a process / procedure where it can show the same event on all the days it is occurring
    Thanks in advance
    Latha

  • Using Microsoft SSIS to pull data from APEX

    Just curious...is it possible to pull data out of APEX using SSIS? Has anyone done it? How do I establish the connection?

    You would pull data out of an Oracle database, APEX is just the development tool like .nyet and Forms... What exactly are you looking to do?
    Thank you,
    Tony Miller
    Webster, TX
    You can get more with a kind word and a two-by-four than you can with just a kind word
    If this question is answered, please mark the thread as closed and assign points where earned..

  • Error importing data via Apex

    Hi,
    I have an apex application on a 10g XE machine, and am in the process of migrating
    this to an 11g machine (same version of apex: 3.2.1).
    With a dozen or more "Apex" users, I first was a little disgruntled to find that there wasn't
    a readily-available tool to migrate all the users across (add that to the "wish list" presuming there
    isn't an easy user-migration mechanism, please).
    Then I took the DDL across to the new platform, which worked quite well.
    My next task was to move the data, in prior preparation for moving the applications.
    On the old machine I performed a "data unload" to a separate XML file on each of my three tables
    (its not a huge application).
    On the new machine, I tried a "data load" into one table, and all I got was the unimaginative
    error message shown below:
    ORA-31011: XML parsing failed ORA-19202: Error occurred in XML processing LPX-00222: error received from SAX callback function ORA-01008: not all variables bound ORA-24801: illegal parameter value in OCI lob function ORA-24801: illegal parameter value in OCI lob function
    Of course, all these error messages are really informative... I can work out (not) from the error message
    how to solve the problem... !
    The table I'm moving has a dozen rows in it. The table has two CLOB columns in it and two BLOB columns.
    If I cannot easily migrate the data, there's no point in moving the applications. Time to ask the forum for
    help please.
    Various attempts of backing up the whole schema with "exp" and "expdp" and even "SQL Developer" proved futile, now
    it looks that I can add "apex" to that list too.
    Any help appreciated; thanks in advance.
    Mungo

    Thankyou for your kind reply.
    flavioc wrote:
    First of all, apex users are migrated when you export and import the workspace.I'm guessing you have to be the Apex Administrator to do that? On my hosted source
    application the highest privilege I enjoy is a single Workspace Administrator - nothing higher.
    Hence the need to transfer the data "the long way".
    >
    Secondly, in my own experience XML data exports are good for simple cases, reasonable amount data (less than 100.000 rows) otherwise you may incur in a variety of problems like insufficient memory, table loading order because of failing constraints and trigger based rules.The XML file I am attempting to import is 928Kbytes in size, and comprises about twelve records with photographs stored in BLOBs
    to bulk out this file.
    >
    Thirdly, i do not see why exp or expdp should not work, i'm using them all the time, so may be you want to be more specific on this.
    As I understand it "expdp" needs a Directory object... that would require raising a ticket with the hosting company and asking for
    them to create one (a step too far, at the moment ;-)
    From failing human memory, the "exp" command seemed to store the tablespace where the tables were stored in. When I then went to
    import from the resultant exported file, the tablespaces were different on the new machine. So I gave up on "exp".
    I thought that the relatively new "SQL Developer" would come to my rescue, but it also has problems with CLOB and BLOB columns.
    All in all it seems to be more work than I had bargained for: all I want to do is "lift" the application off one machine and drop it on
    to the new machine, but Oracle seems to want me to spend at least three days to workaround all the silly "features".
    Comments borne on frustration; forgiveness requested...
    Mungo :-)

Maybe you are looking for