ORA-01461: can bind to a LONG value only for insert into a LONG column

Hello

Oracle XE on RHE dedicated server
create table cvDetails(
cd_id number(14) primary key,
cv_id number(14) constraint education_fk references CvProperties(cv_id),
nationality varchar2(230),
objectives varchar2(3900),
name varchar2(230),
fatherName varchar2(230),
motherName varchar2(230),
dob varchar2(230),
gender varchar2(230),
mStatus varchar2(230),
passportNo varchar2(110),
email varchar2(230),
phone varchar2(45),
mobile varchar2(25),
address varchar2(2500),
state varchar2(230),
zipCode varchar2(230),
city varchar2(230),
education clob,
experience clob,
skills clob,
languages varchar2(1400),
hobbies varchar2(3200),
achievements varchar2(3900),
references varchar2(3900)
);

create sequence cvDetails_seq
start with 1 increment by 1;

create or replace trigger cvDetails_trig
before insert on cvDetails
referencing new as new
for each row
begin 
select cvDetails_seq.nextval into :new.cd_id from dual;
end;
/
Why do I get the error of subject?

Thank you in anticipation

>
in any case, I checked manually according to your instructions and found that this objective column is of character input more than specified.
>
Glad you found the problem, but I hope that you learned a lesson that is time consuming.

It must be remembered that we have no access to your environment. If we do not know which servers, clients, tables and users that you use.
It may seem simple to you but doesn't realize that you provide us with two slightly different versions of the cvDetails table.

The original post had this
>
objectives varchar2 (3900).
>
But when you have provided your 'cvDetails desc' journal text has
>
OBJECTIVES VARCHAR2 (3950)
>
It is the same table that you started with how the column suddenly grow 50 bytes?
This means that you did from different parts of the present in the two schemas or on two servers or you change the table between the two.

You can't address properly when you do this. By chance it is the column that you said is now the problem.
In SQL, the maximum length of a VARCHAR2 is 4000 bytes; no characters but bytes. Nothing more than 4000 bytes would probably be a LONG in the generic sense.

If your error
>
Re: ORA-01461: can bind to a LONG value only for insert into a LONG column
>
means that you try to 'bind a LONG value' to a column VARCHAR2 and you can't you can 'bind a LONG value only for insert in a LONG column.

In the proper context, the error makes sense.

You probably have a problem with

 ps.setString(2,  objectives);

because the 'objectives' has a length of more than 4000 bytes.

Remember this answer from you?
>
I have read and found that there may be a problem with the driver JDBC or Characterset. Am I wrong?
>
The 'Hello' ASCII string is five characters and five bytes because the ASCII code is a set of characters in a single byte. The same string internally in Java is five characters but ten bytes because Java uses UTF16.

So, if the character set of the data itself is double-byte character set then anything more than 2000 characters (4000 bytes) is a "LONG". And if your column is defined as VARCHAR2 (3950), which means bytes a doublel-byte character set which are characters of 1975.

Then you said in a response later
>
I checked by the SNA Server and oracle that are both of the same but new thing I found is that oracle does not allow more than one clob column in a table. Is this true?
>
Somehow a hypothesis has crept it that the problem was not a driver JDBC or Charaterset, but because you can not have more than one clob column in a table.

You could have easily tested for yourself by doing what P. Forstmann - tried to create a table and see.

Then you completely ignored my advice
>
I suggest to you isolate the columns actually causing the problem.
Change your code to insert only a few columns. When it works, add more than a few columns.
This will then tell you which column or the columns are at the origin of the problem.
Display the results once you determine a column that causes the error.
>
When you have finally made the simplest things, you have found what was causing the problem almost immediately.

Many times you don't need 'experts' - you must use a rigorous, methodical, process step by step.

ALWAYS, ALWAYS, ALWAYS reduce the simplest possible code example that illustrates the problem.
If you had followed this a rule would have probably found you the problem and makes you look like the 'expert '.

There are no shortcuts.

Tags: Database

Similar Questions

  • A weird exception in 12 c (ORA-01461: can bind to a LONG value only for insert into a LONG column)

    I have a Windows application that accesses a database of 12 c Oracle via ODBC (driver version is 12.01.00.01).

    I have a table with a column of key named REGION_ID (NVARCHAR2 (9)) and a dozen other columns, of which three are named region1 and region.2 elle3, all of type NVARCHAR2 (40).

    When I try to insert a string in the scope of the region1 is longer than 9 characters (length of REGION_ID), I get an error ORA-01461 (' can bind to a LONG value only for insert into a LONG column). If I set the length of REGION_ID be NVARCHAR2 (15), so I can add channels to the region1 in length up to 15 field until I get ORA-01461 exception again. Curiously, if I change the name of column region1 to REGIONONE, I don't get any errors, and everything works fine. It's almost as if the column name region1 is being confused with REGION_ID backstage.

    Any ideas? I am using SQLBindParameter to bind the columns, and all calls are successful. I get the exception when I run the insert statement. This same code worked for previous versions of Oracle (9i, 10g and 11g). And if I use a driver of client 11g against the 12 c server, I do not receive the exception.

    Thank you!

    It is a component of ODBC driver bug in 12 c and it is fixed. You can download and install the fix for bug 18232462 or the last window for 12 c patch cumulative/bundle.

    Thank you

    Spengler

  • ORA-01461: can bind to a LONG value only for insert into a LONG column of dynamic Action

    I try to apply the condition to display items in a table with the following error code.its dynamic action when him save the day.

    event: click on

    Selection type: button

    name of the button: P23_ADD_MORE_ROW

    condition: no strings attached

    //P23_NAME_BY_CAT,P23_HOW_MANY as LOV  in apex form
    var l_no_rows;
    l_no_rows = apex.item("P23_HOW_MANY").getValue();
    for (var i=0; i<l_no_rows; i++){
      apex.widget.tabular.addRow();
    
    if  ($v("P23_NAME_BY_CAT")==1) {
    $("#WORK_QTY").show();
    $('td[headers=WORK_QTY]').show();
    $("#WORK_LOCTION").hide();
    $('td[headers=WORK_LOCTION]').hide();
    $("#MY_LOCTION").hide();
    $('td[headers=MY_LOCTION]').hide();
    //with morethan 25+ entry
    }
    else if ($v("P23_NAME_BY_CAT")==2) {
    $("#WORK_QTY").hide();
    $('td[headers=WORK_QTY]').hide();
    
    $("#WORK_LOCTION").show();
    $('td[headers=WORK_LOCTION]').show();
    
    $("#MY_LOCTION").hide();
    $('td[headers=MY_LOCTION]').hide();
    //with morethan 25+ entry
    }
    else if ($v("P23_NAME_BY_CAT")==2) {
    $("#WORK_QTY").hide();
    $('td[headers=WORK_QTY]').hide();
    $("#WORK_LOCTION").hide();
    $('td[headers=WORK_LOCTION]').hide();
    
    $("#MY_LOCTION").show();
    $('td[headers=MY_LOCTION]').show();
    //with morethan 25+ entry
    }
    else {
    alert("no  count");
    }
    };
    
    

    dynamic action above can ignite if you level column, it means when I choose LOV value so that specified columns will show only rest in a column will be hidden. up to 10 input works fine.

    Hi Ramani_apex,

    Is the action of javascript executed in the dynamic action of the code you posted above or more code?

    You seem to have exceeded a 4000 or 32 K bytes on a column of metadata for dynamic action when you set the dynamic action.

    function f_mybuttonAction () {
    //P23_NAME_BY_CAT,P23_HOW_MANY as LOV  in apex form
    var l_no_rows;
    l_no_rows = apex.item("P23_HOW_MANY").getValue();
    for (var i=0; i
    
    • Call the action javascript function run the dynamic action javascript code:
    //mybutton action
    f_mybuttonAction();
    

    Reference:

    I hope this helps!

    Kind regards

    Kiran

  • APex 4.1 error ORA-01461: can bind to a value of type LONG only to insert them into a LONG

    Hello

    Faced with a strange question.

    I have a regular cursor, and in this loop of cursor, I have a select statement in some variables based on cursor settings.

    I was getting the "ORA-01461: can bind to a LONG value only for insert into a LONG column" error so I started the individual verification of each of the columns. Now, it works fine for some columns, but the moment I add this numeric field. He began to throw this error. Now, the source of the database where the selection is triggered is of type number, the variable in which I select is number.

    Infact, I have not any column defined anywhere.

    The strange thing is that the block is running perfectly fine in SQl developer. So, looks like a specific problem of the Apex.

    I'm in 4.1 / 11g

    Any ideas?

    Thank you
    Sun

    I'm NOT aware of documentation showing HOW the APEX team have built APEX (database design wise), but this met enough to collect that they use with a near limit of the VARCHAR2 VARCHAR2 columns size limit...

    I'm NOT aware of a limit on the size of the service procedure in the database.

    The code that you add to a form or report is stored in tables oracle APEX uses its called metadata (data about data)... So it would make sense that there are limits to how much can be stored in the form elements when developing... Try this, on a form region, go to the comment section and try to add a ton of comments or lines of text and save... You will hit a point where long error will happen (I'm now hitting, trying to replace sql selects for reports in an application, old registration code in case of questions, can not post in the comments field..)

    I believe in a dynamic action, you can have the run of the pl/sql code, so if you have a procedure called RunMyCode you could do that

      begin
    
       RunMyCode(:P1_AL,:P1_B);
    
      end;
    

    Where you large PL/SQL block could be stored...

    Thank you

    Tony Miller
    Dallas, TX

  • ORA-01461: can bind to a value of type LONG only to insert them into a column error

    Oracle 11g R1 RHEL 5 64-bit (Apex 3.1)

    Hi all

    I will have a hard time with this error:

    ORA-01461: can bind to a LONG value only for insert into a LONG column
    ORA-06512: at "FPRCHR. PKG_TRIGGER_EMAIL', line 39
    ORA-06512: at "ISWRNEW. PKG_NOTIFICATION', line 310
    ORA-06512: at "ISWRNEW. PKG_NOTIFICATION', line 1745
    ORA-06512: at line 1

    The FPRCHR. PKG_TRIGGER_EMAIL is as follows:

    ...
    INSERT INTO fprchr.trigger_email
    (trigger_email_rid,
    email_to,
    email_from,
    email_body,
    objet_message_electronique,
    email_cc,
    email_bcc,
    mime_type,
    email_priority
    )
    VALUES (l_job,
    p_recipients,
    p_sender,
    p_message,
    p_subject,
    p_cc,
    p_bcc,
    p_mime_type,
    p_priority
    );
    run immediately 'alter session set events 'name context 10046 trace off'. "
    Send END;
    ...


    It seems that the characters have exceeded the capable of handling VARCHAR2 limit? What other data type can change the table of fprchr.trigger_email to? Is that all that is needed?

    Thank you.

    It seems that the characters have exceeded the capable of handling VARCHAR2 limit? What other data type can change the table of fprchr.trigger_email to? Is that all that is needed?

    Have you tried with the clob data type?

    Kind regards.

    LOULOU

  • ORA - 01461:can bind a LONG value only for insert in a LONG column. After upgrade to 11g

    After update, oracle 11g, we get the system error when you try to insert the text string in the NCLOB type column.

    ORA - 01461:can bind a LONG value only for insert in a LONG column.

    This has not happened on an earlier version of Oracle.

    I did some testing and found that, if a string more then 2000 we get this error.

    How to solve this problem?

    Thank you

    I found a solution. I had to update ODP.NET to 2.112.1.0 version.

  • Is there a way just to have one or two applications, for example first pro cc or the two sequels. But I see LL is Photoshop for 9.99 per month, is there a way I can get just first pro cc only for 9.99 or something like that?

    Is there a way just to have one or two applications, for example first pro cc or the two sequels. But I see LL is Photoshop for 9.99 per month, is there a way I can get just first pro cc only for 9.99 or something like that? I don't

    # Photography is one of its kind special promotion. There is no other package prioritized at a similar discount. You can get single app or CC full plans.

    Mylenium

  • I plan to change the plan of creative photography of cloud. I currently use 5.7 LR with photoshop elements as my level of pixel Editor.  The question I have is if with the plan CC I can choose to download photoshop CC only for now. I'd do it

    I plan to change the plan of creative photography of cloud. I currently use 5.7 LR with photoshop elements as my level of pixel Editor.  The question I have is if with the plan CC I can choose to download photoshop CC only for now. I prefer wait to download LR CC if possible, but didn't know if I could download one without the other. Thanks for your time.

    Hello

    Yes, you could download Photoshop cc only as well.

    Concerning

    Gilles marneffe

  • Instead of trigger is running, but the values are not inserted into the view

    I created a view
    create or replace view as select e.department_id, e.last_name, d.department_name employee e, Department d where e.department_id = d.department_id;

    create or replace trigger trgg instead of inserting it on vns for each line
    declare
    The CNT number;
    Start
    Select count (*) in the cnt of employees where department_id =:new.department_id;
    If cnt = 0 then
    insert into employees (department_id, last_name) values(11,'nandu');
    end if;
    Select count (*) in the cnt of the Department where department_id =:new.department_id;
    If cnt > 0 then
    insert into dept (department_name) values('wrestling');
    end if;
    end;
    /
    This is the code required. .plz answer the right
    create or replace view
    vns as
    select e.department_id,e.last_name,d.department_name
    from employees e,departments d
    where e.department_id=d.department_id;
    
    create or replace trigger trgg
    instead of insert on vns
    for each row
    declare
    cnt number;
    begin
    select count(*) into cnt from employees where department_id=:new.department_id;
    if cnt=0 then
    --insert into employees(department_id,last_name) values(11,'nandu');
    insert into employees(employee_id,email,hire_date,job_id,department_id,last_name)
                   values(207,'[email protected]',sysdate,'AC_MGR',11,'nandu');   --- Values you have to choose!!
    end if;
    select count(*) into cnt from departments where department_id=:new.department_id;
    if cnt>0 then
    insert into departments(department_id, department_name) values(11, 'wrestling');  -- department_id is needed
    end if;
    end;
    /
    
    -- testing with existing dept id = 10
    
    insert into vns(department_id) values(10);
    
    SQL> select * from departments where department_id = 11;
    
    DEPARTMENT_ID DEPARTMENT_NAME                MANAGER_ID LOCATION_ID
    ------------- ------------------------------ ---------- -----------
               11 wrestling
    

    Requirement, you must be knowing well
    Show you how the trigger must be according to your point of view and logic inside the trigger or you recreate in order to avoid the required values in the trigger body.

    Thank you!

  • ORA-06550: PLS-00394: wrong number of values in the list INTO a mesh FETCH

    Dear friends,
    I ask you a suggestion:

    The following code inserts a table errors (errori_work), the IDS of the records repeat (in the work of the table), but gives me this error:
    ORA-06550: PLS-00394: wrong number of values in the list of a FETCH statement INTO.

    The work of the table has the 78 columns: the problem of the fields used in the slider flew against the 78% ROWTYPE fields?
    I could use a record declared as the cursor (rec_tabwork cu_tabwork % ROWTYPE;), but in the MANUAL I need a field (ID_WORK) is not present in the cursor.

    declare
    CURSOR cu_tabwork IS
    SELECT CD_STRUTTURA, CD_SUB_STRUTTURA, NR_PRATICA, likelihood
    Work
    CD_STRUTTURA, CD_SUB_STRUTTURA, NR_PRATICA, applications GROUP
    HAVING COUNT (rowid) > 1
    UNION ALL
    SELECT CD_STRUTTURA, CD_SUB_STRUTTURA, NR_PRATICA, likelihood
    Work
    CD_STRUTTURA, CD_SUB_STRUTTURA, NR_PRATICA, applications GROUP
    After HAVING COUNT (rowid) > 2.
    rec_tabwork work % ROWTYPE;
    BEGIN
    Open cu_tabwork;
    loop
    extract the cu_tabwork in rec_tabwork;
    If FOUND then % cu_tabwork
    dbms_output.put_line (rec_tabwork. (ASL); -test
    INSERT INTO errori_work
    (cd_errore, note, ID_WORK)
    )
    VALUES ("ACC", "Record ripetuto nella table work", rec_tabwork.ID_WORK)
    );
    end if;
    EXIT WHEN cu_tabwork % NOTFOUND;
    end loop;
    close cu_tabwork;
    end;

    Can you help me?
    Thank you
    Leo

    Hello

    I loaded your data and ran the query. It's coz the NR_RICETTA contains a null value, so your State A.NR_RICETTA = B.NR_RICETTA will fail when it checks for NULL = NULL. Here is your output from the query

    PRAZY@orcl> select count(ID_AMBS) FROM WORK A
      2  WHERE A.ROWID > ANY (SELECT B.ROWID FROM WORK B
      3  WHERE A.CD_PRESIDIO        =B.CD_PRESIDIO
      4  AND A.GGMM_CONTATTO        =B.GGMM_CONTATTO
      5  AND A.NR_RICETTA   =B.NR_RICETTA
      6  AND A.CD_CONT_PRESCR       =B.CD_CONT_PRESCR
      7  AND A.NR_PROG_INT  =B.NR_PROG_INT
      8  AND A.DESTINAZIONE =B.DESTINAZIONE)
      9  /
    
    COUNT(ID_AMBS)
    --------------
                48
    
    Elapsed: 00:00:00.00
    

    Therefore, I have included NVL to A.NR_RICETTA, which will produce true when it finds null checking 0 = 0 and you will get your result. and this is what you are looking for

    PRAZY@orcl> select count(ID_AMBS) FROM WORK A
      2  WHERE A.ROWID > ANY (SELECT B.ROWID FROM WORK B
      3  WHERE A.CD_PRESIDIO        =B.CD_PRESIDIO
      4  AND A.GGMM_CONTATTO        =B.GGMM_CONTATTO
      5  AND NVL(A.NR_RICETTA,0)    =NVL(B.NR_RICETTA,0)
      6  AND A.CD_CONT_PRESCR       =B.CD_CONT_PRESCR
      7  AND A.NR_PROG_INT  =B.NR_PROG_INT
      8  AND A.DESTINAZIONE =B.DESTINAZIONE)
      9  /
    
    COUNT(ID_AMBS)
    --------------
                61
    
    Elapsed: 00:00:00.01
    

    If you want to insert the duplicate ID in a Table of errors, do an insert with the following select statement.

    INSERT INTO errori_work(cd_errore, note, ID_AMBS)
    SELECT 'CAC', 'Record ripetuto nella tabella Work',ID_AMBS FROM WORK A
    WHERE A.ROWID > ANY (SELECT B.ROWID FROM WORK B
    WHERE A.CD_PRESIDIO     =B.CD_PRESIDIO
    AND A.GGMM_CONTATTO     =B.GGMM_CONTATTO
    AND NVL(A.NR_RICETTA,0)     =NVL(B.NR_RICETTA,0)
    AND A.CD_CONT_PRESCR     =B.CD_CONT_PRESCR
    AND A.NR_PROG_INT     =B.NR_PROG_INT
    AND A.DESTINAZIONE     =B.DESTINAZIONE);
    

    Hope that solves your problem.

    See you soon!

  • How to perform an addition of column values in an insert query that would insert in the 3rd column, and the values how to insert into another table.

    I have two tables (2) RESULT TAB (1)

    CREATE TABLE TAB

    (

    NUMBER OF SNO

    A NUMBER,

    B THE NUMBER.

    NUMBER OF THE SUM

    );

    CREATE AN ARRAY OF RESULT

    (

    NUMBER OF SNO

    NUMBER OF THE SUM

    )

    my doubt is:

    (1) I want to insert a table TAB, my question is how to insert a column to the SUM using the column A AND B... Here im adding two values of the column and store result in the AMOUNT column.

    SNO   A  SUM           

    1 100 150 250

    2 300 100 400

    I want to like this, it is possible with single insert query?


    (2) at the time of the insertion TAB of values that SNO, and the values of table TAB $ insert in the table of RESULTS... is it possible these two inserts at the same time?

    in fact, im using another this table.fro TAB and easy to understand I write like that, please solve this problem

    First, you post in the wrong forum as this one is only for Oracle's SQL developer tool. So you might ask your question in the general forum of SQL.

    Second, you might solve your problems with bind variable:

    Insert tab

    (sno, a, b, sum)

    values

    (: SNO,: A: B: A + B :))

    You should not use sum as column name because it is a reserved word.

    More you cannot insert into two different tables with a single SQL, but you can use PL/SQL to do this:

    Start

    insert into tab values (: SNO,: A: B: A + B :);)

    insert into result values (: SNO,: A + B :);)

    end;

    If you meet sno from a sequence, you could do something like this:

    Start

    insert into values tab (seq_sno.nextval,:,: B,: A +: B) return sno in: SNO.

    insert into result values (: SNO,: A + B :);)

    end;

    Hope that helps,

    dhalek

  • Managed pilot throws ORA-01483 or ORA-01461 when inserting the CLOB

    I think I found a bug in the driver managed to ODAC 12 c Release 3 (12.1.0.2.1). It is similar to that examined in problem with Managed ODP.NET driver update nclob raises ORA-01483, but also happens with shorter CLOB. Maye added challenge is therefore necessary.

    I'm trying to insert two strings to the CLOB columns in addition to the other columns. Although I try to insert the same data, a different error is thrown depending on the order of the parameters.

    If I first bind the shorter string, the error is:

    ORA-01483: invalid length for the DATE or NUMBER variable binding

    If I bind the longer string first, the error is:

    ORA-01461: can bind to a LONG value only for insert into a LONG column

    Please see the archive attached to a solution of the sample that reproduces the two errors.

    The system environment:

    • The driver is fully managed from ODAC 12 c Release 3 (12.1.0.2.1) - the pilot who requires that the instant client does not show this problem.
    • .NET framework 4.5.2
    • Windows 7 SP1 x 64
    • Server: 11.2.0.4.0 running on Windows Server 2008 R2 x 64

    Unfortunately, this errors occur quite often in my application and prevent me to move to the managed pilot, so a bug in output or workaround would be greatly appreciated.

    Hello

    As I wrote above, 20361140 patch resolves the issue.

    Patch 20684004 (DB Windows Bundle Patch 12.1. 0.2.4) and hotfix 20684157 (Windows Bundle Patch 12.1.0.2.5 DB) does not contain the fix. They do not contain an updated ODP.NET file.

    The right patch 21020286 (DB Windows Bundle Patch 12.1. 0.2.6) once again does not contain the fix. This is the latest version of ODP.NET I know. His version of product is 4.121.2. 20150515

    I would also like to see a NuGet package update. Handling everything patches manually, it is really a pain.

    Edit: as written below, an updated NuGet package was released. There the 12.1.22 version

  • SQL to align the values of the child with the parent columns

    Hello world

    I'm stumped on how to develop a sql query that generates a report which my child values are aligned with my columns parent based on corresponding years.  Here is an example...

    create table test_yr (yr_id number primary key, yr_nb number);
    insert into test_yr values (1,2013);
    insert into test_yr values (2,2014);
    insert into test_yr values (3,2015);
    
    create table test_parent (parent_id number primary key, parent_yr_id_begin number, parent_title varchar2(100));
    alter table test_parent add foreign key (parent_yr_id_begin) refererences test_yr (yr_id);
    insert into test_parent values (1,1,'This rec starts in 2013');
    
    create table test_child (
         child_id number primary key,
         child_parent_id number,
         child_yr_id_begin number,
         child_title varchar2(100),
         child_yr1_val number, child_yr2_val number, child_yr3_val number, child_yr4_val number, child_yr5_val number
    );
    alter table test_child add foreign key (child_parent_id) references test_parent (parent_id);
    alter table test_child add foreign key (child_yr_id_begin) references test_yr (yr_id);
    insert into test_child values (1,1,3,'This rec starts in 2015',10,20,30,40,50);
    insert into test_child values (2,1,3,'This rec starts in 2015',15,25,35,45,55);
    
    
    

    The child can begin to another to start the year as the parent, which makes different yr1 for parent and yr1 for child.  So, for this example, the child 1 year (2015) = year 3 of the parent.

    I can get the values strictly of the child using the following...

    select child_yr1_val, child_yr2_val, child_yr3_val, child_yr4_val, child_yr5_val
    from test_child
    where child_parent_id = 1;
    
    

    However, I need the report to be based on the first five years of the parent.  And since the child does not start until 2015, two years should be zero.  This is the expected result:

    Yr1 | YR2 | YR3 | yr4 | Yr5

    ---------------------------

    0   | 0   | 10. 20. 30

    0   | 0   | 15. 25. 35

    I am doing it using simple sql without having to use pl/SQL to derive a dynamic query.  But I need to somehow to the height and line up the years... like in this example, yr1 (child) = yr3 (parent), (child) yr2 = yr4 (parent), etc..  I hope that some joints and case statements will do the trick, but I don't know how to use them to get the result that I need.  Can anyone help?  Oracle 11 g 2.

    Thank you

    Mark

    Hi, Mark,.

    Here's one way:

    WITH unpivoted_child AS

    (

    SELECT child_id, child_parent_id

    child_yr_id_begin + child_yr - 1 AS column_num

    val

    OF test_child

    UNPIVOT (val

    FOR child_yr (child_yr1_val AS 1

    child_yr2_val AS 2

    child_yr3_val AS 3

    child_yr4_val AS 4

    child_yr5_val AS 5

    )

    )

    WHERE child_parent_id = 1

    )

    SELECT NVL (y1, 0) AS yr1

    , NVL (y2, 0) AS yr2

    , NVL (y3, 0) AS an3

    , NVL (y4, 0) AS yr4

    , NVL (y5, 0) AS yr5

    Of unpivoted_child

    PIVOT (SUM (val)

    FOR column_num IN (1 AS y1

    2 AS y2

    3 AS y3

    4 AS y4

    5 AS y5

    )

    )

    ORDER BY child_parent_id

    child_id

    ;

    Have 5 columns in the test_child that all say the same thing, obly for different years, isn't a very good design table.  It wouyld be better to have a single table for all the attriburtes that apply to the child and another table for each combination of year, with a single amount on each line.  Because you don't have that, the unpivoted_child of the subquery, it essentially creates on the fly.

  • How to show the value of string with spaces in separate columns

    Hi all, I am using Oracle 10 g.

    create table
    create table sample_test (
      Name    VARCHAR2(20 BYTE))
    Insert a table
    insert into sample_test values ('JOAN   SCT')
         insert into sample_test values ('MELIA FILCK')
          insert into sample_test values ('SSAN LIER-LILEY')
           insert into sample_test values ('C.M. DANY WES')
               insert into sample_test values ('A L SCOTT')
    Select * from sample_test;
    Name
    JOAN   SCT
    MELIA FILCK
    SSAN LIER-LILEY
    C.M. DANY WES
    A L SCOTT
    I would like the following output
    NAME1        NAME2      NAME3
    JOAN          SCT               
    MELIA        FILCK               
    SSAN       LIER-LILEY
    C.M.          DANY       WES
    A             L          SCOTT
    whenever there is a space in the name of the value next to who should be included in another column. Please note the name joan has TBS of two spaces. but it must be treated as a single space.

    also is it possible to get something like that
    NAME1        NAME2     
    JOAN          SCT               
    MELIA        FILCK               
    SSAN       LIER-LILEY
    C.M.DANY       WES
    A L          SCOTT
    the value before the first space on the right must be everything in domain Name1 Name2.

    Thanks in advance.

    Hello

    Since you have Oracle 10, you can use regular expressions:

    For the release of 3 columns:

    SELECT        REGEXP_SUBSTR (name, '[^ ]+', 1, 1)     AS name1
    ,        REGEXP_SUBSTR (name, '[^ ]+', 1, 2)     AS name2
    ,        REGEXP_SUBSTR (name, '[^ ]+', 1, 3)     AS name3
    FROM        sample_test;     
    

    [^ xyz] means "any character except x, y or z."
    + means "1 or more of the previous ones.
    The 4th argument to REGEXP_SUBSTR indicates where we want the appearance of the model.

    For the release of 2 columns:

    SELECT        REGEXP_REPLACE (name, ' *[^ ]+$')     AS before_last_space
    ,        REGEXP_SUBSTR  (name,   '[^ ]+$')     AS after_last_space
    FROM        sample_test;
    

    $ here means "the end of the string.

    In Oracle 10, you will often use REGEXP_REPLACE to get substrings.

    Thanks for posting the CREATE TABLE and INSERT statements; It's very useful!

    Published by: Frank Kulash, 7 Sep 2011 15:21

  • How to retrieve the value from the insert statement

    Hello
    How can I get a certain value of the insert and store it in a variable.
    Suppose that I am inserting emp_no, emp_name, emp_salary for the employee table
    and I want to record the emp_name in a variable for further processing,
    How can I accomplish this? I guess I should use the trigger,
    but do not know the procedure.
    any help will be greatly appreciated
    Thank you

    insert into

    values (...) return in

    You can and should have found that using the SQL language reference manual
    or
    http://www.morganslibrary.org/reference/insert.html

    --------
    Sybrand Bakker
    Senior Oracle DBA

Maybe you are looking for