Corsor using db_link

Is it possible to do it like this ?? To make select for cursor via database link ?
select * from user.table@db_link_name; Have anybody try sth like this ?
I work on Oracle 9.2.0.6
--procedure code
create procedure mm (db_link_name IN VARCHAR2) IS
CURSOR my_rows IS
select * from user.table@db_link_name;
v_i_n VARCHAR2(10);
v_s_n VARCHAR2(20);
v_a VARCHAR2(20);
v_a_d date;
v_ddl VARCHAR2(255);
BEGIN
OPEN my_rows;
LOOP
FETCH my_rows INTO v_s_n, v_i_n, v_a_d, v_a;
EXIT WHEN my_rows%NOTFOUND;
v_ddl := 'insert into m_table values('''||v_s_n || ''',''' || v_i_n || ''','''||v_a_d||''','''||v_a||''');';
DBMS_OUTPUT.PUT_LINE(v_ddl);
--EXECUTE IMMEDIATE v_ddl;
END LOOP;
CLOSE my_rows;
END;
/

the thing is, that when some rows are duplicated no other rows fromm all "insert into table select * from ..." are inserted..
The only solution for me is to create simple "insert into.. " statements for all which was selected form table@db_link...
any ideas ??
now I try like this but have ERROR ORA-03001: unimplemented feature
select db_link from dba_db_links where username='username';
type array is table of m_table%rowtype index by binary_integer;
temp_m_table array;
BEGIN
DBMS_OUTPUT.ENABLE;
FOR i IN master_cursor
LOOP
begin
v_db_link := i.db_link;
v_ddl := 'select * bulk collect into temp_m_table from other_user.table_like_m_table@'||i.db_link;
EXECUTE IMMEDIATE v_ddl;
forall k in 1 .. temp_m_table.count
insert into m_table values temp_m_table(k);
commit;
exception
...

Similar Messages

  • Accessing Large object Using DB_LINK

    Hi,
    Can we access large objects like CLOB and BLOB using db_link in oracle 10g? I know that it is not possible in oracle 9i and lower version.

    user10768613 wrote:
    Hi,
    Can we access large objects like CLOB and BLOB using db_link in oracle 10g? I know that it is not possible in oracle 9i and lower version.In short No, you still can't.

  • OCCI use db_link for connection?

    Will OCCI use db_link for the connection?

    Hi,
    I'm not sure I understand the question as a database link is not specified as part of a connection, rather, it is specified in the sql to execute.
    For example:
    string sql = "select some_value from some_table@db_link_name order by some_value";In any case, the above sql can be executed by an OCCI application if that is what you mean.
    Regards,
    Mark

  • Insert row using db_link

    Hi All,
    I am trying to insert data from one DB to another DB via db_link between them.
    insert into table@xyz
    select
    col 1, col2 , ... coln from table wher id = 123;
    the error is : ORA-02019: connection description for remote database not found
    But i am sure the connection description is good and healthy working fine.
    I checked it by
    select count(*) from table@xyz;
    And this resulted the # of rows.
    Before this the error message was to set global name to true and then i changed the db_link name to global name..
    I am using 10.2.0.5
    Need help to fix this !!
    Thanks,
    AAG

    Hi,
    Just Check the TNSNAMES.ORA file that you have added the connection description for the remote database.
    1.The TNSNAMES.ORA file will be in ORACLe_HOME\ora81\network\ADMIN.
    2. Then try creating the link for the same..
    Login as SYSDBA..
    create database link "Link_name" connect to "REMOTE_USER_NAME"identified by "remote-db-pwd" using 'DBNAME';
    Then, Just Check from you database the link is working by select statement to remote db..
    select * from remote_user_name.table_name@link_name;
    Once if you get, the link is fine and correct..
    So,you can proceed with your Insert statement as
    insert into your_table select * from remote_user_name.table_name@link_name;
    Information:
    There is a need to Perform a commit, if you perform even a select query from the remote database.
    Edited by: Shankar Viji on May 10, 2012 2:52 AM

  • Cannot connect a Oracle 9i DB to 7.3.4 DB ora 1002, 2063 using DB_LINK

    Hi, I created a public db_link in an Oracle 9i 9.2.0.1.0 DB on Red hat Linux, to an Oracle DB 7.3.4 on Unixware 2.1.3.When i try to use it, I'm getting the following errors:
    SQL> create public database link finanzas.world connect to guest identified by huesped using 'FINANZAS'
    Database link created.
    select a,b from [email protected]
    ERROR:
    ORA-01002: fetch out of sequence
    ORA-02063: preceding line from FINANZAS.WORLD
    These are the contents of TNSNAMES.ORA AND SQLNET.ORA
    TNSNAMES.ORA:
    FINANZAS.LOCALDOMAIN =
    (DESCRIPTION =
    (ADDRESS_LIST =
    (ADDRESS = (PROTOCOL = TCP)(HOST = Finanzas)(PORT = 1521))
    (CONNECT_DATA =
    (SERVER = DEDICATED)
    (SID = ART)
    SQLNET.ORA
    NAMES.DEFAULT_DOMAIN = localdomain
    NAMES.DIRECTORY_PATH= (TNSNAMES, ONAMES, HOSTNAME)
    Another weird thing:
    If i omit the ".world" part when creating the db_link, it gets created this way:
    SQL> select db_link from dba_db_links;
    DB_LINK
    FINANZAS.US.ORACLE.COM
    I modified spfile and querying v$_spparameter_file gets the following output:
    SQL> select name,value from v$spparameter where name like '%doma%';
    NAME
    VALUE
    db_domain
    WORLD
    Db_domain is supposed to be appended to db_link name isn't it?.
    Can anyone explain ...?. What i am doing wrong ...?
    HELP ...!
    PD: I created a db_link in 734 DB to connect to Oracle 9i and it works ....

    Database links between 9.2 and 7.3.4 databases are not supported. In general, a 9.2 client connecting to a 7.3.4 database is not supported. I believe you can solve the problem by downgrading the 9.2 database to 9.0 or by upgrading the 7.3.4 database to 8.1.7 (or 9.2).
    Unfortunately, 7.3.4 has not been supported since late '99 if memory serves, so you're going to start running into these compatibility problems.
    Justin

  • Move tables data from One DB to another using DB-Link ?

    Dear friends ,
    I want to move a table data (for a particular schema) from one database to another database's table (for a particular schema) . Can I do it using DB_Link ?
    If yes , then plz tell me the way , how can I do it ?

    >
    I want to move a table data (for a particular schema) from one database to another database's table (for a particular schema) . Can I do it using DB_Link ?>
    Yes you can use db link.Refer to the example in the link:-
    [http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/statements_5005.htm#sthref6315]
    Anand

  • Moving audit Records from one database to another database using dblink

    i got five database, i have to move sys.aud$ records from five databases to one centralized database into another schema every day at 10:00 clock, i have to use a dblink for this, i have to create same table as sys.aud$ with different schema in centralized database with one extra column db_unique_name,by using db_link how i need to move records from all the five databases to one centralized database, can anyone help me here how to create a db_link from to move records from five database to one centralized database, due to maintainance perspective i have to move the records from all the five databases to one centralized database. i have to write a script for moving the audit records from all the five databases to one centralized database, can anyone help me how to write the script, or if you have any related scripts , can u post here, it will helpful for me.

    spool audit.log
    --"Auditing Initialisation Parameters: check initialization parameter"
    select name || '=' || value from v$parameter where name like '%audit%'
    ---"if auditing is disabled then issue this command and bounce"
    alter system set audit_trail=db,extended scope = spfile
    shutdown immediate
    startup
    create tablespace ORDER_DATA datafile '+DDATA' size 50m;
    create user INFO identified by INFO;
    Grant connect,resource to INFO;
    Alter user INFO quota unlimited on ORDER_DATA;
    create table INFO.ORDER as select * from sys.aud$;
    alter INFO.ORDER add db_unique_name varchar2(50);
    create table INFO.ORDER
    partition by range (Timestamp#)
    subpartition by hash(dbid)
    subpartition template
    (subpartition sp1 tablespace users,
    subpartition sp2 tablespace users)(
    partition p1 values less than (TO_DATE('07/29/2010','MM/DD/YYYY')),
    partition p2 values less than (TO_DATE('07/29/2011','MM/DD/YYYY')),
    partition p3 values less than (MAXVALUE)) tablespace BGORDER_DATA as select * from sys.aud$
    spool off;
    exit
    BEGIN
    DBMS_SCHEDULER.create_job(
    job_name => 'Move Aud$ records',
    job_type => 'PLSQL_BLOCK',
    job_action => 'CREATE OR REPLACE PROCEDURE bgorder_aud
                        AS
                   ts TIMESTAMP;
                   BEGIN
    ts := SYSTIMESTAMP;
    insert into info.order select * from sys.aud$ where timestamp# < ts;
    delete sys.aud$ where timestamp# < ts;
    commit;
    END;
    start_date => TRUNC(SYSDATE) + 22 / 24,
    repeat_interval => 'FREQ=daily;BYHOUR=22;BYMINUTE=0;BYSECOND=0',
    enabled => TRUE,
    comments => 'Move records');
    END;
    /

  • Using Bitmap Index over db link.

    I've a problem with the following query:
    select count(*)
    from TABLE_A@db_link TABLE_A, TABLE_B
    where TABLE_A.ACCEPTTIME = TABLE_B.TIME_B
    The above query is doing a full table scan (even after forcing index hints) on TABLE_A which has about 300M records.
    TABLE_A is a local table while TABLE_B is remotely accesed using db_link.
    There is a bitmap index created on the ACCEPT_TIME field of TABLE_A which is not used by the query. However when I fire this query:
    Am I missing something here? How can I make the optimizer use the bitmap index on TABLE_A using remote db_link?
    Here is the explain plan for the above query:
    Operation     Object Name     Rows     Bytes     Cost     Object Node     In/Out     PStart     PStop
    SELECT STATEMENT
    Optimizer Mode=ALL_ROWS          1           2                     
    SORT AGGREGATE          1      17                          
    NESTED LOOPS          1      17      2                     
    REMOTE     .COPY_STM     1      9      2
         STAG_PLMSPDB1.SMART.COM.PH     SERIAL          
    INDEX RANGE SCAN     SYSTEM.DIM_TIME_INDX1     1      8      0                     
    Regards,
    Raj

    Here is a simple case to explain the problem more clearly:
    1. dept: database1 (small table dimension with 4 rows)
    2. emp: database2 (large table fact with 50K rows)
    3. Table emp has bitmap index on column "deptno"
    4. Both tables are analyzed with defualt values using DBMS_STATS.GATHER_TABLE AND INDEX STATS
    5. DB Link db2 is created from database1 to database2
    Observations:
    a) On Database2 when the following query is issued:
    select count(*) from emp@DATABASE1 emp, dept where emp.deptno = dept.deptno
    It does not use the bitmap index.
    b) On Database1 when the following query is issued:
    select count(*) from emp emp, dept@DATABASE2 where emp.deptno = dept.deptno
    It does use the bitmap index since it is available optimizer has this information locally.
    My question is how can I make use of the statistics effectively, so that the optimizer knows it has to use the bitmap index present in the remote db.
    Regards,
    Raj

  • High cpu usage while inserting

    i've 10g database running on sun machine
    insert into id_air_e (aire_key, aire_0) values (:b0,:b1) taking too much time, it has fk on aire_key column reference to other table
    this Insert script inserts into the primary table & this table but it takes lots of CPU when inserting in secondary table
    Please advice how to speed up the insertion.

    Hi Buddy,
    In order to help you better, some questions need to be answered first.
    1) How many rows are been inserted?
    2) Is there any trigger enabled on this tables?
    3) Is the secondary table local or remote (using db_links)?
    4) Is there any index on the secondary table?
    5) Which wait event the session running the insert statement is waiting for? select event from v$session where SID = <sid inserting rows>;
    Cheers,
    JSoufer - Brazil

  • Problem in scheduler - Oracle 10G

    I have 2 databases connected through a connected user link.
    Example:
    1) TEST schema in db1 and TEST schema in db2 connected through DB link LINK1 which is through connected user (Username and password not provided while creating DB link since they have same username and passwords).
    2) I create table T1 in TEST@DB1 and synonym T1 in TEST@DB2.
    3) I create a procedure P1 in TEST@DB2 which inserts into T1.
    4) I run the procedure P1 in TEST@DB2 and it successfully inserts into T1.
    5) I create a job through dbms_scheduler.create_job and schedule P1 to run every 1 minute
    6) Through the scheduler it gives an error saying "Invalid username/password" while accessing T1.
    7) Without connected user it work fine.
    Any idea anyone?

    it might be a requirement. To be able to use db_links in stored procedures ab/or scheduled db jobs you need a db_link with a defined user/pwd.
    You already found the workaround for your problem. Just set up the db link correctly. Is there a reason to do otherwise?

  • Problem when call store procedure over a database link

    Hi all,
    I've create a database link in server "EAST" similar like:
    CREATE DATABASE LINK db_link CONNECT TO tiger IDENTIFIED BY scott USING 'abc';
    and from server "EAST" i ran the procedure located in server "WEST" somethin like:
    exec testing_procedure@db_link('test');
    testing_procedure is look like:
    Create or Replace procedure testing_procedure (p_testing in varchar2)
    as
    cursor check_space is
    select sum(bytes)/1024/1204 tb_size
    from dba_data_files;
    my_check_space%ROWTYPE;
    begin
    open check_space;
    loop
    fetch check_space into my_check_space;
    exit when check_space%NOTFOUND;
    insert into test_tf@db_link (test, tb_value) values
    (p_testing, my_check_space.tb_size);
    end loop;;
    close check_space;
    end;
    and my problem is when i'm run procedure from "EAST" server, the values in test_tf table is the same as when you run that procedure from "WEST" server. I've check the size for both server "EAST", and "WEST" by select sum(bytes)/1024/1204 command. And the value is completely different. And i guest somehow it reuse the value of "WEST" server no matter when you run that procedure in "EAST" server. Any suggesttion, please give me some advices.
    Thanks,
    Kevin

    If this procedure is in WEST server then even if you call it from some another planet using db link, the cursor inside the procedure will fetch the data from that server only means WEST server. So "select sum(bytes)/1024/1204 tb_size
    from dba_data_files;" statement in your procedure always fetch the size of the datafiles belongs to the WEST database.
    If you want to store the data of two different databases then you have to create the similar procedure in EAST database also.
    BTW, you said the you created a database link "db_link" in EAST database to point to WEST database and on WEST database you have that procedure BUT I don't understand why r u using "db_link" in your procdure code in WEST server in this insert statement:
    insert into test_tf@db_link (test, tb_value) values
    (p_testing, my_check_space.tb_size);Is there a database link on that box also?? Where it is pointing to?? And if not then this code should not be compiled.
    Daljit Singh

  • How to open multiple db connections from one form?

    Hello,
    We have two different Oracle databases and need to access them (read and write) from the same form. Is there a way to do this, apart from using EXEC_SQL as described in Note 67516.1 ? I could also use db_links and synonyms, but this would add an extra maintenance aspect that I'd like to avoid.
    Thanks,
    :-Phil

    Sorry Phil,
    but that's all you got.
    Frank

  • How to validate Compnay Codes entered through PFCG Transaction

    Hi friends,
                  I am uploading EXCEL File containing company codes for different combinations of Role and Organization elements.Now I have to validate these compnay codes with those entered into System through the PFCG Transaction .Gor Eg.In file AA01 - AA10 is the Range of Company code while in System
    AA01- AA08,
    AA09,
    AA11,
    AA22
            These can be different Low and High values of company codes.How can i validate file with the System .In this case I can't use T001 Table as these codes are enterd into system which can later be Implemented and all other Org.Level settings will done later.If anyone have any idea,plz let me know.

    Hello Helena Marková-
    Thanks for the reply.
    Can you explain in detail what does your steps will do.
    Creating when-validate-item trigger on item adj_flag will work as it is at the item level trigger and it will fire whenever the user changes that item. But, I want to do the validations after user entered/changed all the values, I mean do the validations when user is trying to save at the very end.
    Reason being that, by having trigger at item level will work fine, but, validations include to compare the data over the db_link, so for every change in adj_flag the trigger will fire and validation will happen using db_link which could be slow process.
    I want to do the validations at the very end so if user changes that particular item many times, and see the test case I mentioned, where it validates even when there is no change in the focused item.
    Thanks,
    r2b.

  • About DBA_DEPENDENCIES and REFERENCED_LINK_NAME

    Hi, i have a question about, the info of DBA_DEPENDENCIES, i found the next two rows on the same database, and i don't understand why they are about the same synonym, that uses a database link, but here it appears two times, once with the db_link that it is related to, and other without the db_link.
    OWNER      NAME      TYPE        REF_OWNER  REF_NAME    REF_TYPE    REF_LINK_NAME     DEPENDENCY_TYPE
    SCHEMAX    PROCX     PROCEDURE   PUBLIC     SYNONYMX       SYNONYM          DB_LINK_X        HARD
    SCHEMAX    PROCX     PROCEDURE   PUBLIC     SYNONYMX      SYNONYM          NULL             HARDSomebody knows what is the reason of this?
    Thank you.
    Edited by: user11173393 on 10/12/2010 02:26 PM
    Edited by: user11173393 on 10/12/2010 02:27 PM

    http://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:3225568207176
    +"+
    +We are missing something in this discussion. Just wanted to Add to it and would also like to know.+
    +How can we find out depencenies on the Objects of a remote database. Let's assume I have created a+
    +view and i am referring to a table of Remote database using DB_LINK.+
    +How can i find out these kind of dependencies. I tried to user DBA_DEPENDENCIES.+
    +DBA_DEPENDENCIES describes all dependencies in the database between procedures, packages,+
    +functions, package bodies, and triggers, including dependencies on views created without any+
    +database links.+
    +Followup December 23, 2009 - 7am Central time zone:+
    +Your object is dependent on the database link - and that is all.+
    +I like to use views, as they import the metadata of the remote table and it is pretty clear what the view refers to to (single table view). It makes the compilation of the procedure a bit speedier as well since the procedure is dependent on the view, not on the database link behind the view - we don't need to even open the link to compile the procedure.+
    +"+
    Hope This Helps.
    Ogan

  • Need help about distributed sql statement

    Hello everybody
    Enviroment:
    Oracle 11g R1.
    This Database was fine, 'till some days ago that a new system was deployed on other database. New system runs some SELECT querys to a my database using db_links. These statements are blocking some resources and 'cause that they are blocking many users of my database. I can see on Enterprise Manager this wait event : "enq: TM contention".
    Now my question is, why are these querys are blocking resources and users if they are only of type SELECT??? I thought that querys that did this were DML and DDL statements.
    Does this behavior is related with that those querys are executed by a distributed way (using dblinks)??
    Thanks a lot

    user652447 wrote:
    Distributed Transactions require commit even if a Select. See the following FAQ post from Jonathan Lewis for some basic information.
    http://www.jlcomp.demon.co.uk/faq/dblink_commit.html
    HTHNot always true though, it depends. The article you are linking to is quite old and covers, as stated, Oracle version(s): 7.0 – 9.2. Whereas the OP is on 11.
    http://download.oracle.com/docs/cd/B10500_01/server.920/a96521/ds_txns.htm
    In the section "Read-Only Response"
    Note that if a distributed transaction is set to read-only, then it does not use rollback segments. If many users connect to the database and their transactions are not set to READ ONLY, then they allocate *rollback space* even if they are only performing queries.
    In the OP's version
    http://download.oracle.com/docs/cd/E11882_01/server.112/e17120/ds_txns003.htm#ADMIN12226
    Note that if a distributed transaction is set to read-only, then it does not use undo segments. If many users connect to the database and their transactions are not set to READ ONLY, then they allocate *undo space* even if they are only performing queries.
    However that doesn't account for the types of lock the OP is experiencing.

Maybe you are looking for