Calling anonymous block from Unix

I have a very simple block of code I'm calling from a wrapping ksh script, it works well but I'm having a hard time getting output from PL/SQL back to my ksh script.
Output from $OUT1 is none
Please advise.
Script:
#!/bin/ksh
# Set environment
. ~/.profile
export ORACLE_SID=vastrp
sqlplus -s / as sysdba>$OUT1<<!
set serveroutput on size 1000000
DECLARE
scn_num number;
BEGIN
select max(next_change#)-1 into scn_num from v$archived_log where next_time > trunc(sysdate) and next_time < trunc(sysdate) + 5/1440;
dbms_output.put_line('SCN:' || to_char(scn_num));
dbms_output.put_line('Print NOW');
END;
exit;
echo $OUT1
exit
----------------------------------------------------------

Here is an example.
   1  i=`sqlplus -s xopmaster/xopmaster<< eof
2  set serverout on;
3  set feedback off;
4  set heading off;
5  exec dbms_output.put_line('Hello world');
6
7  exit;
8  eof`
9  echo $i
"test.sh" 9 lines, 155 characters
hdev1:/apps/home/> ./test.sh
Hello world

Similar Messages

  • Calling Anonymous block from VO

    Hi All,
    I have an Anonymous block which contains Record types, table types, functions, and procedure. Procedure returns multiple rows using all functions and types. I want to display those rows in Advanced table in OAF page. Please suggest methods to get this done.
    Thanks in advance.
    Kaushik Rambhiya

    Hi Kaushik ,
    You can make use of Prepared statment or Callable statement (both are Java API's ) to call an pl/sql block .
    Regards ,
    Keerthi

  • Calling a report from unix shell script

    Hi,
    I had to call a report from unix shell script.
    May i know the procedure to accomplish this
    Thanks in Advance
    A.Gopal

    First you should not include the whole path to your report in the call ...
    Use like this:
    /ora/u01/oracle/v101/as2/bin/rwrun.sh report=an_stati destype=file desname=/ora/u01/oracle/v101/as2/test.pdf desformat=pdf
    In $ORACLE_HOME/bin/reports.sh:
    1) Verify that you have updated the REPORTS_PATH variable to include your folder where you have the report in question
    REPORTS_PATH=/ora/u20/app/qits/env1/run:$ORACLE_HOME/reports/templates:$ORACLE_HOME/reports/samples/demo: ....
    2) Verify that the REPORTS_TMP variable is pointing to a valid location and that the oracle user has access to write on it.
    After that, post the content of the tracefile located at $ORACLE_HOME/reports/logs/{in-process report server name folder}/rwserver.trc
    If no file is present then it means that you need to enable trace in your reports's conf file.... go to the $ORACLE_HOME/reports/conf folder and and locate the .conf file that correspond to your in-process reports server name (as specified in the rwservelet.properties file)... open/edit the file to enable trace logs ..
    i.e.
    Change the following line:
    <!--trace traceOpts="trace_all"/-->
    to <trace traceOpts="trace_all"/>
    Bounce the reports server and try to run the report again, this time the .trc file should be generated, post the content so that we can take a look.

  • My outgoing calls are blocked from Southern Ireland how to unblock

    My outgoing calls are blocked from irelandneed to unblock them

    Hi ,
    Welcome to the community.
    What phone are you using?
    What network are you on EE/T-Mobile/Orange?
    And last question are you on contract?
    If you could reply with this, I will try andf get you sorted to make calls in Ireland .
    Thank you.

  • Calling PL/SQL anonymous block from href in tabular report

    apex 2.2.
    I've got a tabular report where I've added some img columns with a href to call diff processes
    for example
    "<a href="f?p=&APP_ID.:22:&APP_SESSION.:BRANCH_TO_PAGE_ACCEPT|NEW_PROXY:NO:::22,ABCDEF ><img src="/i/asyl.gif" border="0" alt="Runprocess"></a>"
    When clicking on an image column in row x then I would like to run the process - no page submit.
    The pl/sql anonymous block process source calls package.storedproc(p1,p2) - two in parameters
    I'm struggling with the syntax and is wondering if there's a smarter way to achieve the same function
    Any ideas most welcome
    Thanks
    Peter

    &lta href="f?p=&APP_ID.:22:&APP_SESSION.:BRANCH_TO_PAGE_ACCEPT|NEW_PROXY:NO:::22,ABCDEFG" &gt&ltimg src="/i/asylogin.gif" border="0" alt="Process"&gt&lt/a&gtQuestion is how can you pass values from a row in a tabular report to the application process ?

  • Help!! how to call pl/sql anonymous block from java?

    I know that jdbc can call a pl/sql package or procedure,but if i
    want to call a pl/sql anonymous block, how can i do it? no procedure
    name or package name will be offered.
    Can u give me a sample code? thanks very much

    thanks ,but do u make sure that it can work? i have tried to do like this ,but i can not get it. Or please give me a detail code, thanks very much

  • Calling stored procedure from unix shell script

    Hello,
    I am facing a problem while calling a stored procedure from UNIX shell script. I want to return a output variable from the stored procedure to the UNIX environment.
    Here is the code-
    #!/bin/sh
    OUTPUT=`sqlplus cmag/magnum@dw <<ENDOFSQL
    set serveroutput on;
    var prd_out varchar2(100);
    exec create_pm_window(:prd_out);
    exit;
    ENDOFSQL`
    echo " output is - $OUTPUT"
    The problem is :prd_out is not getting copied to shell variable OUTPUT.
    I have a dbms_output.put_line in the stored proc create_pm_window and I can see that prd_out is getting populated.
    Any help is really appreciated.
    Thanks'
    Rakhee

    First step :
    make sure the PL/SQL works as expected.
    Does the following display the expected output executed from SQL*Plus ?
    set serverout on
    declare
    prd_out varchar2(100);
    begin
    create_pm_window(prd_out);
    dbms_output.put_line('output is '||prd_out);
    end;
    I don't have your procedure, but using a dummy procedure like :
    Scott@my10g SQL>create procedure foo(p_out in out varchar2)   
      2  is
      3  begin
      4  select 'Hello '||instance_name into p_out from v$instance;
      5  end;
      6  /
    Procedure created. and a toto.sh script as :OUTPUT=`sqlplus -s scott/tiger <<EOF
    set pages 0 lines 120 trimout on trimspool on tab off echo off verify off feed off serverout on
    var mavar varchar2(100);
    exec foo(:mavar);
    print mavar;
    exit;
    EOF`
    echo "OUT = ${OUTPUT}"
    exitIt works fine :[oracle@Nicosa-oel ~]$ ./toto.sh
    OUT = Hello my10g

  • While calling rwrun.sh from unix, i am getting error

    Hi,
    I am calling rwrun.sh from linux.
    But, sometimes, it is generating the file and sends mail. but sometimes, throws the below error.
    REP-0736: There exist uncompiled program unit(s).
    REP-0069: Internal error
    REP-50002: Server is shutting down
    This is the command i am using.
    $ORACLE_HOME/bin/rwrun.sh userid=anantgop/kolahal123\[email protected] report=an_stati destype=mail desname="[email protected]" desformat=SPREADSHEET ip_rep_id='AN_STATI'
    Could you please anyone guide me whether i need to increase any timeout parameters anywhere.
    Thanks & Regards
    A.Gopal
    Edited by: A.Gopal on Apr 27, 2010 11:47 PM
    Edited by: A.Gopal on Apr 27, 2010 11:52 PM

    Hi,
    you can use this code...
    import oracle.apps.fnd.cp.request.ConcurrentRequest;
    import oracle.apps.fnd.framework.server.OADBTransaction;
    public int submitCPRequest(Number headerId) {
    try {
    OADBTransaction tx = (OADBTransaction)getDBTransaction();
    java.sql.Connection pConncection = tx.getJdbcConnection();
    ConcurrentRequest cr = new ConcurrentRequest(pConncection);
    String applnName = "PO"; //Application that contains the concurrent program
    String cpName = "POXXXX"; //Concurrent program name
    String cpDesc = "Concurrent Program Description"; // concurrent Program description
    // Pass the Arguments using vector
    // Here i have added my parameter headerId to the vector and passed the vector to the concurrent program
    Vector cpArgs = new Vector();
    cpArgs.addElement(headerId.stringValue());
    // Calling the Concurrent Program
    int requestId = cr.submitRequest(applnName, cpName, cpDesc, null, false, cpArgs);
    tx.commit();
    return requestId;
    } catch (RequestSubmissionException e) {
    OAException oe = new OAException(e.getMessage());
    oe.setApplicationModule(this);
    throw oe;
    Now to go to the Monitoring page.
    set the forward url to
    String url = "OA.jsp?akRegionCode=FNDCPREQUESTVIEWREGION&akRegionApplicationId=0";
    try {
    pageContext.setForwardURL(url,
    null,OAWebBeanConstants.KEEP_MENU_CONTEXT, null,
    params, true,
    OAWebBeanConstants.ADD_BREAD_CRUMB_NO,
    OAWebBeanConstants.IGNORE_MESSAGES);
    catch (Exception e)
    throw new OAException("SetDeferredException " +
    e.getMessage(),OAException.ERROR);
    }

  • Call ABAP program from Unix script passing dynamic filename

    Hi,
    Does anyone know if it is possible to call an ABAP program from a Unix script passing a dynamic filename to the ABAP program?
    We are receiving a file from an external company and on receipt of the file want to call an ABAP program passing the filename.  The filename is made up of File ID, Date and Time which we need to read in the ABAP program.  We usually use Events to trigger a program which is fine when the filename if static however since this filename will be dynamic we cannot do this.  In addition we cannot just rename the file to a static name in the Unix script as we need to know the value of the date and time from the file ID in the ABAP program.  I can change the ABAP program to check our /in directory for a Filename that starts with the fixed File ID however I thought there must be a better way of doing this.  We want the external company to put this information in a file header record but they don't want to change the file contents.  Any ideas would be appreciated.
    Thanks,
    Sinead.

    You could follow the following method
    1.Let the external file reside in the SAP application layer in a defined path e.g. /usr/sap/tmp/interface/working/
    2.Write an ABAP program which will include the following steps:-
       i) read all files in the file path using function module EPS_GET_DIRECTORY_LISTING
      ii) Read the data from files existing in the directory using OPEN_DATASET statement
    iii) After the files have been read move the files to another directory e.g. /usr/sap/tmp/interface/backup/ or you can delete the file.
    3.Schedule this program to be executed depending on the frequency of the external file being generated.

  • Calling Form/Block from another Form/Block

    I have several form/blocks in my application with field COMPANY_NAME/ID. How can I navigate from more then 1 form/block to the same Form (with Company information)
    From 1 Block it is easy: Where clause: :t_bedrijf_lijst.bedr_id = t_bedrijf.bedr_id
    But now :t_bedrijf_lijst. is depending from the previous form or block
    can anyone help me with this?

    Hi Slot
    Make a package like this in any PL/Sql Library which is attached to your forms:
    PACKAGE GLOBAL_VAR IS
    v_company_name varchar2(15);
    v_company_id     varchar2(10);
    END;
    and whichever form you want to refer it you can refer this way:
    MESSAGE(GLOBAL_VAR.v_company_name);
    MESSAGE(GLOBAL_VAR.v_company_ID);
    hth
    ARIF

  • Calling anonymous role from html

    Hi All,
    I'm having a problem difficult to find solution.
    I have created a role and assigned anonymous user group to it. Then I've created an html and placed it inside KM and gave link - http://<host>:<port>/irj/portal/anonumous into this html.
    Now, when i directly copy the url of this html to IE, the html comes and clicking on the anonumous role link, the role opens.
    But, i have cretaed an UME user (it has everyone and authenticated user group assigned to it). Now, i'm logging into portal (http://<host>:<port>/irj/portal) with this user and going to the same html page. And, then when I click on the role link - the new window is coming with anonymous portal link but instantly it's forwarding to the html page again.
    Can you guys give me any idea why this is happening. Is it like anonymous link cannt be accessed by logging in.
    Pls help as i'm stuck into it. Any help would be appreciated....
    Best Regards,
    Sen

    Hello Sen.
    It happens because you do not provide a navigation target in your link.
    Modify your link as follows:
    http://<host>:<port>/irj/portal/anonymous?NavigationTarget=<target  iview in your anonymous role>
    Where <target  iview in your anonymous role> can be either in [ROLES|http://help.sap.com/saphelp_nw04/helpdata/en/2d/91e33edd37de63e10000000a11405a/frameset.htm] format or [Short Urls|http://help.sap.com/saphelp_nw04/helpdata/en/b3/7b8163404448e7aad7899c0b30313e/frameset.htm] format.
    Best regards,
    Aliaksandr Zhukau

  • Getting value with an anonymous block using ODP

    Hi all!
    I have a problem I hope someone can help me with. I believe it to be a minor one. I am trying to imbed an anonymous block into my .net app and use it dynamically to get a value from the database depending on the values in a tables. Since my procedure is quite large I am displaying a small example proc for simplicity purposes. Basically I want to execute an anonymous block from my app that will return a value (not a row or rows) from the database. The code is below:
    Private Sub test()
    Dim cn As New OracleConnection(profileString)
    Try
    Dim sb As New System.Text.StringBuilder
    sb.Append("Declare ")
    sb.Append("v_maxnum varchar2(6); ")
    sb.Append("Begin ")
    sb.Append("Select max(to_number(email_address_id)) into ")
    sb.Append("v_maxnum from CVWH14_CDRV_TEST.EMAIL_ADDRESS_TBL; ")
    sb.Append("dbms_output.put_line(v_maxnum); ")
    sb.Append("Exception ")
    sb.Append("When Others ")
    sb.Append("Then ")
    sb.Append("dbms_output.put_line('Program run errors have occurred.'); ")
    sb.Append("End; ")
    Dim cmd As New OracleCommand(sb.ToString, cn)
    With cmd
    cmd.CommandType = CommandType.Text
    Dim parm As New OracleParameter
    parm.ParameterName = "v_maxnum"
    parm.OracleType = OracleType.VarChar
    parm.Direction = ParameterDirection.Output
    parm.Size = 6
    cmd.Connection.Open()
    Dim ret As Object = cmd.ExecuteScalar()
    Dim res As String = cmd.Parameters.Item(0).Value.ToString -- **Error is occuring here**
    cmd.Connection.Close()
    cmd.Dispose()
    End With
    Catch ex As Exception
    MessageBox.Show(ex.Message, "Error")
    'End If
    If cn.State = ConnectionState.Open Then
    cn.Close()
    End If
    End Try
    End Sub
    The exception error reads "Invalid Index 0 for this OracleParameterCollection with Count=0."
    If I can figure out how to get a parameter value from the database via the anonymous block, I can apply the logic to the real application. Any help or direction I could receive would be greatly appreciated. Thanks for reading this post!

    Thank you for responding. The code that I posted was just one of many ways I have tried. I retried the proc making just 2 changes:
    Private Sub test()
    Dim cn As New OracleConnection(profileString)
    Try
    Dim sb As New System.Text.StringBuilder
    sb.Append("Declare ")
    sb.Append("v_maxnum varchar2(6); ")
    sb.Append("Begin ")
    sb.Append("Select max(to_number(email_address_id)) into ")
    sb.Append("v_maxnum from CVWH14_CDRV_TEST.EMAIL_ADDRESS_TBL; ")
    sb.Append("dbms_output.put_line(:v_maxnum); ") -- !Changed this to a bind variable!
    sb.Append("Exception ")
    sb.Append("When Others ")
    sb.Append("Then ")
    sb.Append("dbms_output.put_line('Program run errors have occurred.'); ")
    sb.Append("End; ")
    Dim cmd As New OracleCommand(sb.ToString, cn)
    With cmd
    cmd.CommandType = CommandType.Text
    Dim parm As New OracleParameter
    parm.ParameterName = ":v_maxnum" -- !Changed this to a bind variable!
    parm.OracleType = OracleType.VarChar
    parm.Direction = ParameterDirection.Output
    parm.Size = 6
    cmd.Connection.Open()
    Dim ret As Object = cmd.ExecuteScalar() -- !The error is now occuring here!
    Dim res As String = cmd.Parameters.Item(0).Value.ToString
    cmd.Connection.Close()
    cmd.Dispose()
    End With
    Catch ex As Exception
    MessageBox.Show(ex.Message, "Error")
    If cn.State = ConnectionState.Open Then
    cn.Close()
    End If
    End Try
    End Sub
    I am now getting the error message "Not all variables bound". Any more help or direction that you could throw my way would be greatly appreciated.

  • Crash using block from mutable dictionary

    What can people tell me about why this program crashes:
    #import <Foundation/Foundation.h>
    @interface Action : NSObject
    + (void)execute;
    @end
    @implementation Action
    + (void)execute
        NSLog(@"The action was executed.");
    @end
    @interface ActionPerformer : NSObject {
    @private
        NSMutableDictionary* _namedActions;
    + (ActionPerformer*) performer;
    - (void)addAction:(NSString*)action withClass:(Class)class andSelector:(SEL)selector;
    - (void)performAction:(NSString*)action;
    @end
    @implementation ActionPerformer
    typedef void(^ActionBlock)();
    + (ActionPerformer*) performer
        ActionPerformer* performer = [[ActionPerformer alloc] init];
        performer->_namedActions = [NSMutableDictionary dictionary];
        return performer;
    - (void)addAction:(NSString*)actionName withClass:(Class)class andSelector:(SEL)selector
        ActionBlock block = ^(){ [class performSelector:selector]; };
        // Verify things work
        block();
        [_namedActions setObject:block forKey:actionName];
    - (void)performAction:(NSString*)actionName
        ActionBlock block = [_namedActions objectForKey:actionName];
        // Crash happens here!!!
        block();
    @end
    int main()
        @autoreleasepool {
            ActionPerformer* performer = [ActionPerformer performer];
            [performer addAction:@"action" withClass:[Action class]
                andSelector:@selector(execute)];
            [performer performAction:@"action"];       
        return 0;
    I am using Mac OS X 10.6.8 with Xcode 4.2 and Apple LLVM compiler 3.0

    Thanks etersoft,
    I tried exactly what you suggested and I was able to call the block from the dictionary.
    I assume that if someone is using garbage collection they don't need to worry about calling release on the block held in the dictionary.
    Also, if someone is using automatic reference counting, I'm wondering if that would also take care of calling the release as well.

  • Calling sql script from anonymous block

    Hi
    how to call an script from an anonymous block, like
    declare
    v_reccord_account number :=0;
    begin
    SELECT xx.cc INTO v_reccord_account FROM
    (select count(1) cc
    from accounts
    group by account_id
    having count(account_id) > 1
    )xx
    where ROWNUM=1;
    if v_reccord_account <1
    then
    dbms_output.put_line('no duplicates');
    ELSE
    < here i have to call this script -- @e:/test44.SQL >
    end if;
    end;

    Hi
    thanks for replying, i'm having some sql statements, i have to spool the results of those statements .. below is the content of the file i'm calling.
    =================================================
    whenever sqlerror exit sql.sqlcode
    set serveroutput on
    column fn new_value filename
    select 'remove_duplicates_'||to_char(sysdate, 'yyyymmddhh24miss')||'.log' as fn from dual;
    spool E:/&filename
    prompt 'Checking for duplicates'
    --select account_id, count(1)
    --from accounts
    --group by account_id
    --having count(1) > 1;
    prompt 'Records to be deleted'
    select *
    from accounts
    where decode ( substr(account_id,1,3),'COG',1,0)=1
    group by account_id
    having count(1) > 1;
    prompt ' Deleting duplicates'
    delete
    from accounts
    where account_id in (
    select account_id
    from accounts
    where decode ( substr(account_id,1,3),'COG',1,0)=1
    group by account_id
    having count(1) > 1
    commit;
    ==========================================

  • INVALID CURSOR - Anonymous Block calling Cursor in function

    I am getting an error when trying to call my cursor.
    CREATE OR REPLACE PACKAGE tax_update
    AS
    TYPE gencur IS ref cursor;
    FUNCTION tax_sf
       p_state IN bb_tax.state%type,
       p_thecursor IN OUT gencur
    RETURN NUMBER;
    END;
    CREATE OR REPLACE PACKAGE BODY tax_update
    AS
    FUNCTION tax_sf
       p_state IN bb_tax.state%type,
       p_thecursor IN OUT gencur
    RETURN NUMBER
      IS
      lv_taxrate NUMBER;
    BEGIN
      OPEN p_thecursor FOR
       SELECT taxrate
       FROM bb_tax
       WHERE state = p_state;
      RETURN lv_taxrate;
    END;
    END;
    DECLARE
      tax_cur tax_update.gencur;
      rec_tax bb_tax%rowtype;
    BEGIN
    LOOP
      FETCH tax_cur INTO rec_tax;
       EXIT WHEN tax_cur%NOTFOUND;
        DBMS_OUTPUT.PUT_LINE(rec_tax.taxrate);
    END LOOP;
    END;
    DECLARE
    ERROR at line 1:
    ORA-01001: invalid cursor
    ORA-06512: at line 6Assignment is to create a package that will hold tax rates by state in a packaged cursor. The package will contain a function that can receive a 2 character state abbr. as an argument and find a match in the cursor and return the tax rate for tha tstate. An anonymous block will test the function with state of NC.
    Can anyone assist?

    You would need to call the function to open the cursor before you try to fetch from the cursor
    DECLARE
      tax_cur tax_update.gencur;
      rec_tax bb_tax%rowtype;
      l_some_number number;
    BEGIN
      l_some_number :=  tax_update.tax_sf( <<some state parameter>>, tax_cur );
      LOOP
        FETCH tax_cur INTO rec_tax;
        EXIT WHEN tax_cur%NOTFOUND;
        DBMS_OUTPUT.PUT_LINE(rec_tax.taxrate);
      END LOOP;
    END;A couple of points, though.
    1) Your function returns a NUMBER but that NUMBER will always be NULL. It seems rather unlikely that this is really what you want. It would seem to make more sense for the function to return the cursor rather than returning a superfluous number.
    2) Your function requires a `bb_tax.state%type` parameter. But your anonymous block doesn't seem to have any concept of a state so I'm not sure what you want to pass in there.
    3) Looking at the code, it seems a bit odd that your cursor returns a single column of data. If a state can have multiple rates, wouldn't you need to select some additional criteria in order to figure out which sort of tax each row represents or to otherwise differentiate different rows? If a state can only have a single tax rate, it makes no sense to open a cursor that is only going to ever return a single row.
    4) There is no need to declare your own weak ref cursor type (tax_update.gencur). You can just use the Oracle built-in type SYS_REFCURSOR.
    Justin

Maybe you are looking for