Split Rows in to another set as columns in sql ?

Hi,
I have a sample data..
Id
ENAME
GRADE
1
MILLER         
2
2
CLARK          
4
3
KING           
7
4
ADAMS          
5
5
FORD           
1
6
JAMES          
6
7
MARTIN         
10
8
ALLEN          
3
9
BLAKE          
8
10
REDDY
1
I would like to split 5 rows in to another column set like this..
Id
ENAME
GRADE
Id1
ENAME1
GRADE1
1
MILLER         
2
6
JAMES          
6
2
CLARK          
4
7
MARTIN         
10
3
KING           
7
8
ALLEN          
3
4
ADAMS          
5
9
BLAKE          
8
5
FORD           
1
10
REDDY
1
Please help me on this.
Thank you.

You may be much better doing this at front end
But if you want to implement it in sql server this is the way to go
SELECT MAX(CASE WHEN GrpNo = 0 THEN Id END) AS Id,
MAX(CASE WHEN GrpNo = 0 THEN Ename END) AS ENAME,
MAX(CASE WHEN GrpNo = 0 THEN Grade END) AS Grade,
MAX(CASE WHEN GrpNo = 1 THEN Id END) AS Id1,
MAX(CASE WHEN GrpNo = 1 THEN Ename END) AS ENAME1,
MAX(CASE WHEN GrpNo = 1 THEN Grade END) AS Grade1,
MAX(CASE WHEN GrpNo = 2 THEN Id END) AS Id2,
MAX(CASE WHEN GrpNo = 2 THEN Ename END) AS ENAME2,
MAX(CASE WHEN GrpNo = 2 THEN Grade END) AS Grade2,
FROM
SELECT *,
(ROW_NUMBER() OVER (ORDER BY Id)-1)/5 AS GrpNo,
(ROW_NUMBER() OVER (ORDER BY Id)-1) % 5 AS Seq
FROM Table
)t
GROUP BY Seq
ORDER BY Seq
to make it dynamic see
http://sqlblogcasts.com/blogs/madhivanan/archive/2007/08/27/dynamic-crosstab-with-multiple-pivot-columns.aspx
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

Similar Messages

  • Moving columns of an internal table to rows of an another internal table.

    Hi
    i have an internal table with 20 fields for single record .Now i need to move the 20 fields
    (of similar length) of single record into internal table with those 20 fields as 20 records i.e i need to make rows of first internal table into columns of second internal table.
    hope iam clear.

    HI Deepthi,
    Try with this Logic...
    IF NOT ITAB[] IS INITIAL.
          LOOP AT ITAB FROM 7.
            ITAB2-FIELD1 = ITAB-FIELD1.
            ITAB2-FIELD2 = ITAB-FIELD2.
            APPEND : ITAB2.
            CLEAR : ITAB2.
          ENDLOOP.
          DO 27 TIMES.
            CASE CNT.
              WHEN '1'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD6.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD6.
              WHEN '2'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD7.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD7.
              WHEN '3'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD8.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD8.
              WHEN '4'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD9.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD9.
              WHEN '5'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD10.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD10.
              WHEN '6'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD11.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD11.
              WHEN '7'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD12.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD12.
              WHEN '8'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD13.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD13.
              WHEN '9'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD14.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD14.
              WHEN '10'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD15.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD15.
              WHEN '11'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD16.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD16.
              WHEN '12'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD17.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD17.
              WHEN '13'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD18.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD18.
              WHEN '14'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD19.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD19.
              WHEN '15'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD20.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD20.
              WHEN '16'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD21.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD21.
              WHEN '17'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD22.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD22.
              WHEN '18'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD23.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD23.
              WHEN '19'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD24.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD24.
              WHEN '20'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD25.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD25.
              WHEN '21'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD26.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD26.
              WHEN '22'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD27.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD27.
              WHEN '23'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD28.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD28.
              WHEN '24'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD29.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD29.
              WHEN '25'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD30.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD30.
              WHEN '26'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD31.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD31.
              WHEN '27'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD32.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD32.
              WHEN '28'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD33.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD33.
              WHEN '29'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD34.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD34.
              WHEN '30'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD35.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD35.
              WHEN '31'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD36.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD36.
              WHEN '32'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD37.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD37.
              WHEN '33'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD38.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD38.
              WHEN '34'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD39.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD39.
              WHEN '35'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD40.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD40.
              WHEN '36'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD41.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD41.
              WHEN '37'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD42.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD42.
              WHEN '38'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD43.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD43.
              WHEN '39'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD44.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD44.
              WHEN '40'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD45.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD45.
              WHEN '41'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD46.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD46.
              WHEN '42'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD47.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD47.
              WHEN '43'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD48.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD48.
              WHEN '44'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD49.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD49.
              WHEN '45'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD50.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD50.
              WHEN '46'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD51.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD51.
              WHEN '47'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD52.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD52.
              WHEN '48'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD53.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD53.
              WHEN '49'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD54.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD54.
              WHEN '50'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD55.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD55.
            ENDCASE.
            APPEND ITAB3.
            CLEAR ITAB3.
            CNT = CNT + 1.
          ENDDO.
        ENDIF.
      ENDIF.
    Regards,
    Santosh

  • Error inserting a row into a table with identity column using cfgrid on change

    I got an error on trying to insert a row into a table with identity column using cfgrid on change see below
    also i would like to use cfstoreproc instead of cfquery but which argument i need to pass and how to use it usually i use stored procedure
    update table (xxx,xxx,xxx)
    values (uu,uuu,uu)
         My component
    <!--- Edit a Media Type  --->
        <cffunction name="cfn_MediaType_Update" access="remote">
            <cfargument name="gridaction" type="string" required="yes">
            <cfargument name="gridrow" type="struct" required="yes">
            <cfargument name="gridchanged" type="struct" required="yes">
            <!--- Local variables --->
            <cfset var colname="">
            <cfset var value="">
            <!--- Process gridaction --->
            <cfswitch expression="#ARGUMENTS.gridaction#">
                <!--- Process updates --->
                <cfcase value="U">
                    <!--- Get column name and value --->
                    <cfset colname=StructKeyList(ARGUMENTS.gridchanged)>
                    <cfset value=ARGUMENTS.gridchanged[colname]>
                    <!--- Perform actual update --->
                    <cfquery datasource="#application.dsn#">
                    UPDATE SP.MediaType
                    SET #colname# = '#value#'
                    WHERE MediaTypeID = #ARGUMENTS.gridrow.MediaTypeID#
                    </cfquery>
                </cfcase>
                <!--- Process deletes --->
                <cfcase value="D">
                    <!--- Perform actual delete --->
                    <cfquery datasource="#application.dsn#">
                    update SP.MediaType
                    set Deleted=1
                    WHERE MediaTypeID = #ARGUMENTS.gridrow.MediaTypeID#
                    </cfquery>
                </cfcase>
                <cfcase value="I">
                    <!--- Get column name and value --->
                    <cfset colname=StructKeyList(ARGUMENTS.gridchanged)>
                    <cfset value=ARGUMENTS.gridchanged[colname]>
                    <!--- Perform actual update --->
                   <cfquery datasource="#application.dsn#">
                    insert into  SP.MediaType (#colname#)
                    Values ('#value#')              
                    </cfquery>
                </cfcase>
            </cfswitch>
        </cffunction>
    my table
    mediatype:
    mediatypeid primary key,identity
    mediatypename
    my code is
    <cfform method="post" name="GridExampleForm">
            <cfgrid format="html" name="grid_Tables2" pagesize="3"  selectmode="edit" width="800px" 
            delete="yes"
            insert="yes"
                  bind="cfc:sp3.testing.MediaType.cfn_MediaType_All
                                                                ({cfgridpage},{cfgridpagesize},{cfgridsortcolumn},{cfgridsortdirection})"
                  onchange="cfc:sp3.testing.MediaType.cfn_MediaType_Update({cfgridaction},
                                                {cfgridrow},
                                                {cfgridchanged})">
                <cfgridcolumn name="MediaTypeID" header="ID"  display="no"/>
                <cfgridcolumn name="MediaTypeName" header="Media Type" />
            </cfgrid>
    </cfform>
    on insert I get the following error message ajax logging error message
    http: Error invoking xxxxxxx/MediaType.cfc : Element '' is undefined in a CFML structure referenced as part of an expression.
    {"gridaction":"I","gridrow":{"MEDIATYPEID":"","MEDIATYPENAME":"uuuuuu","CFGRIDROWINDEX":4} ,"gridchanged":{}}
    Thanks

    Is this with the Travel database or another database?
    If it's another database then make sure your columns
    allow nulls. To check this in the Server Navigator, expand
    your DataSource down to the column.
    Select the column and view the Is Nullable property
    in the Property Sheet
    If still no luck, check out a tutorial, like Performing Inserts, ...
    http://developers.sun.com/prodtech/javatools/jscreator/learning/tutorials/index.jsp
    John

  • Split Rows and Store the selection

    Hi all,
    I have a table with a column where there is a numeric data and I developed a code that, if the user insert a number > 1 and he clicks on enter, he writes this row as many times as the number inserted.This table has not a ID that indentify the row, and if I select one or more rows and I click on Enter on numeric data I see that I lost my selection. I think because when I add new rows at my table, I make again the bind of the table, but... there is a method for to store my precedent selection (for ex. the rows that I don't want to split)?
    Tks a lot.

    hi,
    Use this code to get the index of row in which Enter is pressed.
    DATA: lv_index TYPE i.
    lo_el_cn_node = wdevent->get_context_element( name = 'CONTEXT_ELEMENT' ).
    lv_index = lo_el_cn_node->get_index( ).
    Now you can store this index and later after you are done with binding of more rows to the table, Set the lead selection index to lv_index.
    lo_nd->set_lead_selection_index( lv_index ).
    I hope it would help.

  • How to dynamically display the data from a table base on row selection of another table in ADF

    Hi ,
    I have a requirement in ADF. I need to change the data of a table  based on row selection of another Table . Both the table have a Parent Child relationship between them. They have a common attribute say department_id.
                                                                                         For this I created bind variable in view object of employees table and wrote a where clause in the sql query using that bind variable. Then I created method for selection listener of department Table in java bean.
    My method is following
        public void onrowselection(SelectionEvent selectionEvent) {
            RichTable richTable = (RichTable)selectionEvent.getSource();
                            CollectionModel tableModel = (CollectionModel)richTable.getValue();
                            JUCtrlHierBinding adfTableBinding = (JUCtrlHierBinding)tableModel.getWrappedData();
                            Object selectedRowData = richTable.getSelectedRowData();
                            JUCtrlHierNodeBinding nodeBinding = (JUCtrlHierNodeBinding)selectedRowData;
                    oracle.jbo.domain.Number newVal = (oracle.jbo.domain.Number) nodeBinding.getAttribute("DepartmentId");
                    Number pallet = newVal.bigDecimalValue();
                    System.out.println("Selected values " + pallet);
            BindingContext bindingctx = BindingContext.getCurrent();
                          BindingContainer bindings = bindingctx.getCurrentBindingsEntry();
                          DCBindingContainer bindingsImpl = (DCBindingContainer) bindings;
                  DCIteratorBinding dciter = bindingsImpl.findIteratorBinding("EmployeesView1Iterator");//access the iterator by its ID value in the PageDef file
                          ViewObject vo =dciter.getViewObject();
                          vo.setNamedWhereClauseParam("DepartmentId", pallet);//enter your value
                          vo.executeQuery();
    It is printing the selected value of department id from department table in the log. But it is not able to pass the value to employees view. It is showing the following error in the log
    "Definition DepartmentId of type Variable is not found in EmployeesView1."
    I will be very thankful if someone helps me to solve this errror or is there any other way to achieve the same requirement.
    Thanks
    Nilesh

    Note quite sure why you simply wont create a viewlink for the viewobject the tables are based on..
    The viewlink attribute will be based on the departmentId and it's a simple master detail relationship which automatically uses ppr.
    However, if both tables are on the same page; using your hack about;
    On the underlying viewobject, define a viewcriteria e.g. "listById" and set your bind variable here.
    I would bind table two to a RichTable component:
    RichTable t2;
    public void onrowselection(SelectionEvent selectionEvent) {
            RichTable richTable = (RichTable)selectionEvent.getSource();
                            CollectionModel tableModel = (CollectionModel)richTable.getValue();
                            JUCtrlHierBinding adfTableBinding = (JUCtrlHierBinding)tableModel.getWrappedData();
                            Object selectedRowData = richTable.getSelectedRowData();
                            JUCtrlHierNodeBinding nodeBinding = (JUCtrlHierNodeBinding)selectedRowData;
                    oracle.jbo.domain.Number newVal = (oracle.jbo.domain.Number) nodeBinding.getAttribute("DepartmentId");
                    Number pallet = newVal.bigDecimalValue();
                    System.out.println("Selected values " + pallet);
                   refreshTable2(pallet);
            BindingContext bindingctx = BindingContext.getCurrent();
                          BindingContainer bindings = bindingctx.getCurrentBindingsEntry();
                          DCBindingContainer bindingsImpl = (DCBindingContainer) bindings;
                  DCIteratorBinding dciter = bindingsImpl.findIteratorBinding("EmployeesView1Iterator");//access the iterator by its ID value in the PageDef file
                          ViewObject vo =dciter.getViewObject();
                          vo.setNamedWhereClauseParam("DepartmentId", pallet);//enter your value
                          vo.executeQuery();
    private void refreshTable2(Number pallet){
    RichTable x=getT2();
    CollectionModel cm=(CollectionModel)x.getValue();
    JUCtrlHierBinding jcb=(JUCtrlHierBinding)cm.getWrappedData();
    BindingContainer bindings = bindingctx.getCurrentBindingsEntry();
    DCBindingContainer bindingsImpl = (DCBindingContainer) bindings;
    DCIteratorBinding dciter = bindingsImpl.findIteratorBinding(jcb.getName()+"Iterator");
    ViewObject vo =dciter.getViewObject();
    ViewCriteriaManager vcm=vo.getViewCriteriaManager();
    ViewCriteria vc=vcm.getViewCriteria("listById");
    vo.applyViewCriteria(vc);
    vo.setNamedWhereClauseParam("DepartmentId",pallet);
    vo.executeQuery();
    AdfFacesContext.getCurrentInstance().addPartialTarget(getT2());

  • Set a column to be nullable

    Hi, I am not really good at SQL. Please help me if you can.
    I have a column that's Nullable (yes), default (1). Now I want to set the default of the column to null and set the column to be nullable. Here is what I am doing:
    create table testit
    (foo number default 1 not null, doo varchar(10));
    insert into testit (foo, doo) values (15, 'a')
    insert into testit (foo, doo) values (14, 'b')
    insert into testit (doo) values ('c')
    select * from testit
    This will return 3 rows where foo=1 when doo='c'. Now I do:
    ALTER TABLE testit
    modify foo DEFAULT NULL
    This will set the default value of foo to be NULL, however, the Nullable is still No. Then when I do
    insert into testit (doo) values ('ddd')
    I get "cannot insert Null into (testit.foo). What should I do?
    Thanks. :D

    SQL> create table testit
      2  (foo number default 1 not null, doo varchar(10));
    Table created.
    SQL> insert into testit (foo, doo) values (15, 'a');
    1 row created.
    SQL> insert into testit (foo, doo) values (14, 'b');
    1 row created.
    SQL> insert into testit (doo) values ('c');
    1 row created.
    SQL> commit;
    Commit complete.
    SQL> select * from testit;
           FOO DOO
            15 a
            14 b
             1 c
    SQL> describe testit;
    Name                                      Null?    Type
    FOO                                       NOT NULL NUMBER
    DOO                                                VARCHAR2(10)
    SQL> ALTER TABLE testit
      2  modify foo DEFAULT NULL;
    Table altered.
    SQL> describe testit;
    Name                                      Null?    Type
    FOO                                       NOT NULL NUMBER
    DOO                                                VARCHAR2(10)
    SQL> insert into testit (doo) values ('ddd');
    insert into testit (doo) values ('ddd')
    ERROR at line 1:
    ORA-01400: cannot insert NULL into ("TESTIT"."FOO")
    SQL> select constraint_name from all_cons_columns
      2   where table_name = 'TESTIT';
    CONSTRAINT_NAME
    SYS_C00289436
    SQL> select search_condition from all_constraints
      2   where constraint_name =  'SYS_C00289436';
    SEARCH_CONDITION
    "FOO" IS NOT NULL
    SQL> alter table testit drop constraint SYS_C00289436;
    Table altered.
    SQL> insert into testit (doo) values ('ddd');
    1 row created.
    SQL> commit;
    Commit complete.
    SQL>

  • OLE2 how to set a column width of an excel file i'm creating?

    how can i set the column width in an excel file i'm creating with ole?
    or even, haw can i set the auto-fix properties?

    Hallo !
    SORRY MY ENGLISH is very BAD.
    I tried to set page header and  footer in Excel sheet with abap ole
    DATA : BEGIN OF enter,
             x(1) TYPE x VALUE '0D',
            END OF enter.
    DATA : format(255) TYPE c.
    FORM set_page_sheet.
      CALL METHOD OF excel 'ActiveSheet' = sheet.
      CALL METHOD OF sheet 'PageSetup' = pagesetup.
      SET PROPERTY OF pagesetup 'Orientation' = xllandscape.
      SET PROPERTY OF pagesetup 'PrintTitleRows' = '$9:$12'.
      CLEAR format.
    ERROR
      CONCATENATE 'PAGESHEET' enter-x 'PAGE &P/&N' INTO format.
    ERROR
      SET PROPERTY OF pagesetup 'RightHeader' = format.
      CLEAR format.
      CONCATENATE ' Text 1 ' enter-x 'Text 2'
    enter-x 'Text 3 ' INTO format.
      SET PROPERTY OF pagesetup 'RightFooter' = format.
      FREE OBJECT pagesetup.
    ENDFORM.                    " set_page_sheet
    Activate report -
    ERROR - The enter-x must by data type c or another then data type x
    Thanks for answer.

  • Set the column name of a table in a list box

    is there any code to set the column name of a table in a list box at oracle devloper 6i?
    pls help.

    I dont want to go for pl/sql . It should work any table.You want Dynamic SQL without using PL/SQL? Tricky. I'm sure there's a possible way using some very complex and convoluted XML functionality of SQL but in reality you are asking for something that isn't natural to SQL queries, especially if you are expecting a dynamic number of columns to be produced for each row of data. SQL expects a table structure, including output formats, to be a defined number of columns with any number of rows, not a defined number of rows with any number of columns.
    Perhaps if you explain why you need this sort of functionality then we may be able to offer a better solution.
    ;)

  • Set the column length in an sql query

    Hi,
    Is there a way to set the column length in a query without using sqlplus commands like row size and format column.
    I'd like to do it just from the sql query itself.
    select 'this is a test' from dual; Can I define the width of this column in the select statement
    Cheers.

    Use RPAD,
    SQL> WITH T
      2       AS (SELECT 'this is test' str FROM DUAL
      3           UNION ALL
      4           SELECT 'this is a long test' FROM DUAL
      5           UNION ALL
      6           SELECT 'this is a long long long long test' FROM DUAL)
      7  SELECT RPAD ( str, 20) str,LENGTH( RPAD ( str, 20)) len
      8    FROM T;
    STR                         LEN
    this is test                 20
    this is a long test          20
    this is a long long          20
    SQL> G.

  • Splitting rows at specific times (not intervals)

    Greetings.
    I have a data set with fields that hold start and end times for specific events. These events have unique ID's and cross multiple time intervals. I'm looking for a way to split a single row in the dataset into multiple rows with new start and end times for each relevant time interval.
    The examples I've found online describe ways (using the MODEL method) to split rows based on time intervals of a fixed length (24 hours, for example) but I'm looking for a way to split the records at a specific time (at 6am and 6pm.)
    So this record set:
    <tt>SELECT ID, START_DATE, END_DATE FROM EVENTTABLE
    _ ID __________ Start_date __________ End Date _____
    1228322 __ 21-NOV-11 17:51:29 __ 21-NOV-11 19:32:27
    1228327 __ 21-NOV-11 14:53:24 __ 22-NOV-11 03:46:06
    1228334 __ 21-NOV-11 03:32:53 __ 21-NOV-11 05:13:13
    1183267 __ 25-SEP-11 16:09:13 __ 27-SEP-11 04:38:11</tt>
    Would become:
    <tt>SELECT ID, START_DATE, END_DATE FROM EVENTTABLE MODEL...
    _ ID __________ Start_date __________ End Date _____
    1228322 __ 21-NOV-11 17:51:29 __ 21-NOV-11 18:00:00
    1228322 __ 21-NOV-11 18:00:00 __ 21-NOV-11 19:32:27
    1228327 __ 21-NOV-11 14:53:24 __ 21-NOV-11 18:00:00
    1228327 __ 21-NOV-11 18:00:00 __ 22-NOV-11 03:46:06
    1228334 __ 21-NOV-11 03:32:53 __ 21-NOV-11 05:13:13
    1183267 __ 25-SEP-11 16:09:13 __ 25-SEP-11 18:00:00
    1183267 __ 25-SEP-11 18:00:00 __ 26-SEP-11 06:00:00
    1183267 __ 26-SEP-11 06:00:00 __ 26-SEP-11 18:00:00
    1183267 __ 26-SEP-11 18:00:00 __ 27-SEP-11 04:38:11</tt>
    Notice that record 1183267 starts in one interval, crosses two whole intervals and ends in a fourth. This splitting of one event into many is required to create a record set that will guarantee a record for each of the relevant intervals.
    Thanks in advance for your consideration!

    SonyDADCuser wrote:
    Greetings.
    I have a data set with fields that hold start and end times for specific events. These events have unique ID's and cross multiple time intervals. I'm looking for a way to split a single row in the dataset into multiple rows with new start and end times for each relevant time interval.
    The examples I've found online describe ways (using the MODEL method) to split rows based on time intervals of a fixed length (24 hours, for example) but I'm looking for a way to split the records at a specific time (at 6am and 6pm.)
    So this record set:
    <tt>SELECT ID, START_DATE, END_DATE FROM EVENTTABLE
    _ ID __________ Start_date __________ End Date _____
    1228322 __ 21-NOV-11 17:51:29 __ 21-NOV-11 19:32:27
    1228327 __ 21-NOV-11 14:53:24 __ 22-NOV-11 03:46:06
    1228334 __ 21-NOV-11 03:32:53 __ 21-NOV-11 05:13:13
    1183267 __ 25-SEP-11 16:09:13 __ 27-SEP-11 04:38:11</tt>
    Would become:
    <tt>SELECT ID, START_DATE, END_DATE FROM EVENTTABLE MODEL...
    _ ID __________ Start_date __________ End Date _____
    1228322 __ 21-NOV-11 17:51:29 __ 21-NOV-11 18:00:00
    1228322 __ 21-NOV-11 18:00:00 __ 21-NOV-11 19:32:27
    1228327 __ 21-NOV-11 14:53:24 __ 21-NOV-11 18:00:00
    1228327 __ 21-NOV-11 18:00:00 __ 22-NOV-11 03:46:06
    1228334 __ 21-NOV-11 03:32:53 __ 21-NOV-11 05:13:13
    1183267 __ 25-SEP-11 16:09:13 __ 25-SEP-11 18:00:00
    1183267 __ 25-SEP-11 18:00:00 __ 26-SEP-11 06:00:00
    1183267 __ 26-SEP-11 06:00:00 __ 26-SEP-11 18:00:00
    1183267 __ 26-SEP-11 18:00:00 __ 27-SEP-11 04:38:11</tt>
    Notice that record 1183267 starts in one interval, crosses two whole intervals and ends in a fourth. This splitting of one event into many is required to create a record set that will guarantee a record for each of the relevant intervals.
    Thanks in advance for your consideration!Neat problem.
    This assumes you have a reasonably recent version of Oracle, and i only tested it for your "complex" case spanning multiple days because i didn't want to type out a bunch of sample data. Should work on all your data sets though (i always say this when i do incomplete testing :).
    with
      time_data as
      select
          1                                                         as col1
        , to_date('25-sep-2011 16:09:13', 'dd-mon-yyyy hh24:mi:ss') as start_date
        , to_date('27-sep-2011 4:38:11', 'dd-mon-yyyy hh24:mi:ss')  as end_date
      from dual
    select *
    from
      select
          col1
        , greatest
              trunc(t.start_date, 'dd') - interval '6' hour + (interval '12' hour * m.column_value)
            , t.start_date
          ) as start_date
        , least
              trunc(t.start_date, 'dd')  + interval '6' hour + (interval '12' hour * m.column_value)
            , t.end_date
          ) as end_date
      from time_data t,
        table(cast(multiset(select level from dual connect by level <= ceil(end_date - start_date) * 2) as sys.odcinumberlist)) m
    where start_date < end_date;

  • By which method,i can get  the no of rows in the record set?

    Does anyone help me that by which method,i can get the no of rows in the record set?
    now i use next() to check whether the next record is available or not?

    shashi_rajak wrote:
    under Practice Exercise #1 heading :
    there is a statement.
    "Now, the COUNT function does not need to retrieve all of the fields from the table (ie: employee_number, employee_name, and salary), but rather whenever the condition is met, it will retrieve the numeric value of 1. Thus, increasing the performance of the SQL statement."And have you ever tried it? Or do you simply blindly believe everything you read? And what sort of "authority" is "tech on the net"?
    P.S. A quick test on Oracle (and you must do each query at least twice throwing away the first result, as Oracle always caches things which will have an effect, and averaging the remaining attempts).
    count(*) -- 1 min 17 secs for 35,311,978 rows
    count(1) -- 1 min 19 secs for 35,311,978 rows
    Edit: And the table has 46 columns.

  • How do I set the column content to automatic break lines

    Hello Guys,
    I have a problem with the column width and the column content of a standard report. Within the report are hugh entries which aren't interrupted by an space character. I set my column width to a special value by usingen "css style: display block; width: 300px;". Now the problem is that some of the column entries have a longer width than the column width is setted. So they overlock the entries of the column next to them.
    My question is: How do I set the column content to automatic break lines after a certain count of characters?
    After researching a couple of websites and discussion thread I found maybe a reference to the solution. I hope it help you to give me an answer.
    COLUMN LAST_NAME FORMAT A4
    regards
    wderr

    Wderr,
    PDFs are another animal entirely. Try adjusting the width of the column under the Print Attributes tab of the report.
    If that doesn't work you'll probably need to create custom XSL-FO layouts which, depending on the tools you have at your disposal, could take some time.
    Regards,
    Dan
    Blog: http://DanielMcGhan.us/
    Work: http://SkillBuilders.com/

  • How to update the COST column using another table's column

    Dear All,
    I have table:
    table parts: pno, pname, qoh, price, olevel
    table orders: ono, cno, eno, received, shipped
    table odetails: ono, pno, qty
    view:orders_view: ono, cno, eno, received, shipped,sum(qty*price)order_costview:odetails_view: ono, pno, qty, (qty*price)cost
    after I update the price in parts, I need to update COST and ORDER_COST too. The orders_view does not have pno, qty, and price, the odetails_view does not have price, how can I update the COST and ORDER_COST. Please help and Thanks in advance!!!
    I wrote the update the price in parts:
    create or replace procedure change_price(ppno in parts.pno%type, pprice in parts.price%type) as
    begin
        update parts
        set price = pprice
        where pno = ppno;
    end;
    show errorsthis procedure works fine.
    I wrote the trigger:
    create or replace trigger update_orders_v
    after update of price on parts
    for each row
    begin
        update orders_view
        set order_cost = sum(parts.(:new.price)*parts.qty)
        where parts.pno = :new.pno;
    end;
    show errorsIt gives me:Errors for TRIGGER UPDATE_ORDERS_V:
    LINE/COL ERROR
    3/5 PL/SQL SQL Statement ignored
    4/22 PL/SQL ORA-00934: group function is not allowed hereplease help!

    You could add the columns to the tables and then you would need a trigger to update those columns. However, you could just as easily select the price * qty to get the cost, without creating an additional column or trigger. I have no idea what you might want to do with a global temporary table. I think you need to explain what your purpose is, before any of us can suggest the best method. Since I have already demonstrated an update with a view, I will demonstrate an update with the cost column added to the odetails table and a trigger as you asked about. Notice that you will need triggers on both tables, the one that has qty and the one that has price.
    scott@ORA92> create table parts
      2    (pno    number(5) not null primary key,
      3       pname  varchar2(30),
      4       qoh    integer check(qoh >= 0),
      5       price  number(6,2) check(price >= 0.0),
      6       olevel integer)
      7  /
    Table created.
    scott@ORA92> create table odetails
      2    (ono    number(5),
      3       pno    number(5) references parts,
      4       qty    integer check(qty > 0),
      5       cost   number,
      6       primary key (ono,pno))
      7  /
    Table created.
    scott@ORA92> create or replace procedure change_price
      2    (ppno   in parts.pno%type,
      3       pprice in parts.price%type)
      4  as
      5  begin
      6    update parts
      7    set    price = pprice
      8    where  pno = ppno;
      9  end;
    10  /
    Procedure created.
    scott@ORA92> create or replace trigger update_cost1
      2    after insert or update of price on parts
      3    for each row
      4  begin
      5    update odetails
      6    set    cost = qty * :new.price
      7    where  pno = :new.pno;
      8  end update_cost1;
      9  /
    Trigger created.
    scott@ORA92> show errors
    No errors.
    scott@ORA92> create or replace trigger update_cost2
      2    before insert or update of qty on odetails
      3    for each row
      4  declare
      5    v_price parts.price%type;
      6  begin
      7    select price
      8    into   v_price
      9    from   parts
    10    where  pno = :new.pno;
    11    --
    12    :new.cost := :new.qty * v_price;
    13  end update_cost2;
    14  /
    Trigger created.
    scott@ORA92> show errors
    No errors.
    scott@ORA92> insert into parts values (1, 'name1', 1, 10, 1)
      2  /
    1 row created.
    scott@ORA92> insert into odetails values (1, 1, 22, null)
      2  /
    1 row created.
    scott@ORA92> -- starting data:
    scott@ORA92> select * from parts
      2  /
           PNO PNAME                                 QOH      PRICE     OLEVEL
             1 name1                                   1         10          1
    scott@ORA92> select * from odetails
      2  /
           ONO        PNO        QTY       COST
             1          1         22        220
    scott@ORA92> -- update:
    scott@ORA92> execute change_price (1, 11)
    PL/SQL procedure successfully completed.
    scott@ORA92> -- results:
    scott@ORA92> select * from parts
      2  /
           PNO PNAME                                 QOH      PRICE     OLEVEL
             1 name1                                   1         11          1
    scott@ORA92> select * from odetails
      2  /
           ONO        PNO        QTY       COST
             1          1         22        242
    scott@ORA92> -- select works without extra cost column or trigger:
    scott@ORA92> select o.ono, o.pno, o.qty, (o.qty * p.price) as cost
      2  from   odetails o, parts p
      3  where  o.pno = p.pno
      4  /
           ONO        PNO        QTY       COST
             1          1         22        242
    scott@ORA92>

  • SQL Query (Updateable Report) conditionally set a column read-only with lov

    Hi
    I'm attempting to set a column that has a select list lov read-only if there is existing data in the column otherwise permit the end-user to enter a value using the select list.
    I've looked at Re: A better method of handling tabular forms with variable column type? and using this code as an example it almost works, except the select list lov button is still active and therefore the data can be changed. How does one conditionally disable the select list lov button in Javascript?
    TIA

    In the JS code where you make the field readonly, add another line to hide the lov opener link ( in jQuery it would be *$('<selector>').hide()* ).
    If you can provide the HTML code from your page for such a column (the JS code would depend on the template/theme), I can try helping.

  • Clicking on any row in a record set

    How can I click any where in a row and retrieve that records data in a report. I know how to highlight a row. Any help would be appreciated.
    Thanks
    Aron

    Hi Scott,
    I read your post. and I am able to go to another page when you click a row. that is fine. my real problem is i have a report say with 10 columns. so the user has to scroll all the way to the other side. when they are in the first column and select a particular row that is highlighted, but when they scroll that highlight disappears and they wont really know which row they were in when they selected the 1st column say.
    <BR> so what the user wants is highlight the whole row so that they will be able to know on which row they are in even when they scroll. (this is actually like a LOV screen, but they really want to highlight the row they are in, and have the flexibility to highlight another row and scroll to the last column if they have to)
    Thanks
    Knut

Maybe you are looking for

  • Receiver HTTP Adapter Dynamic Query String

    Hello, I am using HTTP Adapter on receiver side. My URL is  <b>http://server:port/abc/def?xyz=123&luw=345</b> When I am using Adapter specific attributes. If I check apply Parameters and pass Parameter 1 as xyz and Parameter 2 as luw and pass their v

  • Importing Canon 550d footage

    Hello again! What easy set up options should I use for Canon 550d footage? Thanks Ian

  • Help with transfering movies bought on iPhone to iPod

    In my iTunes under purchased movies it has all my movies. The ones that I bought on the computer all transfer to my iPod, but the ones I bought with my iPhone will not transfer to my iPod. It will not let me drag and drop those specific ones. I have

  • Abap knowledge for SD consultant

    Dear Friends,                    Iam a SD consultant, I want to know upto what extent Abap knowledge is required by a SD consultant. Please tell me on what topics we need have knowledge to be compitetive in market. I believe companies are looking for

  • Pulling clients over time in Prime Infrastructure

    Ive been trying to pull how many clients are connected to an AP hourly(to make a spreadsheet). The only place i can find this is in each individual AP, but it is in flash and you cannot save this. Was wondering if anyone have any ideas how to save th