Insert a default line where there is no data

Hi using Oracle 10 g, I stuck a simple simulation below... I would like to insert a default value of "42" to the province of "AB", is a set of records for all products that do not exist in all provinces, would therefore create a line with the corresponding province to the right join.  Hope this makes sense...


CREATE TABLE TBL_TEST1

(PROD_ID VARCHAR2 (10), VARCHAR2 (2) OF THE PROVINCE, THE NUMBER OF PRIZES);

INSERT ALL

IN TBL_TEST1 (PROD_ID, PROVINCE, PRICE) VALUES ('42', "BC", 178)

IN TBL_TEST1 (PROD_ID, PROVINCE, PRICE) VALUES ('42', 'MT', 178)

IN TBL_TEST1 (PROD_ID, PROVINCE, PRICE) VALUES ('42', 'NB', 178)

IN TBL_TEST1 (PROD_ID, PROVINCE, PRICE) VALUES ('42', "NF", 178)

IN TBL_TEST1 (PROD_ID, PROVINCE, PRICE) VALUES ('42', 'NS', 178)

IN TBL_TEST1 (PROD_ID, PROVINCE, PRICE) VALUES ('42', 'ON', 178)

IN TBL_TEST1 (PROD_ID, PROVINCE, PRICE) VALUES ('42', 'PI', 178)

IN TBL_TEST1 (PROD_ID, PROVINCE, PRICE) VALUES ('42', 'SK', 178)

SELECT * FROM DUAL;

-SELECT * FROM TBL_TEST1

CREATE TABLE TBL_PROV

(PROV. VARCHAR2 (2));

INSERT ALL

IN TBL_PROV (PROV) VALUES ("AB")

IN TBL_PROV (PROV) VALUES ("BC")

IN TBL_PROV (PROV) VALUES ("MT")

IN TBL_PROV (PROV) VALUES ('NB')

IN TBL_PROV (PROV) VALUES ('NC')

IN TBL_PROV (PROV) VALUES ('NS')

IN TBL_PROV (PROV) VALUES ('ON')

IN TBL_PROV (PROV) VALUES ("PI")

IN TBL_PROV (PROV) VALUES ('SK')

SELECT * FROM DUAL;

-SELECT * FROM TBL_PROV;

SELECT

A.PROD_ID

COALESCE(A.PROVINCE, B.PROV)

NVL(A.PRICE,0)

Of

TBL_TEST1 HAS

RIGHT OUTER JOIN

TBL_PROV B

WE A.PROVINCE = B.PROV;

3031421 wrote:

Hi Frank,.

So I want the select to return all the lines by product ID.  Not all ID's products are available in all provinces.  So, using the Province TBL_PROV list table as a reference, I want to show a line for each province Product_ID in the TBL_PROV table.  The select statement, I posted does not list the product ID for the "AB" province, so even if there are 8 rows in the product table, yes I would show 9 lines with the overall product id...

42 BRITISH COLUMBIA 178
42 MT 178
42 NB. 178
42 NF 178
42 NS 178
42 WE 178
42 PI 178
42 SK 178
42 AB 0

Good, then you don't want to INSERT new data into a table. you just want to a new row in the result set.

It would be helpful if you posted some examples of data for tbl_test1 who had a couple of prod_ids different and different prices.

You want all prod_id in tbl_test1 combined with all the provinces of the tbl_prov?

If so, you can use an outer join partitioned, like this:

SELECT t.prod_id

p.prov

, COALESCE (t.price, 0) IN the price

OF tbl_prov p

LEFT OUTER JOIN tbl_test1 t PARTITION BY (t.prod_id)

ON t.province = p.prov

ORDER BY prod_id

Prov.

;

Why did you use COALESCE to the provinces, but prices NVL?  If you like COALESCE, as it would be infinitely faster, wouldn't it faster in both places?  If you like NVL because it is easier to code, it will be easier to code in both places?

In this case, you have no need either for the province, assuming that tbl_prov is never NULL (and even if this is the case, it will never reach the join condition).

Almost no one is never using RIGHT OUTER JOIN, because the same results are always possible with LEFT OUTER JOIN.  Partitioned outer joins operate in the same way that you use the LEFT or RIGHT.  It's as if you did a separate outer join for each value of the partitioning column, and and made a UNION ALL operation to combine all separate them the results.

Tags: Database

Similar Questions

  • Word RTF Tem [plate - insert a blank line in the loop

    I'm entering my template like this XML data (this is just an example of dumbed down):

    <? XML version = "1.0"? >

    < LABEL_TEST >

    < LIST_G_TEST >

    < G_LABEL_HEADER >

    < NAME > Parent 1 < / NAME >

    < / G_LABEL_HEADER >

    < G_LABEL_HEADER >

    < NAME > Kid 1 < / NAME >

    < / G_LABEL_HEADER >

    < G_LABEL_HEADER >

    < NAME > Parent 2 < / NAME >

    < / G_LABEL_HEADER >

    < G_LABEL_HEADER >

    < NAME > Parent 3 < / NAME >

    < / G_LABEL_HEADER >

    < G_LABEL_HEADER >

    < NAME > 4 Parent < / NAME >

    < / G_LABEL_HEADER >

    < G_LABEL_HEADER >

    < NAME > Kid 4 < / NAME >

    < / G_LABEL_HEADER >

    < / LIST_G_TEST >

    < / LABEL_TEST >

    In summary, I have a list of Parents, and if they have a child, the name of their children is below. Not all parents have children.

    If the data is a bit like this:

    Name of the parent

    Name of the child

    Name of the parent

    Name of the parent

    Name of the parent

    Name of the child

    When I loop data in my RTF model, I want to be able to insert a blank line before all of the lines 'Parent '. A bit like this:

    Name of the parent

    Name of the child

    Name of the parent

    Name of the parent

    Name of the parent

    Name of the child

    I tried to do this by adding an empty xml tag in the list, like this:

    <? XML version = "1.0"? >

    < LABEL_TEST >

    < LIST_G_TEST >

    < G_LABEL_HEADER >

    < NAME > Parent 1 < / NAME >

    < / G_LABEL_HEADER >

    < G_LABEL_HEADER >

    < NAME > Kid 1 < / NAME >

    < / G_LABEL_HEADER >

    < G_LABEL_HEADER >

    < NAME > < / NAME >

    < / G_LABEL_HEADER >

    < G_LABEL_HEADER >

    < NAME > Parent 2 < / NAME >

    < / G_LABEL_HEADER >

    < G_LABEL_HEADER >

    < NAME > < / NAME >

    < / G_LABEL_HEADER >

    < G_LABEL_HEADER >

    < NAME > Parent 3 < / NAME >

    < / G_LABEL_HEADER >

    < G_LABEL_HEADER >

    < NAME > < / NAME >

    < / G_LABEL_HEADER >

    < G_LABEL_HEADER >

    < NAME > 4 Parent < / NAME >

    < / G_LABEL_HEADER >

    < G_LABEL_HEADER >

    < NAME > Kid 4 < / NAME >

    < / G_LABEL_HEADER >

    < / LIST_G_TEST >

    < / LABEL_TEST >

    But that doesn't seem to work.

    Manny

    I found a solution that works very well.

    I added a new XML field to my data called .  In my model, this field is inserted in the line, but in a location where there is no data being printed. And it is formatted as white text, so that it basically just does not appear.

    So essentially, it's what I have now:

    Parent 1

    .

    Child 1

    .

    .

    Parent 2

    .

    .

    Parent 3

    .

    .

    Mother 4

    .

    Child 4

    .

    If the data is a bit like this:

    The name of the parent.

    The name of the child.

    .

    The name of the parent.

    .

    The name of the parent.

    .

    The name of the parent.

    The name of the child.

    When I loop data in my RTF model, the '. ' is a white text, then I get this:

    Name of the parent

    Name of the child

    Name of the parent

    Name of the parent

    Name of the parent

    Name of the child

  • Command line cursor drives me crazy. I never want to turn overtype mode, but it lights up just at the moment where I'm trying to insert something online. Is there a way to keep overtype mode?

    64 bit

    Vista SR2

    I use a lot the command line to test the python scripts. I never I want to turn overtype mode but it turns on itself just when I try to insert something online. Is there a way to keep overtype mode?

    BTW, I don't have this problem with another computer that is running Windows 7.

    Thank you

    Hello

    Refer to this link: http://bugs.python.org/issue10165

    I suggest you contact Python for more information:

    http://www.Python.org/community/

    Diana

    Microsoft Answers Support Engineer

    Visit our Microsoft answers feedback Forum and let us know what you think.

    If this post can help solve your problem, please click the 'Mark as answer' or 'Useful' at the top of this message. Marking a post as answer, or relatively useful, you help others find the answer more quickly.

  • CP5 narrow legends: insert a new line between existing lines

    In the Notes slide - closed captioning - 'Folienaudio' / 'Bilduntertitel' (narrow legends) is already there lines 1, 2, 3 and 4. I need to insert a new line between lines 3 and 4, but the + always opens a new line to the 2nd line.

    Is there a way to overcome this problem?

    Hello

    This can be done safely by the tab this subtitle in the audio slide dialog box.

    1. call the audio slide dialog box (shortcut: F5)

    2. go to the tab captions

    3. play audio

    4 stop the audio to the point where you need to add subtitles

    5. click on the button '+' to add captioning to the place you need.

    6. click on 'Save' to save the changes.

    This will save time.

    Rick: It could probably also completely accomplish the CC dialog box. I saw the recent problems reported with operation directly from this dialog box in CP5, so I offered to beginning of slide Notes.

    Ashwin: I do not see problems here Rick...

    Remi - Ashwin B

  • How better to insert a subarray (line) in a 2D array to the correct index which is based on the value of the first column

    Hello

    I would like to insert a subarray (line) in a 2D to the correct index table. The position is to say the index value depends on the value of the first column of the table 2d.

    As an examlple my 2d array would look like this

    230 50 215 255

    300 60 270 330

    360 20 350 370

    And I would like to insert another line (subarray) with the following values

    320 40 300 340

    This new line should be placed between the second and third rows (this is based on the first column only).

    I tried the threshold 1 d function table by taking an 1Dsub array of my 2d array (first column), then using the first of the new line (320) as the threshold. It sort of work, but it does not work when I start the table (IE there is only 1 row) and it seems to not work properly on other occasions (as explained in the help of Labview).

    Hopefully the explanation is clear enough for any suggestion. Thanks in advance for the help!

    JTRI wrote:

    The idea is I have start with a new table and add these lines in the right order every time that the user sets the values Jack

    Ahh, so try this.

    This will also work with an empty array.

    You want to do with this function it is a Subvi.

    Make the entries 'table' and 'subarray"on the connector, then 'new array' output.

    You can then put this Subvi in a loop with a registry to shift and it will help to add new lines in a sorted order, when they are added.

    That is what you were aiming for?

  • Question: insertion of several lines in the MS Sql Server table using the DB adapter

    Hi all

    I managed to insert a single row in a table of MS SQL Server via the adapter DB to my process BPEL, but when I tried to insert in mutiple lines in the same table of MS SQL server, I encounter the error below.

    I use a DB SQL XA connection to connect to the server.

    Kindly help me to solve the problem. Thanks in advance.

    Error:

    " < bpelFault > < faultType > 0 < / faultType > < remoteFault xmlns =" http://schemas.Oracle.com/BPEL/extension "> < a name ="summary"part > < summary > exemption is is produced when the binding was used." Exception occurred during invocation of the JCA binding: "JCA binding run 'merge' reference operations have to: DBWriteInteractionSpec Execute Failed Exception." the merger failed. The descriptor name: [LoadCmpAggSpendStage.SapTable]. Caused by com.microsoft.sqlserver.jdbc.SQLServerException: incorrect syntax near ')'... Check the logs for the record output full DBAdapter before this exception. This exception is considered as reproducible, probably due to a communication failure. To be classified as not reproducible rather add property nonRetriableErrorCodes with the '102' value in the deployment descriptor (i.e. weblogic - RA.Xml). Auto retry a reproducible fault set composite.xml for this invoke these properties: jca.retry.interval, jca.retry.count and jca.retry.backoff. All properties are integers. ". The called JCA adapter threw an exception of resource. Please examine the error message above carefully to determine a resolution. < /Summary. (> < / piece > < part name = "detail" > < detail syntax > incorrect near ')'. < / details > < / piece > < part name = "code" > < code > 102 < / code > < / piece > < / remoteFault > < / bpelFault >

    Kind regards

    Balaji Rahmani

    It seems that in this case is called merge operation. If existing records (check primary key) are not there then it will be inserted on the other update. Check the syntax of the query that is created. It looks like she may have a supplement "). If you want to only insert then call insert operation and not merge.

  • Help: How can I change the default line by 15 to 100 page?

    Hello

    Our database table has a large amount of data. On the one hand of the error type column, we could have 1378 data for the type of the onr and our application need at least in spring to 100 or 200 per page in order to check and remove 100 lines. For example, if there are 400 lines of type VITA100 error data, using a page impression 100 lines, the user will erase the data 4 time using the button Delete. Now if the page print 15 ranks in time then the user erases data more then 25 times.

    The problem is because we have a lot of data and when I run the report, click the action button, go to the page by lines from the context menu and change to 100, APEX will freeze all trying to deal with this and it will always and it is painful to watch take everyday whithout changing. Page blocks all the time while this process does not work for us for this particular application. I can do for other applications that access the data that is on a 6000 lines. So for now, I need the mechanism to change lines with the attribute of paging and here, I don't have much to work with.

    Can someone help me how to change the line value default report down with the following icon at 100.

    Thank you.

    1013278

    To set the number of lines shown as default value to a value other than 15.

    1. If the action menu is not enabled to activate the interactive report. Make sure 'Lines per Page' and 'Save the report' are checked.
    2. Now run the page and use the menu Action > lines per page to set the number of lines you want.
    3. Save the hollow new report the action menu.
    4. When you are prompted, choose to save "as a default report parameters".
    5. Then choose "primary".

    The number of lines displayed by default is now permanent has changed.

    If users are not allowed to use the action menu you can now turn off again.

    The record of the report as a default report parameters for the other settings of the action menu also works well.

    Nicolette

  • Insert a blank line in the query output

    Is it possible to insert a blank line between two rows of the query output?

    In the EMP table, the column LINES is as follows:

    LINES
    1
    2
    3
    4
    1
    2
    3
    1
    2
    3
    4
    5

    I want to insert a blank line after every 1

    Please suggest.

    Sanjay

    I'm quite puzzled why you need rows in the dataset returned by a select statement that is empty.
    If you are using Oracle reports to the release date, you define the presentation of the report to have spaces between the rows returned by the select and have do not need to have the select statement returns a blank line after each line of data. If the output should be obtained by using another client, I think that the customer will have facilities for output formatting.

    Admit that you really need "blank lines" between data lines, I see only one way: use a temporary table and do an insert into select temporary_table (...) ... from... where... Then, in this temporary table, you can insert 'empty rows', which is actually not really empty, because they must have some fields that give the order of the rows. And then select in temporary_table, you place your order by the columns that are used to give the order for the release.
    Thus

    insert into temporary_table (
    ....
    )
    select ...
    from ...
    where ...
    ;
    for r in (
    select col1, col2, col3  -- columns used for order by
    from temporary_table
    order by col1, col2, col3
    )
    loop
      insert into temporary_table (col1, col2,col3, col4)
      values (r.col1,r.col2,r.col3, null);
    end loop;
    -- this way, a select * from temporary_tabel order by col1, col2, col3, col4 will return a blank row after each data row
    
  • Failed to insert a new line with a column generated sequence id

    Hello

    I'm trying to insert a new row in a table containing a column of sequence according to db, used as the primary key.

    Here is the code for the custom method of the corresponding AM I use to insert the new line:

    Line row2 = getCaAppointments1 () .createRow ();
    row2.SetAttribute ("Member ID", Member ID);
    row2.SetAttribute ("Status", "Planned");
    row2.SetAttribute ("CreatedBy", coachId);
    row2.SetAttribute ("CreationDate", date);
    AppointmentId will be generated by the sequence
    DBSequence newId = row2.getAttribute("AppointmentId") (DBSequence);
    SequenceImpl s = new SequenceImpl ("XX_CA_APPOINTMENT_ID", getDBTransaction());
    Long next = newId.getSequenceNumber () .longValue ();
    System.out.println ("Got sequence as id:" + newId);
    row2.SetAttribute ("AppointmentId", newId);
    row2.SetAttribute ("CoachId", coachId);
    row2.SetAttribute ("Type", "0");
    row2.SetAttribute ("AppointmentNumber", 0);
    row2.SetAttribute ("PlannedDate", Department of justice);
    getCaAppointments1 (.insertRow (row2));

    I put the attribute EO 'AppointmentId' to use a DBSequence. I tried different combinations to get the sequence Id and insert a line. Nothing worked well and I'm unable to insert a new line.

    If I avoid using the attribute 'AppointmentId' and that you try to insert a row, it will fail with the error below:

    ORA-01400: cannot insert NULL into ('APPS'. "" "" XX_CA_APPOINTMENTS '. "" APPOINTMENT_ID") ORA-06512: at line 1

    Tried to insert the new row using BCTester but I am struck by the same error it (I was unable to change the value of the "AppointmentId" column when inserting the line because this column is read-only and it showed as - 2 value).

    I guess, since the attribute of column/is already marked to use a DBSequence, the value should be assigned by default and I shouldn't hit "cannot insert the value NULL to the column.
    Did I miss something necessary to trigger the sequence to automatically generate new Id and assign it to the new line before it is created?

    Please let me know the fix.

    Thanks in advance
    Rouhaud

    Hello

    Oracle changes this behavior each version, so I hope that its still OK.
    If you have a trigger on the table that inserts the value of the id if none is preset, then mark it as DBSequence, or be it the number.

    Now for your entity, just generate the impl class and override the method create, kind of old school, I know, but it never fails.
    In the create just add the code to your sequence you had:

    SequenceImpl seqImpl = new SequenceImpl("", thisTransaction);
    Number idValue= s.getSequenceNumber();
    setAttribute("Id", idValue);
    

    -Anton

  • How to insert a new line in a table?

    I have a table of basic bit of lines and columns.

    In excel if I want to insert a blank line in the Middle, I just click right and do it.

    In DW, I am at a loss what to do. Thank you.

    It is very similar to the DW.  Right-click in a cell, and then click Table-> Insert a row or a column.  There is options to add several lines above or below.

  • Sporadic emails sent, transmitted mainly from the emails contain this symbol everywhere where there is a space, and the receiver cannot read emails easily

    In the course of the last 3 weeks, forwarded emails mainly, but occasionally sent standard mail are received by the receiver with the included symbol everywhere where there is a space or a comma reversed in the email. The receiver can not easily read the e-mail that there is a working email address, it is very professional. I tried to change the default text encoding, but it makes no difference. Help? I tried to look for an alternative e-mail program, but as a long term user of Thunderbird, I can't find anything that comes even close to it. Please help me find a solution to this problem. Sincerely, Gavin. The example e-mail: subject: Jive

    Hi all

    I m do not know who is testing this Apple, but any comment on his performance in your territory would be appreciated.

    Thank you

    John

    The second e-mail was received and everything seems OK. There is no characters.

    The view source now shows: Content-Transfer-Encoding: City-printable Content-Type: text/plain; charset = utf-8; format = flowed

    Content-Type: multipart/related;

    boundary="------------F73D86391D19EF781844DCB7"
    

    F73D86391D19EF781844DCB7

    Content-Transfer-Encoding: City-printable Content-Type: text/html; charset = utf-8

    So this is now correct as the "quoted-printable" now works.

    If your recipient called 'Claire' can also read all correctly then could mark you my previous comment (which deals with "mail.strictly_mime") as the ' solution '.

  • Several Tables with where there is no

    Hello
    Im trying to set up an insert statement and I would like to insert 3 record in the EMPLOYEE table. The three tables (USED, MEASURES, SALES) have constraints so it will check the tables on the fly to see whether the data exists already, if it does not then the insert. Is the place where there is no instruction wrighten as it should? Ive not been able to get this statement to work without error.

    (* ORA-00933: SQL not correctly completed command *)
    * 00933. 00000 - "not correctly completed SQL command * ')

    Any input will be appreciated, thanks!


    INSERT EMPLOYEES
    (
    EMPLOYEE_RATING,
    EMPLOYEE_VALUE,
    EMPLOYEE_REASON,
    )

    SELECT DISTINCT
    EMPLOYEE_RATING,
    EMPLOYEE_VALUE,
    EMPLOYEE_REASON
    MEASUREMENT, SALES
    WHERE THE MEASURES. EMPLOYEE_ID = SALES. EMPLOYEE_ID

    (WHERE there is no (select)
    MEASURE_RATING,
    MEASURE_VALUE,
    MEASURE_REASON
    the employee
    WHERE USED. EMPLOYEE_ID = SALES. SALES_ID);

    Try this Code is untested.

    INSERT INTO employee
    (
    employee_rating, employee_value, employee_reason
    )
    SELECT DISTINCT employee_rating, employee_value, employee_reason
    MEASURES, sales
    WHERE measures.employee_id = sales.employee_id
    AND NOT EXISTS (SELECT measure_rating, measure_value, measure_reason
    The EMPLOYEE
    WHERE employee.employee_id = sales.sales_id);

    Alen

  • This line where you can see your bookmarks and stuff are gone... ! How can I get that back?

    my laptop is 93.1% full so its quite slow work... I was on a website and I tried to click right (I needed to copy something) and the computer was slow, it didn't work. (already happened). so I tried a few times right click and before I new it this line where you can see your bookmarks (and other stuff) had disappeared. ! I tried right click again to see if I could get back, but it did not work. then I tried to turn off the computer and it still does not work. How can I get that back? and if I get it back, all my favorites will be gone?

    Versions of Firefox 3.6 + have a feature to allow the user to hide the Menu bar.

    Press the Alt key to temporarily show the Menu bar, then open view > toolbars and select menu bar, so it has a check mark.

    The F10 can also be used on most PCs to temporarily reveal the menu bar.

    https://support.Mozilla.com/en-us/KB/menu+bar+is+missing

  • How to change the default line width in Ultiboard?

    Hello

    I was recently working on my Board and somehow (for screen printing lines) default line width has been set to 0.00004 mils.

    How can I change this default width?

    Thank you

    Nick

    Hi Nick,

    You should be able to set the width of the default drawing for the layers of the toolbar settings to draw that is above the Board default workspace. Select the top layer of the screen and enter a value, it shouldn't forget for the subsequent designs.

    See you soon,.

    Jeff

  • How to insert the new line char in sticky c# code?

    Hi all

    I paste the code complete c# on a line of string as follows.

    int _intUserID = 0; string _strUserName = string. Empty; string _strEmployeeID = string.empty;
     
    c# VS2005 .cs file code should stick as follows.

    int _intUserID = 0;
    String _strUserName = string. Empty;
    String _strEmployeeID = string. Empty;

    So how do you achieve this. by inserting the new line char in c#?

    Hi Murthy,

    Thanks for posting your query in Microsoft Community.

    I understand that you have problems with the code in Visual studio.

    The question you posted corresponds to the coding software, it would be better suited to the MSDN Community.

    Please visit the link below to find a community that will provide the support you want.

    http://social.msdn.Microsoft.com/forums/en-us/category/VisualStudio

    Hope it will be useful. If you still have questions, please reply and we will be happy to help you.

Maybe you are looking for