Max function for table having no rows

Hi All
I have a table in which initially no rows. I am running max() function for a column and then wnats to add 1.
But when no rows there below code in not working
select max(code) into p_maxCode from cms_codedetails where codetypeid=0;
p_maxCode:=p_maxCode+1;
dbms_output.PUT_LINE('p_maxCode: '||p_maxCode);
result is:
p_maxCode:
How can I handle the this to get 1 if no rows in the table .

Hi !
Max function in yur case returns NULL and then
null + <anything> ... is still null
You can do
p_maxCode:=nvl(p_maxCode,0)+1;
or
select nvl(max(code),0) into p_maxCode from cms_codedetails where codetypeid=0;
Of course if YOU have decide that null in this case can be treated as 0
T

Similar Messages

  • Function module table returning empty rows but export data is getting

    Hi,
    I am executing function module through JCO after setting importing parameter and when i retrieve the table i get table with empty data 0 rows but i am able get export parameter data . when execute the same function module in abap through sap gui i get table containing 5 rows. what may be the problem. please find below code 
          function = getDefaultJCoConnection().getJCoFunction("ZCRM_ICSS_PROJ_CUST_USR");
                function.getImportParameterList().getField("USER_ID").setValue("MLDL010");
                getDefaultJCoConnection().execute(function);
                exportTable = function.getTableParameterList().getTable("PROJCUSTLIST");
                int rowsNumber = exportTable.getNumRows(); // companies table number of rows
                log.error("rowsNumber----"+String.valueOf(rowsNumber));
      try
         if (rowsNumber > 0)
         int i = 0;
         do
         tempString="table valuesZCOMP_ID"(String)exportTable.getValue("ZCOMP_ID")"ZCOMP_SPC-"+(String)exportTable.getValue("ZCOMP_SPC")
                     + "table valuesZCOMP_DESC"(String)exportTable.getValue("ZCOMP_DESC")"ZPRICE-"(String)exportTable.getValue("ZPRICE")"---" ;
         log.error(tempString);
         while (exportTable.nextRow());
         catch (Exception th)
         log.error("The following error occured: while retrieving table values ", th);
    Do you have any idea where may be the problem
    Regards,
    Pavan
    Edited by: Pavan Reddy on Apr 10, 2010 4:46 PM

    Hi Pavan,
    This could be the case. The function module might be expecting a value converted into its format.
    By this, I mean that the function module might be expecting 0012345678 for 12345678 (Where data element of the ID is of type CHAR 10 ).
    Please check if it is so.
    Best Regards,
    Kris.

  • How to alter or add foreign key constr to table having child rows or data

    Hi,
    I have a table by name DEPT in which the column DEPTNO is a primary key column and have data in it for all the columns . Now I have a EMP table where in the column DEPTNO is not having any constraint including foreign key constraint too. Now i have data in the EMP table for all the columns . now i would like to add the foreign key constraint to DEPTNO column in the EMP table referencing the DEPTNO column in the DEPT table. Both the table do not have any null values .
    I need to add the foreign key without deleting the data in the EMP table.
    Please advice.
    Regards,
    Vinesh

    Hi,
    I need to add the foreign key without deleting the data in the EMP table.Foreign key constraint can have only those values which are present in the primary key of the parent table or null.
    When your tables are populated with values and then you are adding the constraint then,
    the parent table data is only present in child table or null values.
    Example
    SQL> create table emp_bkp as select * from emp;
    Table created.
    SQL> create table dept_bkp as select * from dept;
    Table created.
    SQL> alter table dept_bkp
      2  add constraint pk_deptno primary key(deptno);
    Table altered.
    SQL> select distinct deptno from emp_bkp;
        DEPTNO
            30
            20
            40
            10
    SQL> select deptno from dept_bkp;
        DEPTNO
            10
            20
            30
            40
            55
    SQL>  alter table emp_bkp
      2   add constraint fk_deptno_bkp foreign key(deptno)
      3    references dept_bkp(deptno);
    Table altered.
    SQL> alter table emp_bkp
      2  drop constraint fk_deptno_bkp;
    Table altered.
    SQL> insert into emp_bkp(empno,ename,deptno) values(142,'Fenny',90);
    1 row created.
    SQL> alter table emp_bkp
      2  add constraint fk_deptno_bkp foreign key(deptno)
      3   references dept_bkp(deptno);
    add constraint fk_deptno_bkp foreign key(deptno)
    ERROR at line 2:
    ORA-02298: cannot validate (SCOTT.FK_DEPTNO_BKP) - parent keys not found
    SQL> update emp_bkp
      2  set deptno=null
      3  where empno=142;
    1 row updated.
    SQL> alter table emp_bkp
      2  add constraint fk_deptno_bkp foreign key(deptno)
      3   references dept_bkp(deptno);
    Table altered.
    SQL> insert into dept_bkp (deptno,dname)values(90,'IT');
    1 row created.
    SQL> update emp_bkp
      2  set deptno=90
      3  where empno=142;
    1 row updated.Twinkle

  • Inserting sequence value in a created column already table having some rows

    i have a table emp whish has already having rows in that table
    now i added one more column to that table with alter command and also i created sequence
    now i want to insert the value in that newly created column with sequencename.nextval??????

    insert into employees values (employees_seq.nextval);
    commit;
    Here employees_seq is the name of the sequence.
    Regards
    Asif Kabir
    17 (17 unresolved)
    -- Mark your answer as correct/helpful
    Edited by: asifkabirdba on Dec 22, 2009 3:39 PM

  • How to use min-max functions for date in transformation in bpel?

    Hi,
    I have a requirement where i need to map earliest date of a Source field among all the dates to a target field in a transformation file in BPEL. There are functions called max-value-among-nodeset and min-value-among-nodeset in mathematical functions but they can be used only for numbers and strings.How to do these with dates?
    Thanks,
    Prasanna

    I exactly have the same requirement.Are you able to solve this?
    Its very urgent.Please help me.

  • Index Size is 300MB for table with No Rows

    Hello
    On one of the table in 11g database , the size of the index is about 300mb , when i checked the table, it has got no rows. Is this normal ?
    Thanks

    Hi,
    It can be a case when table was having data earlier and later all the rows from the table were deleted (not truncated).
    You can try rebuilding the index which will re create the index and will release the extra space.
    Regards

  • Instr function for table column

    hi,
    lets consider the basic soctt.emp table. i need to check for the first occurence of 'a' in the Ename column in emp table.
    select instr(ename,'a') from empabove function does not seem to work
    Please advise.
    Regards

    Hi,
    sri wrote:
    but how would be the query if we have ,(comma) in place of 'A'.
    select instr(ename , ',') from empwill this work.What happens when you try it?
    If it's not doing what you want, then post a little sample data (CREATE TABLE and INSERT statements) and the results you want from that data. Dplain how you get those results from that data.
    If you can show the problem using commonly available tables (such as those in the scott or hr schemas) then you don't need to post any sample data, just the results and explanation.
    Always say which version of Oracle you're using.

  • GET PROPERTIES function for TABLE OPERATORS sometimes get MMM1034

    Hi! Another strange problem occurrs in my OMBPlus script:
    I call for the SCHEMA property on a table operator of a mapping by issuing:
    OMBRETRIEVE MAPPING 'SSM_ODS_MU_DETALJ_INS' OPERATOR 'SSM_ODS_MU_DETALJ' GET PROPERTIES (SCHEMA)
    (The command OMBRETRIEVE MAPPING 'SSM_ODS_MU_DETALJ_INS' GET PROPERTIES (BUSINESS_NAME) works.)
    The reply is:
    + OMB02918: Property SCHEMA of SSM_ODS_MU_DETALJ does not exist: MMM1034: Property SCHEMA does not exist.+
    I know I have this property set so I went into OWB Designer and looked at the setting and everything looked OK. The SCHEMA was set to 'SSM' so I closed OWB Designer
    Then I reran the exact command from above
    OMBRETRIEVE MAPPING 'SSM_ODS_MU_DETALJ_INS' OPERATOR 'SSM_ODS_MU_DETALJ' GET PROPERTIES (SCHEMA)
    And it answered 'SSM' !
    Why did I get an error the first time? What did OWB Designer do that suddenly made the property valid for read by OMB? Why does it say that the property doesn't exist?
    It might have something to do with the mapping and it's tables have been recently imported, but why can OWB fix it and not OMB? Any thoughts of what I'm hitting here would be greatly appriciated!
    Thanks!
    Paer

    Nevermind! I went into OWB Desginer and validated everything and that seems to have solved the problem. It is however a strange behaviour...

  • Sql server max function for decimal value

    dear team
    i have column which contains decimal value eg,
      QuestionMasterId  Studentid   Score
    19                         1            9.01,
    19                         2            9.02,
    19                         3            9.35,
    19                         4            8.04,
     i have to display the max score  - that student score but when i am using the following query it is returning the int value  
      DECLARE @MAX decimal
      SELECT @MAX=max(Score) from [QuestionPaperwiseScore] where QuestionMasterId=19 
      print @MAX
     select Studentid,Score,@MAX-Score as diff from [QuestionPaperwiseScore] where QuestionMasterId=19
    kindly help

    Take a look at
    BOL again. The default scale is 0. Thus it behaves like an INT.
    DECLARE @Sample TABLE
    QuestionMasterId INT ,
    Studentid INT ,
    Score DECIMAL(3, 2)
    INSERT INTO @Sample
    VALUES ( 19, 1, 9.01 ),
    ( 19, 2, 9.02 ),
    ( 19, 3, 9.35 ),
    ( 19, 4, 8.04 );
    DECLARE @MAX DECIMAL(3,2);
    SELECT @MAX = MAX(Score)
    FROM @Sample
    WHERE QuestionMasterId = 19
    SELECT @MAX;
    SELECT Studentid ,
    Score ,
    @MAX - Score AS diff
    FROM @Sample
    WHERE QuestionMasterId = 19

  • Repeating headers for tablix having nongrouped data.

    Hi All,
    I have one table that contains detail data and header data.
    But for detail data I need not require the grouped data so I have deleted the row group from by using advanced mode.
    When ever I am generating report it gives me 4 pages of report.
    I have used "RepeatOnNewPage"property to show the header data in each page but it is not working.
    This "RepeatOnNewPage" property is working for table having grouped data.
    Also I found one issue in Line report item is that same thing is not working for Line report item when I have select the "repeathWith" property for tablix.
    Both the above issues are working for Tablix having grouped data. But in my report requirement I want the same for Non Grouped data.
    Please help me how to sort out this issue.
    Thanks and Regards,
    Aswini Rout

    Hi Aswini,
    According to your description, you have a report with only detail rows. Now you have some issues on setting repeat header for your detail rows. Right?
    In Reporting Service, even you don’t have any group, you will still have detail rows. If you delete this Details, the detail rows will become a single static row so that your report will show you only show you a single record when rendering. If you still
    keep this group, your just need go to Advanced Mode of your Row and Column Groups, select the static member (this is the header row), then go to Properties pane, set RepeatOnNewPage true. Now it supposed to show you repeated header on each page.
    Also in Line report, if you set the line repeat with a tablix, the line will always repeat that tablix until all records in this tablix are rendered. So we are still finding out the reason that makes your repeat unavailable. If possible could you post the records
    in your tablix or any other detail information which can help us tested your case in our local environment. Thank you.
    Reference:
    Display Row and Column Headers on Multiple Pages (Report Builder and SSRS)
    If you have any question, please feel free to ask.
    Best Regards,
    Simon Hou (Pactera)
     

  • Create pagination for table contain more than 2 PK

    Guys;
    Is there any way to use the wizard for creating FORM PAGINATION for tables having more than 2 PK??
    Regards;

    Hi dimitri;
    after the user login & start using this form thiswhat should happen to these 3 PKs:
    -1st PK will be a unique number for the questions.
    -2nd PK should be the ID for each survey ( created as global variable in Zero Page ).
    -3rd PK will be the division for this user (also created as a global variable in ZERO PAGE)..so this is the only field which will nt be changed while the user is logged..
    i tried to use the 1st 2 PKs...& set the last one to get a default value..it worked in the begining but gave me the 1st record for each Survey but my problem that i couldnt navigate to the 2nd record..& after that once i log out & relogin it willnt give me anything.
    Regards;
    ehammad

  • Table having trigger

    SQL> exec dbms_wm.enableversioning('shan','view_wo_overwrite');
    BEGIN dbms_wm.enableversioning('shan','view_wo_overwrite'); END;
    ERROR at line 1:
    ORA-20080: invalid 'hist' parameter for EnableVersioning
    ORA-06512: at "SYS.LTDDL", line 441
    ORA-06512: at "SYS.LTDDL", line 1177
    ORA-06512: at "SYS.LTDDL", line 1163
    ORA-06512: at "SYS.LT", line 8033
    ORA-06512: at line 1
    when i enable versioning for table having trigger i am facing above problem. Am i missing something here.
    Thanks and Regards,
    Satheesh Babu.S

    Hello,
    Currently, the hist parameter is case sensitive. So, the following should work:
    SQL> exec dbms_wm.enableversioning('shan','VIEW_WO_OVERWRITE');
    We will allow any case hist parameter in a future release.
    Thanks,
    Ben

  • SQL query to find top 5 users having more rows/data in table

    Dear experts,
    OS = HP-UX
    Database = Oracle 9.2.0.8
    AC users = 600
    Ex:-
    select * from all_users where username like 'AC%';
    AC_1
    AC_2
    AC_3
    AC_4
    AC_5
    AC_6
    AC_.
    AC_.
    AC_.
    AC_600
    Each AC user having same tables INCOMING, OUTGOING
    Now i need to find top 5 users having more rows/data in INCOMING , OUTGOING tables. I tried this:
    SQL>conn AC_1/pwd
    select 'select count(*) from '||table_name||';' from user_tables;
    But i get max counts info only for this AC_1 user , however, i need top 5 users having more rows/max counts query.
    Thank you,

    source : oracle forums
    May be , this one.. not tested though.
    Before doing this you need to have select_catalog_role
    WITH tmp
         AS (SELECT owner,
                    table_name,
                    TO_NUMBER (
                       EXTRACTVALUE (
                          xmltype (
                             DBMS_XMLGEN.getxml (
                                'select /*+ PARALLEL*/ count(*) c from '
                                || table_name)),
                          '/ROWSET/ROW/C'))
                       Cnt
               FROM dba_tables
              WHERE 1 = 1 AND table_name IN ('INCOMING', 'OUTGOING')),
         tmp1
         AS (SELECT a.*,
                    MAX (cnt)
                       OVER (PARTITION BY a.table_name ORDER BY a.cnt DESC)
                       maxcnt
               FROM tmp a)
    SELECT DISTINCT a.*
      FROM tmp a, tmp1 b
    WHERE a.cnt = b.maxcnt AND a.table_name = b.table_name;

  • Aggregate functions for internal table.

    Hi Gurus,
    I'm just wondering whether we can use aggregate functions for internal table. I wanted to know the max value for a particular column in my internal table. How can I achieve this easily and quickly.
    Thanks,
    David.

    sort the table on which you want the maximum value and read it. Please find below example code.
    TYPES : BEGIN OF ty_mvke,
            matnr TYPE mvke-matnr,
            vkorg TYPE mvke-vkorg,
            vtweg TYPE mvke-vtweg,
           AUMNG type mvke-AUMNG,
            END OF ty_mvke.
    DATA : wa_mvke TYPE ty_mvke,
           it_mvke TYPE STANDARD TABLE OF ty_mvke.
    data : temp_AUMNG type AUMNG.
    START-OF-SELECTION.
      SELECT matnr vkorg vtweg AUMNG FROM mvke INTO
            table it_mvke.
    sort it_mvke by AUMNG.
    read TABLE it_mvke into wa_mvke INDEX 1.
    if sy-subrc = 0.
    move wa_mvke-AUMNG to temp_AUMNG.
    write : temp_AUMNG.
    endif.
    Thanks,
    Sreekala.

  • Trouble with the SQL smt to :list tables having more than 1000 rows

    Please I trying to list only tables having more than 1000 rows, but the sql stmt below doesn't work, can someone gives me a tips
    select table_name from user_tables where table_name in ( select table_name from user_tables where rownum > 1000 ) : The result is no rows!
    But I know that I have at lest 50 tables having more than 1000 rows
    Thanks a lot for the help

    If your tables are reasonably analyzed, then you can simply query:
    SELECT table_name,
           num_rows
      FROM user_tables
    WHERE num_rows >= 1000This will give you quite a reasonable estimate.
    Otherwise you have to go for dynamic sql or use the data dictionary to help you generate suitable scripts ....

Maybe you are looking for

  • Need Help on Sending Multiple Attachments

    Hi to all, I hope some one will help me.. Im stuck with this one. I can only send one attachment. Is there someone who know how to send an mail with 2 or more attachments? My code is below, I followed this code from the toturial: Hope for a kind repl

  • Dynamic Parameter Prompting for Database Connection Password When schedulin

    I'm having problems with Dynamic Parameters when I try to schedule a report in InfoView. I create the report in Crystal Reports XI and publish it to the Crystal Server. I go into CMC and under Process:Database set the correct data source and enter th

  • How to modify KM upload to accept jpg/bmp files only?

    Hi All, I want to modify the KM upload command so that it accepts only ".jpg or ".bmp" file types. If any other file type is used then give an error message such as "Files of type jpg, bmp can only be uploaded". Also restrict the size to 1 or 2 MB on

  • Air FileReference.data

    How do I retrieve the data bytearray from a FileReference once it has been downloaded?  Everywhere I look online about this simply states that in a web browser this data is not accessible because it's a security issue, but in Air this is not an issue

  • 508 Compliance issue: Subtitling Captivate Slides, esp for Breeze

    My organization is designing a software demonstration for the Department of Labor, so our work must be 508 compliant. I think I can make our simulation work with screen readers, but I must also include subtitles for the audio instructions in order to