DBAsupport.com Forums - Powered by vBulletin
Results 1 to 9 of 9

Thread: ip

  1. #1
    Join Date
    Jul 2002
    Posts
    10

    Question

    HI, I have a problem...really not only one...How can I obtain the ip address with plsql????
    Thanks in advance,



  2. #2
    Join Date
    May 2002
    Posts
    2,645
    Create a trigger, program unit or store function using SYS_CONTEXT function to get the IP address.

    Example:
    CREATE OR REPLACE Function IP
    RETURN Varchar2
    IS
    v_ip Varchar2(30);
    Begin
    Select SYS_CONTEXT('USERENV','IP_ADDRESS')
    Into v_ip
    From Dual;
    Return v_ip;
    End;

    For more information on the SYS_CONTECT function refer to:
    Oracle8i Application Developer's Guide - Fundamentals.

    You can do Select SYS_CONTEXT('USERENV','IP_ADDRESS') from dual;
    in a SQL*Plus session if all you want is your IP address.

  3. #3
    Join Date
    Jul 2002
    Posts
    10

    Question

    Thanks a lot!

    ....ops...

    I have create function ip...now ??????

    I'm startin use oracle and plsql monday!!!!


  4. #4
    Join Date
    May 2002
    Posts
    2,645
    You have the code (in my previous post) to create the function. Shouldn't be any problem.

  5. #5
    Join Date
    Jul 2002
    Posts
    10
    The function is ok, but I want to store client' ip in a log file and in a table, so how can execute it in a procedure??


  6. #6
    Join Date
    May 2002
    Posts
    2,645
    declare
    client_ip varchar2(20);
    begin
    client_ip := select statement to get IP address
    insert into table_name (IP) values (:client_ip);
    Use the utl_file utility to write to a log file
    end;

  7. #7
    Join Date
    Jul 2002
    Posts
    10
    Ok...but there is a problem...

    this is my procedure:

    create or replace procedure bo is
    client_ip varchar2(20);
    begin
    client_ip := marco();
    insert into ipm values(client_ip);
    htp.prints(client_ip);
    end bo;

    and this, my function:

    CREATE OR REPLACE Function marco
    RETURN Varchar2
    IS
    v_ip Varchar2(30);
    Begin
    Select SYS_CONTEXT('USERENV','IP_ADDRESS')
    Into v_ip
    From Dual;
    Return v_ip;
    End;


    when i'm calling procedure by browser, client_ip is the server ip!!!
    I don't know why!...can u help me?

    thank u for everything...

  8. #8
    Join Date
    May 2000
    Location
    ATLANTA, GA, USA
    Posts
    3,135
    The sys_context will not give server ip address.
    Even if you run the procedure in the server machine, this will return NULL value.
    The SYS_CONTEXT('USERENV','IP_ADDRESS') will work only at the client side.

  9. #9
    Join Date
    Jul 2002
    Posts
    10
    i have oracle client on my machine(m1) and oracle db (8i) on another(m2)...if i run procedure on my pc using plsql dev, ip is my ip, but if i run procedure calling by browser, ip is the server ip (where oracle db is installed)
    I try the use select sys_context('userenv','ip_address')ip from dual; on m2 and the result is m2' ip....
    I don't know what is the problem.
    thank u for your answer!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Click Here to Expand Forum to Full Width