How to avoid the error ORA-01858:

Hi all
I use apex 4.1.
I tried a query while dealing with the dates I had error, but I did not how to avoid it.
like trying to get the number of students joined between certain dates.
declare
SMO varchar2 (100);
SDO varchar2 (100);
SYO varchar2 (100);
SYDS varchar2 (100);
SYDE varchar2 (100);
a varchar2 (100);
b the number;
D1 date;
D2 date;
Start
Select to_char(sysdate,'MM'), to_char(sysdate,'DD'), to_char(sysdate,'YYYY') in SMO, SDO, SYO double;
SYDS: = '0602' | SYO;
SYDES: = '0902' | SYO;
D1: = to_date(SYDS,'MM/DD/YYYY');
D2: = to_date(syde,'MM/DD/YYYY');
run immediately "select |" TO_CHAR (DATE_OF_JOIN, "YY"), (TOTAL_NO_STUDENTS) Count of CROP_SALE where class = 7 and to_char (DATE_OF_JOIN, "YYYY") = to_char (sysdate, "YYYY") and to_date (to_char (DATE_OF_JOIN), "MM/DD/YYYY") > to_date(''d1'',''MM/DD/YYYY'') and to_date(DATE_OF_JOIN,''MM/DD/YYYY'') < to_date(''d2'',''MM/DD/YYYY'') group to_char (DATE_OF_JOIN "AA")' has , b ;
dbms_output.put_line(a|| b);
end;
This error comes in dates d1 & d2 referring, but I did not how slove it.
can someone help me pls
Kind regards
Pavan

There are two types of errors that I see. First, fix the date format before removing the slashes (because the source has no slash).

D1: = to_date (SYDS, 'MMDDYYYY');
D2: = to_date (SYDE, 'MMDDYYYY');

Secondly, in the statement immediately execute you put in the text "d1" and "d2", not the values of d1 and d2. You must either concatenate the values like this:

to_date('||) D1 |', "MM/DD/YYYY)

Or better yet, use bind variables like this:

to_date(:B1,''MM/DD/YYYY'')

and add a "using" clause

using d1, d2;

I made the changes in the code. Try this:

declare
  SMO  varchar2(100);
  SDO  varchar2(100);
  SYO  varchar2(100);
  SYDS varchar2(100);
  SYDE varchar2(100);
  a    varchar2(100);
  b    number;
  d1   date;
  d2   date;
begin
  select to_char(sysdate, 'MM'),
         to_char(sysdate, 'DD'),
         to_char(sysdate, 'YYYY')
    into SMO, SDO, SYO
    from dual;
  SYDS := '0602' || SYO;
  SYDE := '0902' || SYO;
  d1   := to_date(SYDS, 'MMDDYYYY');
  d2   := to_date(SYDE, 'MMDDYYYY');
  execute immediate 'select to_char(DATE_OF_JOIN,''YY''),
                     COUNT(TOTAL_NO_STUDENTS)
                     from CROP_SALE
                     where class=7
                     and to_char(DATE_OF_JOIN,''YYYY'')=to_char(sysdate,''YYYY'')
                     and to_date(to_char(DATE_OF_JOIN),''MM/DD/YYYY'') > :B1
                     and to_date(DATE_OF_JOIN,''MM/DD/YYYY'') < :B2
                     group by to_char(DATE_OF_JOIN,''YY'')'
    into a, b
    using d1, d2;
  dbms_output.put_line(a || b);
end;

Edit: Fixed the to_date function, which operated on a date. Also fixed an extra | After the selection

Tags: Database

Similar Questions

  • How to solve the error ORA-00001 in SQL Insert?

    Hi all, I need your help appreciated.

    I do a plsql procedure that inserts a line according to the value of the slider, I have error oracle ORA-00001: unique constraint (constraint_name) violated.

    This message may appear if a duplicate entry exists at a different level: in the RDBMS MySQL, I have the syntax IGNORES to solve this error of duplication... and in Oracle?

    Thanks for your time and your advice.
    Miguelito

    user6317803 wrote:
    How to solve the error ORA-00001 in SQL Insert?

    ORA-00001 means table a unique/primary key / index and you attempt to insert a row with the key value already exists in the table. I'll assume table has a primary key on COUNTRY_ID. Then modify SQL for:

    SQL = "INSERT INTO COUNTRIES (COUNTRY_ID, COUNTRY_NAME, REGION_ID) SELECT"BZ","BLZ", 3 DOUBLE WHERE DOES NOT EXIST (SELECT 1 FROM COUNTRIES WHERE COUNTRY_ID ="BZ").

    There is a good chance COUNTRY table also has unique key/index on COUNTRY_NAME. If so use:

    SQL = "INSERT INTO COUNTRIES (COUNTRY_ID, COUNTRY_NAME, REGION_ID) SELECT"BZ","BLZ", 3 DOUBLE WHERE DOES NOT EXIST (SELECT 1 FROM COUNTRIES WHERE COUNTRY_ID = 'BZ' OR 'BLZ' = COUNTRY_NAME).

    SY.

  • How to solve the error ORA-01658

    Trying to get a little old working code database and get the following errors with the following

    REM **********************************************************************

    CREATE TABLE gam_service (/ * gam_ser * /)

    service_group_id NUMBER (10) NOT NULL

    CONSTRAINT gam_ser_fk_gam_sergrp REFERENCES gam_service_group (service_group_id)

    ON DELETE CASCADE,

    service_id NUMBER (10) NOT NULL,

    service_name VARCHAR2 (127) NOT NULL, / * length leave CPG code.

    service_type char(1) NOT NULL, / * type of Service Gulp, taken mp, special client * /.

    Server VARCHAR2 (127) NOT NULL, / * Server name, for example "gulp" * /.

    version VARCHAR2 (20) NOT NULL, / * need binary Server version number * /.

    parameters NULL VARCHAR2 (2000), / * parameters to start the service - could be binary * /.

    cpu_power_level NULL NUMBER (3), / * NULL for generics.

    type_systeme_exploitation NULL char (1) / * NULL for generics (Solaris2.4, winNt) * /.

    CONSTRAINT gam_ser_ostype CHECK (type_systeme_exploitation IN (NULL, the of ', 'n')),

    hardware_owner_type NULL VARCHAR2 (10) / * NULL for Joker (company name) * /.

    ) TABLESPACE gam_tab STORAGE (INITIAL 25 K NEXT 100 K PCTINCREASE 100 MINEXTENTS 1 MAXEXTENTS unlimited)

    /

    CREATE UNIQUE INDEX gam_service_pk on gam_service (service_group_id, service_name)

    TABLESPACE gam_ind

    STORAGE (INITIAL 5 K NEXT 20 K PCTINCREASE 100 MINEXTENTS 1 MAXEXTENTS unlimited)

    /

    CREATE SEQUENCE gam_service_seq

    INCREMENT BY 1

    START WITH 1001

    NOCYCLE

    NOCACHE

    ALL

    /

    Here the error message

    CREATE UNIQUE INDEX gam_service_pk on gam_service (service_group_id, service_name)

    *

    ERROR on line 1:

    ORA-01658: cannot create as INITIAL segment in tablespace GAM_IND

    I really hope someone can help me thanks

    You just was lack of space in the tablespace gam_ind. contiguous space to be precise. Your INTITIAL extend needs 5K of space contoguous. And as you have specified PCTINCREASE 100, contiguous space requirement will double with each following measure. Most likely, that you ended up with a case where there are a lot of free space not no contiguous space to required size.

    SY.

  • How to avoid the report query needs a unique key to identify each line

    Hello

    How to avoid the error below

    The report query needs a unique key to identify each row. The supplied key cannot be used for this query. Please change the report attributes to define a unique key column.

    I have master-detail tables but without constraints, when I created a query as dept, emp table he gave me above the error.

    Select d.deptno, e.ename

    by d, e emp dept

    where e.deptno = d.deptno

    Thank you and best regards,

    Ashish

    Hi mickael,.

    Work on interactive report?

    You must set the column link (in the attributes report) to something other than "link to display single line." You can set it to 'Exclude the column link' or 'target link to Custom.

  • Error ORA - 01858 Apex report working / valid underlying the request

    After two days of searching for these forums and AskTom, I think I need to put the following problem.

    I have what seems to be a valid view of certain data that is created as follows (with apologies for the formatting - doesn't seem to be a way to use a fixed font here):

    CREATE OR REPLACE VIEW "PRICING_CAPABILITY" OF THE FORCE. "" POW_EXEC_SUMM010 "("Item",
    "Jul-09", "Aug-09", "Ms-09", "Oct-09", "Nov-09", "Dec-09", "Jan-10", "" "" "
    'Feb-10', '10-Mar', 'Apr-10', '10-may', 'Jun-10', 'CDA')
    AS
    SELECT
    "Item."
    Sum (decode("ItemMonth",'Jul-09',"ItemValue",0)) "Jul - 09,
    Sum (decode("ItemMonth",'Aug-09',"ItemValue",0)) "Aug - 09,
    Sum (decode("ItemMonth",'Sep-09',"ItemValue",0)) "Sep - 09,
    Sum (decode("ItemMonth",'Oct-09',"ItemValue",0)) "Oct - 09,
    Sum (decode("ItemMonth",'Nov-09',"ItemValue",0)) "Nov - 09,
    Sum (decode("ItemMonth",'Dec-09',"ItemValue",0)) "Dec - 09,
    Sum (decode("ItemMonth",'Jan-10',"ItemValue",0)) "Jan - 10,
    Sum (decode("ItemMonth",'Feb-10',"ItemValue",0)) "Feb - 10,
    Sum (decode("ItemMonth",'Mar-10',"ItemValue",0)) "Mar - 10,
    Sum (decode("ItemMonth",'Apr-10',"ItemValue",0)) "Apr - 10,
    Sum (decode("ItemMonth",'May-10',"ItemValue",0)) "may-10,
    Sum (decode("ItemMonth",'Jun-10',"ItemValue",0)) "Jun - 10."
    Sum ("ItemValueOptional") AS "CDA".
    Of
    (
    SELECT
    "Received new proposals" AS "Item."
    To_char(T1.scope_received,'Mon-RR') AS "ItemMonth."
    Count (*) AS "Valeurelement."
    10. AS 'SortOrder '.
    Of
    PRICING_CAPABILITY. POW_DATA t1
    WHERE
    T1.scope_received IS NOT NULL
    AND extract it (FROM AN t1.scope_received) IN (2009,2010)
    ' AND t1.scope_received > = July 1, 2009.
    GROUP BY
    «New proposals received.»
    To_char(T1.scope_received,'Mon-RR'),
    10
    UNION
    SELECT
    "New proposals complΘtΘ' AS"Item. "
    To_char(T2.pricing_approval,'Mon-RR') AS "ItemMonth."
    Count (*) AS "Valeurelement."
    20. AS 'SortOrder '.
    Of
    PRICING_CAPABILITY. POW_DATA t1
    JOIN PRICING_CAPABILITY. POW_LAST_HISTORY t2
    WE
    T1. POW_DATA_ID = t2. POW_DATA_ID
    WHERE
    T2.pricing_approval IS NOT NULL
    AND extract it (FROM AN t2.pricing_approval) IN (2009,2010)
    ' AND t2.pricing_approval > = July 1, 2009.
    GROUP BY
    "End of new proposals."
    To_char(T2.pricing_approval,'Mon-RR')
    )
    GROUP BY
    "Item."
    'SortOrder '.
    ORDER BY
    "SortOrder";

    This view works, IE produced good results by operating (i.e. select * from...) with SQL Developer and SQL Workshop of the Apex section.

    But when I try to produce an Apex report, use it as a data source, I get the following error:

    ORA-01858: a non-digit character was found here where was waiting for a digital

    The error is displayed before that appear part any report itself, that is to say the header of the region is displayed and then the error message.

    So far, everything I could find on the forums or AskTom suggests that this is probably due to a problem. But the goal here is to summarize records dated by month, so I've extracted the elements year and date values, convert them to strings (using TO_CHAR) and then using the resulting chains of "MON - YY" to group the results.

    If there is a better way, I'm interested.

    But I do not understand why the Apex seems to be rejecting what appears to be valid results from a query of valid work.

    Any ideas? Suggestions?

    See you soon,.

    Peter

    You hit some implicit date conversion problem, probably caused by the preferred language of the browser in combination with the use of literals in the query.
    It's a bad idea to use literals as July 1, 2009"in an environment like Apex, which may have different date forrmats according to the preferences of the user.

    At the beginning of the rendered page Apex performs a SESSION of ALTER to change various NLS parameters.
    You can see this by turning on debugging, look for NLS in the resulting output and take a look at the settings that the Apex is application.
    The literal 1 July 2009"means the format DD-MON-YYYY mask, but regional settings applied through Apex may involve a different date format mask.

    Flavio

    ------
    http://oraclequirks.blogspot.com

  • Satellite Pro 4200 how to avoid the mistakes of the ACPI

    Satellite Pro 4200 how to avoid the ACPI errors after installing SP2 for windows XP Prof
    The problem is that my computer after installation service Pack 2 need about 15 minutes from time of shoutdown - what should I do to avoid this problem.
    Piotr Plecke

    Hello
    in this case it would be interesting what Type of laptop it is exactly.

    You will find this model on the bottom of your laptop. There is a review of it.

    Some models have a Bios update available, others not, for example.

    Please send additional information!

    Good bye

  • FFT waveform (file converted from Matt file lvm) - how to overcome the error dt &lt; = 0?

    Hello

    I use a lvm file after conversion of Matt file. I wanted to get the fft spectrum. I get this error message this dt waveform<>

    How he overcome?

    I have attached the matte file and the vi that I used.

    Best regards

    FESMI

    The Forum is a bit special files that can be attached. Creating a zip file often works. Sometimes, you can change the .txt extension. If you change the extension, please indicate in your message which was the extension of the moose.

    It seems that data in the file has a time column and a column of amplitude. The LabVIEW waveform data type is a cluster of a table of amplitudes (Y), sampling interval (dt), from the time (t0) and optional attributes. That's what the power spectrum VI requires as input. The t0 values is not used if the default is fine. the value of dt can be calculated by the difference of the two adjacent values in the time column. Given that the first value is equal to zero, the second value is equal to dt.  Use the primitive to build a waveform of the palette of waveform.  Expand it to view the dt element.

    In the VI attached all lines is an indicator that contains your saved default file data. Graph XY plots that data.  After subtracting the way to get rid of a continuous component, the data is converted to a waveform. The power spectrum is calculated and displayed using the same VI as in your program. It also uses extract several Information.vi tone for the frequency and amplitude of the main peaks in the data.

    Interestingly, the lower frequency of the spectrum a harmonic of 60 Hz while the tops are almost sharp space 4 kHz ~ 100 Hz apart.  The broad peak near 2.1 kHz does not seem to have noticeable components to 60 or 100 Hz.

    How to avoid the Type of dynamic data (DDT)? Stop using screw Express! For reasons known only to EITHER screw Express a deliver their outputs via the DDT. Except when you open the block diagram of the express VI, there is no way of knowing what the underlying data structure on a thread of DDT.

    Lynn

  • Basic sql oca lession doubts 3 on error ora-01858

    SELECT last_name, hire_date
       FROM   employees
       WHERE  hire_date = TO_DATE('May 24, 1999', 'fxMonth DD, YYYY');
       
    talk about books, it will leave an error (ora-01858 which is a non-numeric error) but the statement being executed perfectly while
    by removing this "fx" - prefix gives an error called ora-01861.

    I'm confused here? can someone show me the right way?

    Hello

    The result depends on your NLS parameters. Yours probably are on something different than AMERICAN. In you language in may can then have a different number of characters (?)

    That's why you hit the ORA-01861 FX Format model with something else without. (Do not see why you should get ORA-01858, however)

    Concerning
    Peter

  • How to avoid the SEPARATE in OBIEE SQL

    Hello...

    For the issue I posted previously...
    Problem with the data type LONG in responses

    I executed the query into a FROG, and I've identified the error because of what this error is coming... because of SEPARATE...
    I took care to avoid this column in ORDER BY putting order on another column...

    Now my question is how to avoid the DISTINCT clause in SQL generated by OBIEE...
    If the first column of criteria is then it avoids the SEPARATE... but if I use measure... Group of will come... and group of should not be used here...

    If it's done... my problem is solved...
    Of course... I get duplicate rows...

    However, I want the answer how avoid SEPARATE?
    Waiting for the response from your...

    Thanks and greetings
    Kishore Guggilla

    Kishore,

    In the physical layer, open the properties of physical catalog and in the features tab find DISTINCT_SUPPORTED and remove the check box value.

    who removed separate in each query generated for this database.

    -Madan

  • How to fix the error with the code: 0xe7210001 failed to load powrprof, object: cls

    Hello

    Dose anyone know how to fix the error with the code: 0xe7210001, message: unable to load powrprof, object: CLSD-no-it is found;
    OR: Fingerprintsoftware OR error: replicas THotkey.exe message window and the computer freezes

    Maleware scanned and virus, also in safe mode, found no infection, reinstalled driver fingerprint, but nothing has changed.

    grateful for the help!

    Hello

    > message: unable to load powrprof, object: CLSD-no-it is found;
    In my view, this would mean that there is a problem with Toshiba Power Saver
    What laptop Toshiba, you have exactly?

    Maybe reinstall Power Saver could help. You can find it on the official website of Toshiba.

  • Camileo S10 - how to avoid the 'information' during video playback on TV

    I just received my Camileo S10... very nice indeed... but how to avoid the track and reading data to be shown on the screen during playback on my TV...?

    Go to the movies, then before you start playing click the OK button. This also works when you save. You must do this before playing or recording.

  • How to explain the error in the executable file?

    As everyone knows, there are 3 parts to the cluster of error: status and source code. The State's flag, the code is the error code and the source is where Labview think that the error occurred. Normally, when I'm in the environment labview course I can just right mouse click the error and click "explain the error" and a description and detailed error possible cause rises.

    However, when I create an executable I don't know how to explain the error to the user, such as labview.

    When an error occurs that I wish I had a popup that says code error, source and EXPLANATION. The code and the only source is so enigmatic sound quite panic inducing the user, whether or not the error is unrecoverable/crash-inducing. Also this would save me having to search the online error code.

    How to make the explanation of the error code? There is a vi that I can enter an error code and get the explanation string?

    There is probably something simple I forget but I couldn't find the answer in my research. Thanks in advance for your help.

    Simple error handler and screw General Error Handler?

  • Avoid the error message "the resource specified is reserved"

    Hi all

    My question is this: I have two Labview VI each using a wizard DAQ to collect different channels analog voltage. While a VI data collection of 3 channels at 1000 Hz, the other gets just a sample on request from a fourth channel. Now, when I run them at the same time, I get the error "specify resource is reserved. Please note that I don't want two VI to be beaten in a single task. I want that they separate because one is for accelerometers and another is for "startpad. I call these my C# code VI. I read in another thread, saying that this is not possible. But both that they use different channels, I don't understand why this cannot be done. Is it possible that I can get around this problem?

    No, you can avoid the error, and most of the other threads explains why. This card has a clock unique convert. Your card has all of the analog inputs in a single A/D muxes and who uses the clock unique convert. The unique clock means that you simply cannot have two different rates. You have to combine all channels in a single task (do not know what 'club' means) or run one at a time.

    Of course, you can always get a second DAQ card as well.

  • How to avoid the launch of Labview VI when he invokes in Teststand environment?

    Hi, friends.

    I am a student of teststand. I wrote a few screws by Labview. Now, I want to invoke in teststand environment.

    But when I run the sequence. LabVIEW automatically launches.

    How to avoid the launch of Labview when I run the sequence?

    Thank you.

    LabVIEW programs require a runtime engine. Under the TestStand configuration drop-down, select adapters. You can change the LabVIEW adapter to select the runtime rather than the development system.

    This should prevent the main screen of LabVIEW to appear, but you will not be able to change your LabVIEW VIs while they run of TestStand using the runtime engine.

  • How to avoid the launch of Labview when called by Teststand VI

    Hi, friends.

    I am a student of teststand. I wrote a few screws by Labview. Now, I want to invoke in teststand environment. But when I run the sequence. LabVIEW automatically launches. How to avoid the launch of Labview when I run the sequence?

    Thank you.

    I'm not sure that I follow what you're saying...  But it seems that when the VI is called, the LabVIEW Development software is started and you want to avoid this.

    If you create an executable file or a dll and that any call within TestStand, she should not call the development environment.  You must have the LabVIEW runtime engine installed on the target computer.

    For several years I used TestStand with LV, if my memory does not have to be precise.  I think that the above worked for me.  However, it seems that I remember something to have the LV code in debug mode, causing to open development environment... but it's a distant memory.    You do not use breakpoints where the LV VI is called, are you?

    R

Maybe you are looking for