Is it wrong to use SQL % ROWCOUNT = 0?

Hello

I have two tables, BILL and VALIDATIONS, have all two (LDAP_UID, TERM) as a composite key. I wrote a procedure to do the following:

1. I use this composite key to extract some the key fields from the table of BILL, form a new row and insert it into the table VALIATIONS;
2. prior to inserting into the table of VALIDATIONS, I use a SELECT statement to verify if the composite key already exists in the table of VALIDATION and not inserting at least that the composite key is not found.

The procedure is the following:
create or replace procedure save_transactions
   (i_ldap_uid IN varchar2, i_term IN varchar2)
AS
   v_validated_ldap_uid validations.ldap_uid%type;
   v_student_id validations.student_id%type;
   v_first_name validations.first_name%type;
   v_last_name validations.last_name%type;
   v_term validations.term%type;
BEGIN
   select ldap_uid
   into v_validated_ldap_uid
   from validations
   where ldap_uid = i_ldap_uid
   and term = i_term;

   if SQL%ROWCOUNT = 0 then
      select student_id, first_name, last_name
      into v_student_id, v_first_name, v_last_name
      from bill
      where ldap_uid = i_ldap_uid
      and term = i_term;
      insert into validations values (
      v_student_id, i_ldap_uid, v_first_name, v_last_name,
      i_term, sysdate, (to_char(sysdate, 'yymmdd'))||
      (select to_char(count(TRANSACTION_DATE)+1, 'fm0999') from VALIDATIONS where to_char(TRANSACTION_DATE) = to_char(sysdate))
      );
   end if;
END;
/
The procedure is created and updated clean, without any error. But the error occurs when using it. If the line is already in table VALIDATIONS, the {color: blue} if SQL % ROWCOUNT = 0 {color} is fine and the insertion code block is bypassed. However, if the line is not found in the table of VALIDATION, I got the following error:
SQL> execute save_transactions('john.brown', '200902')
BEGIN save_transactions('john.brown', '200902'); END;

*
ERROR at line 1:
ORA-01403: no data found
ORA-06512: at "ZBOV.SAVE_TRANSACTIONS", line 10
ORA-06512: at line 1
Well, for me, the whole use of SQL % ROWCOUNT is for testing. If he cannot test SQL ROWCOUNT = 0%, how else can test? However, I got the error and I must be wrong. But what is bad?

Thanks a lot for your help!


Newman

Hello

The "no data found" error is raised whenevde make you a select... IN the query and the query found no line.
You can always include SELECT it... IN his own statement BEGIN block, with its own «EXCEPTION WHEN NO_DATA_FOUND» Manager... ", but often, there are easier ways to work around the problem.

In this example, I can see two of these ways:

(1) Say

SELECT  COUNT (*)
INTO    num_found
FROM    transactions
WHERE   ldap_uid = i_ldap_uid
AND     term     = i_term;

   if num_found = 0 then
...

"SELECT COUNT...". "without a GROUP BY will always return exactly one line, if you do not have to worry about the error"no data found ".

(2) a better (but more difficult) solution: instead of making a "INSERT...". Statement of VALUES... ', using the results of the query on the Bill, make a

INSERT  ...
SELECT  ...
FROM    bill
WHERE   ...
AND     NOT EXISTS
        (
        SELECT  1
        FROM    validations
        WHERE   ldap_uid = i_ldap_uid
        AND     term     = i_term
        );

In fact, you have PL/SQL to do this (although there are good reasons to have a PL/SQL procedure that does nothing other than this INSERT statement).

Tags: Database

Similar Questions

  • SQL ROWCOUNT %

    When I use SQL % ROWCOUNT, it returns the account = 1 if there is no record of the PRODUCT in the condition table

    SELECT count (*) from the PRODUCT v_count WHERE LOC = v_oldloc;

    dbms_output.put_line (' documents found in the PRODUCT table for column LOC with the value ' | v_oldloc |': ' |) SQL % ROWCOUNT);

    COMMIT;

    But, when I use the v_count to display the number of records, it returns ZERO (correct) as below

    SELECT count (*) from the PRODUCT v_count WHERE LOC = v_oldloc;

    dbms_output.put_line (' documents found in the PRODUCT table for column LOC with the value ' | v_oldloc |': ' | v_count);

    COMMIT;

    Please let me know if there is a problem with the code?

    Thanks in advance

    Hello

    % ROWCOUNT SQL returns you the number of lines that returns the query "SELECT count (*) in v_count PRODUCT WHERE LOC = v_oldloc;

    In fact, the query returns a row with the value 0. This is why SQL ROWCOUNT % gives you 1 as output.

    Of course v_count is 0 because it is what is the result of the query.

    Both are expected results in your case.

    Cheerz,

    Stako

  • Incorrect SQL % RowCount value

    Hello.

    I created dblink of Oracle 11 g (11.2.0.4.3) for Sybase ASE database (15.5) using gateway of Oracle database for Sybase (11.2.0.4.3) on x 64 OEL (6.5).

    When I make changes to a remote table with triggers and use the variable in the WHERE clause, SQL % RowCount value is miscalculated.
    Found the antidote on the side of Sybase - the use of "set nocount on" within a trigger.
    Is there a solution on the side of Oracle (database or gateway)?

    Detailed description is given below:

    Description table and relaxing 1) (Sybase)
    create table test_TR)
    identity of whole ID,
    oper_id integer not null,
    counter integer not null,
    constraint XPKtest_TR primary key clustered (id))
    go
    insert into test_TR (oper_id, meter) values (1,10)
    insert into test_TR (oper_id, meter) values (2.21)
    insert into test_TR (oper_id, meter) values (2.36)
    go

    create trigger tUtest_TR on test_TR for UPDATE as
    Start
    declare @numrows int
    Select @numrows = @@rowcount
    return
    error:
    RAISERROR 31000 "UPDATE."
    ROLLBACK transaction statement
    end
    go

    (2) description gateway (gateway)
    HS_FDS_CONNECT_INFO=xxx.xxx.xxx.xxx.xxx:XXXX/test
    HS_FDS_RECOVERY_ACCOUNT = RECOVERY
    HS_FDS_RECOVERY_PWD = *.
    HS_FDS_TRANSACTION_MODEL = COMMIT_CONFIRM
    HS_FDS_TRANSACTION_LOG = HS_TRANSACTION_LOG
    HS_FDS_RESULTSET_SUPPORT = TRUE
    HS_FDS_PROC_IS_FUNC = FALSE

    (3) description Dblink (Oracle)
    CREATE DATABASE LINK PUBLIC 'SYB_TEST' CONNECT TO ' * ' IDENTIFIED by ' * ' using 'SYB_TEST ';

    (4) test query (Oracle)
    declare per_id digital;
    Start
    Update "test_TR"@SYB_TEST "counter" value = "counter" + 1 where 'oper_id' = 0;
    dbms_output.put_line ('0 rows =' |) SQL % number of lines);
    PER_ID: = 0;
    Update "test_TR"@SYB_TEST "counter" value = "counter" + 1 where 'oper_id' = per_id;
    dbms_output.put_line ('0 rows =' |) SQL % number of lines);
    Rollback;
    end;
    /

    0 rows = 0
    0 line = 1

    Thanks in advance for any information!

    filed Bug 19844303 - SQL % ROWCOUN RETURNS a VALUE INCORRECTE

  • Data capture, etc. using SQL Developer mysql Orac conversion problems

    Hello

    I have been using Sql Developer to try to convert my mysql database to oracle, I managed to set up the connections and the repository very well. However, when I right click on my database connection and click on the capture of the capture window appears but nothing happens. What I am doing wrong?

    Thank you


    Aaron

    This error usually indicates a corrupt repository of migration or a user privilege is missing.

    Also the migration of SQL Developer 2 and 1 repository is not compatible - so I would say to create a single repository user for each new version.
    It is a repository of sample for SQL Developer 2.x user:

    CREATE USER migration IDENTIFIED BY migration DEFAULT TABLESPACE users TEMPORARY TABLESPACE temp;

    GRANT CONNECT, RESOURCE, CREATE VIEW, CREATE A PUBLIC SYNONYM TO
    Migration WITH the ADMIN OPTION.

    GRANT ALTER ANY ROLE, ALTER ANY SEQUENCE, ALTER ANY TABLE, ALTER TABLESPACE, ALTER ANY TRIGGER, COMMENT ANY TABLE, CREATE ANY SEQUENCE, CREATE ANY TABLE, CREATE ANY TRIGGER, CREATE ROLE, CREATE TABLESPACE, CREATE USER, DROP ANY SEQUENCE, DROP ANY TABLE, DROP ANY TRIGGER, DROP TABLESPACE, DROP USER, DROP ANY ROLE, GRANT ANY ROLE, INSERT ANY TABLE, SELECT ANY TABLE UPDATE no matter WHAT TABLE OF migration;

  • SQLCODE and sql rowcount % in test conditions

    I'm translating a procedure of Ingres to oracle. I use the Oracle sql and sqlcode % rowcount
    variables instead of Ingres, iierrornumber and iirowcount.

    I replaced the names of ingres with the names of oracle and now wonder how how oracle uses these
    values.

    I use DBMS_OUTPUT. Put_line to display the content of rowcount % sqlcode and sql.

    What happens when I'm 'without selected lines. I have run the same query in the stand-alone command line
    and don't get any selected rows... "(and that's okay, because I do not have the corresponding data to)."

    But when I run it in the procedure, I don't get any value of sqlcode or sql % rowcount... the
    program just stops. The author used the ingres code to test if the data were there
    continue to do something else.

    If you get no rows returned, what it means, the sqlcode is 0? and the number of lines % sql is empty?
    That's why my DBMS_OUTPUT. Put_line does not display anything?

    my example...

    before this section in proceedings... after running another select statement that returns data...
    I use the DBMS to debug the values I spent...

    DBMS_OUTPUT. Put_line ('BEFORE sqlcode is' | sqlcode);
    DBMS_OUTPUT. Put_line ('until sqlrowcount is"| % rowcount sql);

    Select the table value
    WHERE condition = "Y"; > This selection will be made 'no return lines' and ignore the below DBMS_OUTPUTS - 2

    DBMS_OUTPUT. Put_line ('AFTER sqlcode is' | sqlcode);
    DBMS_OUTPUT. Put_line ("AFTER sqlrowcount is" | % rowcount sql);

    When I run the procedure... I get statements DBMS BEFORE and nothing after...
    BEFORE sqlcode is 0
    Sqlrowcount is 1 > > > > that's all that is displayed


    Given that I'm getting the 'no row returned. How oracle it round to the experience of someone?

    Thank you. I learn a lot from your comments and your information.

    Show us the full procedure please.

    I'm guessing that you have a generic WHEN catch of OTHER exception that swallows the NO_DATA_FOUND exception I expect to see (depending on what you posted).

  • CRM using SQL database in an environment of small business often inaccessible with the following error message

    Hello

    This is my first time on this forum so bear with my ignorance!  I'll expose the background of my setup and then explain the error.

    We have a small business with a server running SBS2011 and PC running Windows 8 and 8.1 connected to the server in a domain environment.

    We use a CRM product called Emu Tall that uses SQL Server 2008 R2 on the server for the database and the PC run a local application that connects to this database.

    On a daily basis, but completely randomly and sometimes several times a day, a user will try and open the application on a PC and get the following error message.

    Could not load file or assembly 'Microsoft.SqlServer.SqlEnum, Version = 10.0.0.0, Culture = neutral, PublicKeyToken = 89845dcd8080cc91' or one of its dependencies. The system cannot find the specified file.

    At first, I thought it must be a matter of waiting time as it seemed to happen every morning, but I've proved since that it occurs at any time of the day and is apparently unrelated to amount of users or idle time or something like that.

    Here's another oddity that hopefully sheds some light on it. If I go to the server and open the CRM application on the server, it works very well since it is only the PC that have the connection problem.  In addition, as soon as I connected to the server of any PC can connect immediately (until it happens again later in the day).  I don't need to stay connected to the server, connect one time and close the session and he "fixed" it for a few hours for all PC users.

    I contacted the CRM vendor, and they are completely confused and have no idea what to do.

    We are trolling along at the moment with me opening a session on the server for launch launch whenever a user receives the error message but it is far from satisfactory.

    A final observation is that it does not always.  It used to work fine.  The problem began just two months ago and seems to coincide with the increase in our user from 5 to 12 users license even if the CRM provider swear that it is nothing to do with the license.  They may agree; I don't know enough to argue the point.

    Any help will be appreciated! I'm sure it will be a simple solution and someone there will know why and the answer immediately but is elusive at this time.

    This issue is beyond the scope of this site and must be placed on Technet or MSDN

    http://social.technet.Microsoft.com/forums/en-us/home

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

  • How to find the primary key columns in the tables in MS Access using SQL queries

    How to find the primary key columns in the tables in MS Access using SQL queries

    Hello

    This is the forum for Windows Vista programs related issues.

    For better assistance, please try instead the Forums in SQL Server .

    Thank you! Vincenzo Di Russo - Microsoft MVP Windows Internet Explorer, Windows Desktop Experience & security - since 2003. ~ ~ ~ My MVP profile: https://mvp.support.microsoft.com/profile/Vincenzo

  • Copy of database SQL from SQL 2005 using SQL Server Management Studio 2008

    I made a backup of the database and tried to do a cover but I don't know where is the database restored too.

    I connected the old PC to SQL with the new using SQL 2008 Management Studio.

    Hello

    Your question is beyond the scope of this community.

    Please repost your question in the SQL Server TechNet Forums.

    https://social.technet.Microsoft.com/forums/SQLServer/en-us/home?category=SQLServer

    "The MSDN SQL Server Forums.

    https://social.msdn.Microsoft.com/forums/SQLServer/en-us/home?category=SQLServer

    TechNet forums:

    https://social.technet.Microsoft.com/forums/en-us/home

    MSDN forums:

    https://social.msdn.Microsoft.com/forums/en-us/home

    See you soon.

  • Error occurs when you use SQL Server 2012 assessment vs window detail of the object in window 7 - KERNELBASE.dll exception 0xe0434352

    Hello

    Error occurs when you use SQL Server 2012 assessment vs window detail of the object in window 7.  I use the window of the object but the detail of the objects window arrives and immediately SQL Server stops with the error below and then opens again.  I didn't find any help with this specific error is but suspect there is a problem between SLQ Server 2012 et.NET Framework 4.  Unfortunately, I do not know what it takes in this regard.

    Thanks, Deb

    Event ID: 1000
    Task category: (100)
    Level: error
    Keywords: Classic
    User: n/a
    Computer: Deb - HP
    Description:
    Name of the failing application: Ssms.exe, version: 2011.110.3000.0, time stamp: 0x5081c1cd
    Name of the failed module: KERNELBASE.dll, version: 6.1.7601.18015, time stamp: 0x50b83c8a
    Exception code: 0xe0434352
    Offset: 0x0000c41f
    ID of the process failed: 0x13a8
    Start time of application vulnerabilities: 0x01ce609a6d3db991
    The failing application path: C:\tempSQLWOW\110\Tools\Binn\ManagementStudio\Ssms.exe
    Path of the failing module: C:\Windows\syswow64\KERNELBASE.dll
    Report ID: 1fb1cbfb-cc8e-11e2-b436-abd2bebb3f17

    Hi Claude,.

    The question you posted would be better suited in the TechNet Forums. I would recommend posting your query in the link below.

    http://social.technet.Microsoft.com/forums/en-us/category/SQLServer

    Good day!

    Answer please if you face concerns.

  • XML data in the table using sql/plsql

    Hi experts,

    Could you please help with the following requirement. I have the tags xml (.xml on a server file) below. I need to access this file and read the XML and insert into the db table using sql and plsql. Is it possible with the cdata below? And there is a nested this table.

    Could someone please guide me if you have a sample code file and xml.

    <? XML version = "1.0" encoding = "UTF-8"? >

    < generation_date > <! [CDATA [17/11/2015]] > < / generation_date >

    < generated_by > <! [CDATA [Admin Admin]] > < / generated_by >

    < year > <! [CDATA [2015]] > < / year >

    < month > <! [CDATA [01]] > < / month >

    < author >

    < author > <! [CDATA [user author]] > < / author > < author_initial > <! [CDATA [user]] > < / author_firstname > < author_country > <! [CDATA [author]] > < / author_lastname >

    < author_email > <! [CDATA [[email protected]]] > < / author_email >

    < author_data_01 > <! [CDATA []] > < / author_data_01 >

    < author_data_02 > <! [CDATA []] > < / author_data_02 >

    < items >

    < article_item >

    < article_id > <! [CDATA [123456]] > < / article_id >

    < publication > <! [CDATA [Al Bayan]] > < / publication >

    < section > <! [CDATA [Local]] > < / section >

    < issue_date > <! [CDATA [11/11/2015]] > < / issue_date >

    < page > <! [CDATA [2]] > < / print this page >

    < article_title > <! [CDATA [title.]] > < / article_title > < number_of_words > <! [CDATA [165]] > < / number_of_words >

    < original_price > <! [CDATA [200]] > < / original_price >

    < original_price_currency > <! [CDATA [DEA]] > < / original_price_currency >

    < price > <! [CDATA [250]] > < / price >

    < price_currency > <! [CDATA [DEA]] > < / price_currency >

    < / article_item >

    < / articles >

    < total_amount > <! [CDATA [250]] > < / total_amount >

    < total_amount_currency > <! [CDATA [DEA]] > < / total_amount_currency >

    < / author >

    < / xml >

    Thanks in advance,

    Suman

    XMLTABLE using...

    SQL > ed
    A written file afiedt.buf

    1 with t (xml) as (select xmltype ('))
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    [[12 [email protected]]] >
    13
    14
    15
    16
    17
    18
    19


    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33 ") of the double)"
    34-

    35 end of sample data
    36-
    37 - assumptions:
    (38 - a) XML may have several tags
    (39 - b) each may contain more
    40-
    41 select x.gen_by, x.gen_date, x.mn, x.yr
    42, y.author, y.auth_fn, y.auth_ln, y.auth_cnt, y.auth_em, y.auth_d1, y.auth_d2

    43, z.id, z.pub, z.sec, z.iss_dt, z.pg, z.art_ttl, z.num_wrds, z.oprice, z.ocurr, z.price, z.curr
    44 t
    45, xmltable ('/ authxml')
    from $ 46 t.xml
    path of 47 columns gen_date varchar2 (10) '. / generation_date'
    48, path of varchar2 (15) of gen_by '. / generated_by'
    49, path of varchar2 (4) year '. "/ year"
    50 varchar2 (2) mn road '. "/ month"
    51, path of xmltype authors '.'
    52                 ) x
    53, xmltable ('/ authxml/authors ')
    from $ 54 x.authors
    author of 55 path of varchar2 columns (15) '. / author'
    56, path of varchar2 (10) of auth_fn '. / author_firstname'
    57, path of varchar2 (10) of auth_ln '. / author_lastname'
    58 road of VARCHAR2 (3) auth_cnt '. / author_country'
    59 road of varchar2 (20) of auth_em '. / author_email'
    60 road of varchar2 (5) of auth_d1 '. / author_data_01'
    61, path of varchar2 (5) of auth_d2 '. / author_data_02'
    62, path of xmltype articles '. / Articles'
    63                 ) y
    64, xmltable ('/ Articles/article_item ')
    from $ 65 y.articles
    path id 66 number columns '. / article_id'
    67, path of varchar2 (10) pub '. ' / publication.
    68 road of varchar2 (10) dry '. / section'
    69, path of varchar2 (10) of iss_dt '. / issue_date'
    70 road of VARCHAR2 (3) pg '. "/ print this page"
    71, path of varchar2 (20) of art_ttl '. / article_title'
    72, path of varchar2 (5) of num_wrds '. / number_of_words'
    73, path of varchar2 (5) of oprice '. / original_price'
    74 road to VARCHAR2 (3) ocurr '. / original_price_currency'
    75, path of varchar2 (5) price '. "/ price"
    76, path of VARCHAR2 (3) curr '. / price_currency'
    77*                ) z
    SQL > /.

    GEN_DATE GEN_BY YEAR MN AUTHOR AUTH_FN AUTH_LN AUT AUTH_EM AUTH_ AUTH_ ID PUB DRY ISS_DT PG ART_TTL NUM_W OPRIC HEARTS PRICE OCU
    ---------- --------------- ---- -- --------------- ---------- ---------- --- -------------------- ----- ----- ---------- ---------- ---------- ---------- --- -------------------- ----- ----- --- ----- ---
    17/11/2015 Admin Admin 2015 01 user author user author [email protected] 123456 UAE Al Bayan Local 11/11/2015 2 is the title.   165 200 AED AED 250

    Of course, you'll want to change the types of data, etc. as needed.

    I assumed that the XML can contain several "" sections and that each section can contain several entries.

    Thus the XMLTABLE aliasing as 'x' gives information of XML, and supplies the data associated with the XMLTABLE with alias 'y' which gets the multiple authors, which itself section of the XMLTABLE with alias 'z' for each of the article_item.

    CDATA stuff are handled automatically by SQLX (XML functionality integrated into Oracle's SQL)

  • % SQL rowcount returns 1, but he should return 2

    Oracle 10g

    Hi gurus

    I was reading one of the PL/SQL challenge site https://plsqlchallenge.oracle.com/pls/apex/f?p=10000:23:114157934581224:NOquestion: but can't get the exact idea.

    I appreciate if someone helps me to understand the code.

    Examples of data

    Set serveroutput on
    /
    drop table plch_stuff;
    /

    CREATE TABLE plch_stuff)
    ID INTEGER PRIMARY KEY,
    NM SINGLE VARCHAR2 (5))
    /

    create or replace procedure (plch_insert)
    insert_row_in IN BOOLEAN DEFAULT true)
    IS
    Start
    IF insert_row_in
    THEN
    INSERT INTO plch_stuff VALUES (1, 'Hat');
    END IF;
    END;
    /
    Start
    plch_insert;
    UPDATE plch_stuff SET nm = 'Hat ';
    dbms_output.put_line (' last count ='|) SQL % ROWCOUNT);
    END;

    Result

    Last Count = 1

    But according to my understanding, result = last count = 2 because a sql % rowcount for insert and then one to update. Please guide. Thank you

    Concerning

    Matt

    But according to my understanding, result = last count = 2 because a sql % rowcount for insert and then one to update. Please guide. Thank you

    Where did you got your "understanding"?

    When you have questions about the basic features Oracle, you must ALWAYS first check the documentation.

    A search on the web for "oracle 11g sql % rowcount" returns this as the first link

    http://docs.Oracle.com/CD/B28359_01/AppDev.111/b28370/sql_cursor.htm

    % NUMBER OF LINES

    Returns the number of rows affected by a INSERT , UPDATE , or DELETE or returned by a statement SELECT INTO statement.

    The County refers to one, AND only ONE, statement - the last statement executed.

  • Import Export using SQL Developer

    People

    I have 6 tables whose data must be exported from a database and imported into the other. The structure of the table constraints etc. is the same across both of the DB.

    Database is 11g. Average amount of data in tables 5 is 2.5million contain lines and 1 340million.

    Could you please suggest the best possible way to the export and import of data using SQL Developer. Developer SQL version 3.2.20.09

    There is an option in the 'View' tab in Developer SQL by using 'DBA' but do not have s/n of these patterns. I am well aware expdp and impdp operations but it is managed by another team that can cause delays both want to do it myself.

    Can we do expdp and impdp on SQL Developer without access s/n?

    All of the suggestions.

    Thank you

    Simple method would be to create external table Using the ORACLE_DATAPUMP Access Driver. Its neat and fast.

    http://docs.Oracle.com/CD/B28359_01/server.111/b28319/et_dp_driver.htm#i1007502

  • Question to load data using sql loader in staging table, and then in the main tables!

    Hello

    I'm trying to load data into our main database table using SQL LOADER. data will be provided in separate pipes csv files.

    I have develop a shell script to load the data and it works fine except one thing.

    Here are the details of a data to re-create the problem.

    Staging of the structure of the table in which data will be filled using sql loader

    create table stg_cmts_data (cmts_token varchar2 (30), CMTS_IP varchar2 (20));

    create table stg_link_data (dhcp_token varchar2 (30), cmts_to_add varchar2 (200));

    create table stg_dhcp_data (dhcp_token varchar2 (30), DHCP_IP varchar2 (20));

    DATA in the csv file-

    for stg_cmts_data-

    cmts_map_03092015_1.csv

    WNLB-CMTS-01-1. 10.15.0.1

    WNLB-CMTS-02-2 | 10.15.16.1

    WNLB-CMTS-03-3. 10.15.48.1

    WNLB-CMTS-04-4. 10.15.80.1

    WNLB-CMTS-05-5. 10.15.96.1

    for stg_dhcp_data-

    dhcp_map_03092015_1.csv

    DHCP-1-1-1. 10.25.23.10, 25.26.14.01

    DHCP-1-1-2. 56.25.111.25, 100.25.2.01

    DHCP-1-1-3. 25.255.3.01, 89.20.147.258

    DHCP-1-1-4. 10.25.26.36, 200.32.58.69

    DHCP-1-1-5 | 80.25.47.369, 60.258.14.10

    for stg_link_data

    cmts_dhcp_link_map_0309151623_1.csv

    DHCP-1-1-1. WNLB-CMTS-01-1,WNLB-CMTS-02-2

    DHCP-1-1-2. WNLB-CMTS-03-3,WNLB-CMTS-04-4,WNLB-CMTS-05-5

    DHCP-1-1-3. WNLB-CMTS-01-1

    DHCP-1-1-4. WNLB-CMTS-05-8,WNLB-CMTS-05-6,WNLB-CMTS-05-0,WNLB-CMTS-03-3

    DHCP-1-1-5 | WNLB-CMTS-02-2,WNLB-CMTS-04-4,WNLB-CMTS-05-7

    WNLB-DHCP-1-13 | WNLB-CMTS-02-2

    Now, after loading these data in the staging of table I have to fill the main database table

    create table subntwk (subntwk_nm varchar2 (20), subntwk_ip varchar2 (30));

    create table link (link_nm varchar2 (50));

    SQL scripts that I created to load data is like.

    coil load_cmts.log

    Set serveroutput on

    DECLARE

    CURSOR c_stg_cmts IS SELECT *.

    OF stg_cmts_data;

    TYPE t_stg_cmts IS TABLE OF stg_cmts_data % ROWTYPE INDEX BY pls_integer;

    l_stg_cmts t_stg_cmts;

    l_cmts_cnt NUMBER;

    l_cnt NUMBER;

    NUMBER of l_cnt_1;

    BEGIN

    OPEN c_stg_cmts.

    Get the c_stg_cmts COLLECT in BULK IN l_stg_cmts;

    BECAUSE me IN l_stg_cmts. FIRST... l_stg_cmts. LAST

    LOOP

    SELECT COUNT (1)

    IN l_cmts_cnt

    OF subntwk

    WHERE subntwk_nm = l_stg_cmts (i) .cmts_token;

    IF l_cmts_cnt < 1 THEN

    INSERT

    IN SUBNTWK

    (

    subntwk_nm

    )

    VALUES

    (

    l_stg_cmts (i) .cmts_token

    );

    DBMS_OUTPUT. Put_line ("token has been added: ' |") l_stg_cmts (i) .cmts_token);

    ON THE OTHER

    DBMS_OUTPUT. Put_line ("token is already present'");

    END IF;

    WHEN l_stg_cmts EXIT. COUNT = 0;

    END LOOP;

    commit;

    EXCEPTION

    WHILE OTHERS THEN

    Dbms_output.put_line ('ERROR' |) SQLERRM);

    END;

    /

    output

    for dhcp


    coil load_dhcp.log

    Set serveroutput on

    DECLARE

    CURSOR c_stg_dhcp IS SELECT *.

    OF stg_dhcp_data;

    TYPE t_stg_dhcp IS TABLE OF stg_dhcp_data % ROWTYPE INDEX BY pls_integer;

    l_stg_dhcp t_stg_dhcp;

    l_dhcp_cnt NUMBER;

    l_cnt NUMBER;

    NUMBER of l_cnt_1;

    BEGIN

    OPEN c_stg_dhcp.

    Get the c_stg_dhcp COLLECT in BULK IN l_stg_dhcp;

    BECAUSE me IN l_stg_dhcp. FIRST... l_stg_dhcp. LAST

    LOOP

    SELECT COUNT (1)

    IN l_dhcp_cnt

    OF subntwk

    WHERE subntwk_nm = l_stg_dhcp (i) .dhcp_token;

    IF l_dhcp_cnt < 1 THEN

    INSERT

    IN SUBNTWK

    (

    subntwk_nm

    )

    VALUES

    (

    l_stg_dhcp (i) .dhcp_token

    );

    DBMS_OUTPUT. Put_line ("token has been added: ' |") l_stg_dhcp (i) .dhcp_token);

    ON THE OTHER

    DBMS_OUTPUT. Put_line ("token is already present'");

    END IF;

    WHEN l_stg_dhcp EXIT. COUNT = 0;

    END LOOP;

    commit;

    EXCEPTION

    WHILE OTHERS THEN

    Dbms_output.put_line ('ERROR' |) SQLERRM);

    END;

    /

    output

    for link -.

    coil load_link.log

    Set serveroutput on

    DECLARE

    l_cmts_1 VARCHAR2 (4000 CHAR);

    l_cmts_add VARCHAR2 (200 CHAR);

    l_dhcp_cnt NUMBER;

    l_cmts_cnt NUMBER;

    l_link_cnt NUMBER;

    l_add_link_nm VARCHAR2 (200 CHAR);

    BEGIN

    FOR (IN) r

    SELECT dhcp_token, cmts_to_add | ',' cmts_add

    OF stg_link_data

    )

    LOOP

    l_cmts_1: = r.cmts_add;

    l_cmts_add: = TRIM (SUBSTR (l_cmts_1, 1, INSTR (l_cmts_1, ',') - 1));

    SELECT COUNT (1)

    IN l_dhcp_cnt

    OF subntwk

    WHERE subntwk_nm = r.dhcp_token;

    IF l_dhcp_cnt = 0 THEN

    DBMS_OUTPUT. Put_line ("device not found: ' |") r.dhcp_token);

    ON THE OTHER

    While l_cmts_add IS NOT NULL

    LOOP

    l_add_link_nm: = r.dhcp_token |' _TO_' | l_cmts_add;

    SELECT COUNT (1)

    IN l_cmts_cnt

    OF subntwk

    WHERE subntwk_nm = TRIM (l_cmts_add);

    SELECT COUNT (1)

    IN l_link_cnt

    LINK

    WHERE link_nm = l_add_link_nm;

    IF l_cmts_cnt > 0 AND l_link_cnt = 0 THEN

    INSERT INTO link (link_nm)

    VALUES (l_add_link_nm);

    DBMS_OUTPUT. Put_line (l_add_link_nm |) » '||' Has been added. ") ;

    ELSIF l_link_cnt > 0 THEN

    DBMS_OUTPUT. Put_line (' link is already present: ' | l_add_link_nm);

    ELSIF l_cmts_cnt = 0 then

    DBMS_OUTPUT. Put_line (' no. CMTS FOUND for device to create the link: ' | l_cmts_add);

    END IF;

    l_cmts_1: = TRIM (SUBSTR (l_cmts_1, INSTR (l_cmts_1, ',') + 1));

    l_cmts_add: = TRIM (SUBSTR (l_cmts_1, 1, INSTR (l_cmts_1, ',') - 1));

    END LOOP;

    END IF;

    END LOOP;

    COMMIT;

    EXCEPTION

    WHILE OTHERS THEN

    Dbms_output.put_line ('ERROR' |) SQLERRM);

    END;

    /

    output

    control files -

    DOWNLOAD THE DATA

    INFILE 'cmts_data.csv '.

    ADD

    IN THE STG_CMTS_DATA TABLE

    When (cmts_token! = ") AND (cmts_token! = 'NULL') AND (cmts_token! = 'null')

    and (cmts_ip! = ") AND (cmts_ip! = 'NULL') AND (cmts_ip! = 'null')

    FIELDS TERMINATED BY ' |' SURROUNDED OF POSSIBLY "" "

    TRAILING NULLCOLS

    ('RTRIM (LTRIM (:cmts_token))' cmts_token,

    cmts_ip ' RTRIM (LTRIM(:cmts_ip)) ")". "

    for dhcp.


    DOWNLOAD THE DATA

    INFILE 'dhcp_data.csv '.

    ADD

    IN THE STG_DHCP_DATA TABLE

    When (dhcp_token! = ") AND (dhcp_token! = 'NULL') AND (dhcp_token! = 'null')

    and (dhcp_ip! = ") AND (dhcp_ip! = 'NULL') AND (dhcp_ip! = 'null')

    FIELDS TERMINATED BY ' |' SURROUNDED OF POSSIBLY "" "

    TRAILING NULLCOLS

    ('RTRIM (LTRIM (:dhcp_token))' dhcp_token,

    dhcp_ip ' RTRIM (LTRIM(:dhcp_ip)) ")". "

    for link -.

    DOWNLOAD THE DATA

    INFILE 'link_data.csv '.

    ADD

    IN THE STG_LINK_DATA TABLE

    When (dhcp_token! = ") AND (dhcp_token! = 'NULL') AND (dhcp_token! = 'null')

    and (cmts_to_add! = ") AND (cmts_to_add! = 'NULL') AND (cmts_to_add! = 'null')

    FIELDS TERMINATED BY ' |' SURROUNDED OF POSSIBLY "" "

    TRAILING NULLCOLS

    ('RTRIM (LTRIM (:dhcp_token))' dhcp_token,

    cmts_to_add TANK (4000) RTRIM (LTRIM(:cmts_to_add)) ")" ""

    SHELL SCRIPT-

    If [!-d / log]

    then

    Mkdir log

    FI

    If [!-d / finished]

    then

    mkdir makes

    FI

    If [!-d / bad]

    then

    bad mkdir

    FI

    nohup time sqlldr username/password@SID CONTROL = load_cmts_data.ctl LOG = log/ldr_cmts_data.log = log/ldr_cmts_data.bad DISCARD log/ldr_cmts_data.reject ERRORS = BAD = 100000 LIVE = TRUE PARALLEL = TRUE &

    nohup time username/password@SID @load_cmts.sql

    nohup time sqlldr username/password@SID CONTROL = load_dhcp_data.ctl LOG = log/ldr_dhcp_data.log = log/ldr_dhcp_data.bad DISCARD log/ldr_dhcp_data.reject ERRORS = BAD = 100000 LIVE = TRUE PARALLEL = TRUE &

    time nohup sqlplus username/password@SID @load_dhcp.sql

    nohup time sqlldr username/password@SID CONTROL = load_link_data.ctl LOG = log/ldr_link_data.log = log/ldr_link_data.bad DISCARD log/ldr_link_data.reject ERRORS = BAD = 100000 LIVE = TRUE PARALLEL = TRUE &

    time nohup sqlplus username/password@SID @load_link.sql

    MV *.log. / log

    If the problem I encounter is here for loading data in the link table that I check if DHCP is present in the subntwk table, then continue to another mistake of the newspaper. If CMTS then left create link to another error in the newspaper.

    Now that we can here multiple CMTS are associated with unique DHCP.

    So here in the table links to create the link, but for the last iteration of the loop, where I get separated by commas separate CMTS table stg_link_data it gives me log as not found CMTS.

    for example

    DHCP-1-1-1. WNLB-CMTS-01-1,WNLB-CMTS-02-2

    Here, I guess to link the dhcp-1-1-1 with balancing-CMTS-01-1 and wnlb-CMTS-02-2

    Theses all the data present in the subntwk table, but still it gives me journal wnlb-CMTS-02-2 could not be FOUND, but we have already loaded into the subntwk table.

    same thing is happening with all the CMTS table stg_link_data who are in the last (I think here you got what I'm trying to explain).

    But when I run the SQL scripts in the SQL Developer separately then it inserts all valid links in the table of links.

    Here, she should create 9 lines in the table of links, whereas now he creates only 5 rows.

    I use COMMIT in my script also but it only does not help me.

    Run these scripts in your machine let me know if you also get the same behavior I get.

    and please give me a solution I tried many thing from yesterday, but it's always the same.

    It is the table of link log

    link is already present: dhcp-1-1-1_TO_wnlb-cmts-01-1

    NOT FOUND CMTS for device to create the link: wnlb-CMTS-02-2

    link is already present: dhcp-1-1-2_TO_wnlb-cmts-03-3
    link is already present: dhcp-1-1-2_TO_wnlb-cmts-04-4

    NOT FOUND CMTS for device to create the link: wnlb-CMTS-05-5

    NOT FOUND CMTS for device to create the link: wnlb-CMTS-01-1

    NOT FOUND CMTS for device to create the link: wnlb-CMTS-05-8
    NOT FOUND CMTS for device to create the link: wnlb-CMTS-05-6
    NOT FOUND CMTS for device to create the link: wnlb-CMTS-05-0

    NOT FOUND CMTS for device to create the link: wnlb-CMTS-03-3

    link is already present: dhcp-1-1-5_TO_wnlb-cmts-02-2
    link is already present: dhcp-1-1-5_TO_wnlb-cmts-04-4

    NOT FOUND CMTS for device to create the link: wnlb-CMTS-05-7

    Device not found: wnlb-dhcp-1-13

    IF NEED MORE INFORMATION PLEASE LET ME KNOW

    Thank you

    I felt later in the night that during the loading in the staging table using UNIX machine he created the new line for each line. That is why the last CMTS is not found, for this I use the UNIX 2 BACK conversion and it starts to work perfectly.

    It was the dos2unix error!

    Thank you all for your interest and I may learn new things, as I have almost 10 months of experience in (PLSQL, SQL)

  • Building xml in oracle without unnecessary tags using sql

    I wanted to build XML in oracle using sql, I found a way to construction using sql functions after a little research, I am completely unaware of any XML. My query is


    SELECT XMLELEMENT("orderwave",
      XMLAGG
    (XMLELEMENT("order_header",
      
    -- XMLATTRIBUTES(t2.l_name AS "order_number"),
      XMLFOREST
    (
      nvl
    (t2.l_name,' ') as "order_number",
      
    (
      SELECT XMLAGG
    (XMLELEMENT("order_line",
      XMLFOREST
    ( nvl(t1.l_name,' ') AS "label_type",
      nvl
    (t1.l_num,0) AS "lpn",
      nvl
    (t1.l_num,0) AS "sku"
      
    )
      
    )
      
    ) 
      FROM test_table t1
      WHERE UPPER
    (t1.record_type)='D'  
      
    ) AS sap
      
    )
      
    )
      
    )
      
    ) AS HEADER
      FROM test_table t2
      WHERE UPPER
    (t2.record_type) ='H';


    My problem is for using xmlforest, I had to use alias name 'sap' in my query to work and to get xml output. If i am using that, I am getting an unwanted tag 'SAP' around my data which I have to later cut it, which is unacceptable. Is there a way I can get rid of this extra 'SAP' tag without having to cut. The output data is


    <orderwave>
      
    <order_header>
      
    <order_number>order1</order_number>
      
    <SAP>
      
    <order_line>
      
    <label_type>test1</label_type>
      
    <lpn>1</lpn>
      
    <sku>1</sku>
      
    </order_line>
      
    <order_line>
      
    <label_type>test2</label_type>
      
    <lpn>2</lpn>
      
    <sku>2</sku>
      
    </order_line>
      
    <order_line>
      
    <label_type />
      
    <lpn>0</lpn>
      
    <sku>0</sku>
      
    </order_line>
      
    </SAP>
      
    </order_header>
      
    <order_header>
      
    <order_number>order2</order_number>
      
    <SAP>
      
    <order_line>
      
    <label_type>test1</label_type>
      
    <lpn>1</lpn>
      
    <sku>1</sku>
      
    </order_line>
      
    <order_line>
      
    <label_type>test2</label_type>
      
    <lpn>2</lpn>
      
    <sku>2</sku>
      
    </order_line>
      
    <order_line>
      
    <label_type />
      
    <lpn>0</lpn>
      
    <sku>0</sku>
      
    </order_line>
      
    </SAP>
      
    </order_header>
    </orderwave>


      Any help is really appreciated and thanks in advance.

    -- sample data
    with test_table
    as
    (
        select 'H' record_type, 'order1' l_name, 0 l_num from dual
        union all
        select 'H' record_type, 'order2' l_name, 0 l_num from dual
        union all
        select 'D' record_type, 'test1'  l_name, 1 l_num from dual
        union all
        select 'D' record_type, 'test2'  l_name, 2 l_num from dual
    )
    -- end of sample data
    select xmlelement
           (
              "order_wave"
            , xmlagg
              (
                xmlelement
                (
                    "order_header"
                  , xmlelement("order_number", t1.l_name)
                  , xmlagg
                    (
                      xmlelement
                      (
                         "order_line"
                       , xmlelement("label_type", t2.l_name)
                       , xmlelement("lpn", t2.l_num)
                       , xmlelement("sku", t2.l_num)
                      )
                    )
                )
              )
           ) xml_data
      from test_table t1
     cross
      join test_table t2
     where t1.record_type = 'H'
       and t2.record_type = 'D'
     group
        by t1.l_name;
    
    -- output
    /*
    
            
                    order1
                    
                            test1
                            1
                            1
                    
                    
                            test2
                            2
                            2
                    
            
            
                    order2
                    
                            test1
                            1
                            1
                    
                    
                            test2
                            2
                            2
                    
            
    
    */
    
  • How to get the full DDL using SQL developer

    Hi all

    I need get the full DDL a table with the details of the index partitions, synonyms, comments (if any) and give information if given any role, use SQL developer. We can achieve the same thing using shortcut F4 on name of the table into a frog, then selecting tab DDL. Is it possible to get the same in SQL Developer also?


    Also how I see existing procedures using SQL developer?  A toad, we were able to achieve using the schema browser.

    Hi all

    I reached by - right click on connection - diagram open... and any browser will even...

Maybe you are looking for

  • Excel 2010 question Satellite L300-29 t and F11

    Anyone can help with this problem? Using Excel 2010, by pressing f11 is supposed to make a graph on a new sheet, but no graphic is displayed. The shortcut alt f1 works but the picture is on the same sheet as it should. He has been installed from the

  • Replacing the HARD drive on the satellite A110-252

    I'm looking for a replacement of the hard drive for my laptop and I don't know which are compatible. I understand that I need a 2.5 "internal HDD, size 7 cm x 10 cm x 9.5 mm However the confusion for me is above the interface, I think I understand it

  • Mouse event down in a table

    Hello If I use the event 'Array' the mouse down, is possible to know which element in the table was clicked? Thank you.

  • Stop errors: 0x0a (0x0000001b, 0x0b74f845, 0x8e505c85, 0x00000001) for restoring Acer to factory default.

    Original title: Acer factory default restore I Stop 0x0a (0x0000001b, 0x0b74f845, 0x8e505c85, 0x00000001) I'm trying to restore an Acer Aspire 5330 to back to factory default. I do it by pressing alt f10. During the installation, I get the stop error

  • Need me another license for my rebuilt rig?

    I plan to upgrade my OS hosted WinXP 32 bit PT Win 7 Pro 64 bit. I need more RAM and although my mobo allows me up to 8 GB, my OS (Windows XP 32-bit) limit myself to 3 concerts. Upgrade to Win7 Pro 64 bit will allow me to use up to 8 GB of RAM. Later