Get value from PL/SQL procedure to shell variable

Hello,
I have one little problem. I want to run plsql procedure from shell program and then I want to fill a shell variable with return value of plsql procedure or function. But I don't want to pass this value to some file and then read it.
Thank's

user9357436 wrote:
Hello,
I have one little problem. I want to run plsql procedure from shell program and then I want to fill a shell variable with return value of plsql procedure or function. But I don't want to pass this value to some file and then read it.
Thank'sLike below?
bcm@bcm-laptop:~$ cat day.sh
set X
var1=$1
SQLPLUS="sqlplus -s"
LOGON="user1/user1 "
day=`$SQLPLUS $LOGON <<EOF
set heading off
set feedback off
set verify off
select 'Have a nice day!' from dual where dummy ='$var1';
exit;
EOF`
echo $day
bcm@bcm-laptop:~$ ./day.sh
Have a nice day!
bcm@bcm-laptop:~$

Similar Messages

  • Getting values from a stored procedure with no parameters

    Hi,
    I'm trying to get values out of a stored procedure that I created on SQL server. I'm trying to get XML values out of the database, but I'm not sure how to get any data out of it written to a file if the procedure doesn't have any parameters.
    So I'm just making a call:
    CallableStatement cs = conn.prepareCall("{call myproc}");
    cs.execute();How do I get values back from this stage?
    Thank you very much,
    Lior

    The short form answer, which assumes that the stored procedure is returning the XML as an out parameter would go something like this.
         public void build(String newUserID, String newPassword) throws SQLException {
              String sql = "{ call GET_ITEM_DETAIL(?, ?, ?, ?, ?, ?) }" ;
              try{
                   init(newUserID, newPassword) ;
                   setCallableStatement(getConnection().prepareCall(sql)) ;
                   getCallableStatement().setInt(1, getItemNumber()) ;
                   getCallableStatement().registerOutParameter(2, oracle.jdbc.driver.OracleTypes.CURSOR) ;
                   getCallableStatement().registerOutParameter(3, oracle.jdbc.driver.OracleTypes.INTEGER) ;
                   getCallableStatement().registerOutParameter(4, oracle.jdbc.driver.OracleTypes.VARCHAR);
                   getCallableStatement().registerOutParameter(5, oracle.jdbc.driver.OracleTypes.VARCHAR) ;
                   getCallableStatement().registerOutParameter(6, oracle.jdbc.driver.OracleTypes.VARCHAR) ;
                   getCallableStatement().execute() ;
                   setSqlResult(getCallableStatement().getInt(3)) ;
                   setSqlMessage(getCallableStatement().getString(4)) ;
                   if( getSqlResult() != 0 ){
                        throw new SQLException(getSqlMessage(), null, getSqlResult()) ;
                   setResultSet((java.sql.ResultSet) getCallableStatement().getObject(2)) ;
                   if( getResultSet() != null ){
                        while( getResultSet().next() ){
                             setItemType(getResultSet().getString("ITEM_TYPE")) ;
                             setItemValue(getResultSet().getString("ITEM_VAL")) ;
                             setDisplayType(getCallableStatement().getString(5)) ;
                             setDisplaySize(Integer.parseInt(getCallableStatement().getString(6))) ;
              catch(SQLException e){
                   java.util.Date now = new java.util.Date() ;
                   java.text.DateFormat format = java.text.DateFormat.getInstance() ;
                   setSqlMessage( e.getClass().getName() + " : " + format.format(now) + " : " + e.getMessage() + " : IN " + getClass().getName() ) ;
                   System.err.println(getSqlMessage()) ;
                   throw e ;
              finally{
                   closeResources() ;
         }The GET_ITEM_DETAIL stored procedure returns several out parameters of various types. The code registers them as out parameters along with an anticipated type and then calls the getXXX(n) method that corresponds with that data type in the appropriate position.
    As I mentioned in my other post, the onus of returning the XML is on the stored procedure, when you get it into Java it's going to be a java.lang.String that you can then parse by whatever means is appropriate to your situation.
    Regards,

  • Get the returned OUT value from Pl/Sql Procedure in AppMod

    Hi,
    I am using jdeveloper 10.
    In the database i have a procedure like this :
    procedure test (v1 in out number,
    v2 in number);
    And am calling this procedure from application module in this way :
    Object[] procArgs = new Object[]{v_1,
    v_2
    try {  
    callStoredProcedure("test (?,?)",procArgs);
    I want to read the value of the v1 parameter after procedure is executed. Can anyone tell me how can i do it from application module ?
    Thanks in advance,

    After the call of the proc the value should be in procArgs[0]
    Timo

  • PL/SQL Region : Getting values from PL/SQL generated form?  (APEX 2.2.0)

    Hi, all,
    If I've got an PL/SQL region that dynamically generates a form using HTMLDB_ITEM.TEXTAREA, what is the best way to get the contents of those form data at submit time?
    Thanks,
    Don
    Message was edited by:
    Don_84
    Edited for clarity.

    Don,
    The apex_item (nee htmldb_item) functions take an index number as a parameter. So if you give the textarea function p_idx=>1, it creates item f01. If you give it p_idx=>2, it creates item f02, etc. In your after-submit code, access the package variable apex_application.g_fxx where xx is the index number you used.
    Scott

  • Getting values from a datagrid to an ArrayCollection

    Hi, I have a drag and dropable datagrid. I fill it with rows of data from another datagrid. Finally, my application demands savings the data from the datagrid into an array collection along with the index of each row. How do i get values from a datagrid into an arrayCollection variable? Please help me..!

    Whatever is dropped into the DataGrid automatically goes into its dataProvider property, typically an ArrayCollection. Just access the data grid's dataProvider property to see the values.

  • Get value from Direct Database Request

    Hi Experts,
    I have report based on Direct Database Request which returns one row. I have to use value from this report in other one.
    So, I have to get value from query and set into some variable but I don't know there is any way to do it.
    Thanks in advance for any suggestion
    Regards,
    Esk

    Thank you for your reply, but I don't want to use variable in Direct Database Request in clausal 'WHERE' or 'IN'.
    I want value which returns query. For example if my Direct Database Request is : 'Select ID from table1', then
    I wand this 'ID' in variable to use it in other report.
    regards
    Esk
    Edited by: Eskarina on 21-may-2012 2:16

  • Get a return value from a stored procedure.

    hi all ,
    i need to know where i am going wrong with the below code. I am trying to get a value from a stored procedure. the return type is int. The stored procedure works fine as i've debugged it. The variable have been declared correctly.
    int n = 0;
    proc = conn.prepareCall("{ ? = call SP_GETITEMCURRENTSOH(?,?) }");
                proc.registerOutParameter(1, java.sql.Types.INTEGER);
                proc.setString(1, locationCode);
                proc.setString(2, itemCode);
                proc.execute();           
                n = proc.getInt(1);thanks

    Hi ayub_a,
    According the [ *setString*|http://java.sun.com/javase/6/docs/api/java/sql/CallableStatement.html#setString(java.lang.String,%20java.lang.String)] method of the [*CallableStatement*|http://java.sun.com/javase/6/docs/api/java/sql/CallableStatement.html] interface, the first parameter must be a parameter name and not an ordinal position index !!!
    Edit : I've just found out the solution, it must be :
    int n = 0;
    proc = conn.prepareCall("{ ? = call SP_GETITEMCURRENTSOH(?,?) }");
                 proc.registerOutParameter(1, java.sql.Types.INTEGER);
                 proc.setString(2, locationCode);
                 proc.setString(3, itemCode);
                 proc.execute();           
                 n = proc.getInt(1);Edited by: Chicon on Jul 5, 2009 7:48 PM

  • How do I return two values from a stored procedure into an "Execute SQL Task" within SQL Server 2008 R2

    Hi,
    How do I return two values from a
    stored procedure into an "Execute SQL Task" please? Each of these two values need to be populated into an SSIS variable for later processing, e.g. StartDate and EndDate.
    Thinking about stored procedure output parameters for example. Is there anything special I need to bear in mind to ensure that the SSIS variables are populated with the updated stored procedure output parameter values?
    Something like ?
    CREATE PROCEDURE [etl].[ConvertPeriodToStartAndEndDate]
    @intPeriod INT,
    @strPeriod_Length NVARCHAR(1),
    @dtStart NVARCHAR(8) OUTPUT,
    @dtEnd NVARCHAR(8) OUTPUT
    AS
    then within the SSIS component; -
    Kind Regards,
    Kieran. 
    Kieran Patrick Wood http://www.innovativebusinessintelligence.com http://uk.linkedin.com/in/kieranpatrickwood http://kieranwood.wordpress.com/

    Below execute statement should work along the parameter mapping which you have provided. Also try specifying the parameter size property as default.
    Exec [etl].[ConvertPeriodToStartAndEndDate] ?,?,? output, ? output
    Add a script task to check ssis variables values using,
    Msgbox(Dts.Variables("User::strExtractStartDate").Value)
    Do not forget to add the property "readOnlyVariables" as strExtractStartDate variable to check for only one variable.
    Regards, RSingh

  • Unix shell script run from pl/sql procedure

    Hi Guru
    I want to run unix shell script from pl/sql procedure. Actual I want to run it from developer 10g form.
    Please guide me in this regards
    Regards
    Jewel

    Look at the host or client_host builtins in the help

  • How to get values from a stored package variable of type record ?

    Sir,
    In my JClient form, I need to get values from a database stored package variable of type record. And the values are retained in the JClient form for the whole session. The values are copied only once when the form is started.
    What is the best way to do that ?
    Thanks
    Stephen

    Stephen,
    not sure what your model is, but if it is Business Components, I think I would expose the properties as a client method on the application module. This way all JClient panels and frames will have access to it. You could use a HashMap to store the data in teh app module.
    If JDBC supports the record type, then you should be able to call it via a prepared SQL statement. If not, you may consider writing a PLSQL accessor to your stored procedure that returns something that can be handled.
    Steve Muench provides the following examples on his blog page
    http://otn.oracle.com/products/jdev/tips/muench/stprocnondbblock/PassUserEnteredValuesToStoredProc.zip
    http://otn.oracle.com/products/jdev/tips/muench/multilevelstproc/MultilevelStoredProcExample.zip
    Frank

  • Returing array from PL/SQL procedure

    Hi,
    I am trying to return array from PL/SQL procedure. Heres is the code. I am getting an error "OracleParameter.ArrayBindSize is invalid ".
    Will anybody let me know what is wrong in following code. or does anybody have code to return PL/SQL array using VB.NET.
    oCommand.CommandText = "MyPack.TestVarchar2"
    oCommand.CommandType = CommandType.StoredProcedure
    Dim id As Integer = 10
    Dim deptname As String()
    Dim oParam1 As Oracle.DataAccess.Client.OracleParameter = New Oracle.DataAccess.Client.OracleParameter("id", Oracle.DataAccess.Client.OracleDbType.Int32)
    Dim oParam2 As Oracle.DataAccess.Client.OracleParameter = New Oracle.DataAccess.Client.OracleParameter("deptname", Oracle.DataAccess.Client.OracleDbType.Varchar2)
    oParam1.Direction = ParameterDirection.Input
    oParam2.Direction = ParameterDirection.Output
    oParam1.CollectionType = Oracle.DataAccess.Client.OracleCollectionType.None
    oParam2.CollectionType = Oracle.DataAccess.Client.OracleCollectionType.PLSQLAssociativeArray
    oParam1.Value = id
    oParam2.Value = ""
    oParam1.Size = 10
    oParam2.Size = 20
    oCommand.Parameters.Add(oParam1)
    oCommand.Parameters.Add(oParam2)
    oCommand.ExecuteNonQuery()
    Thanks
    Sameer

    Thanks Arnold for the reply..
    Yes, I am trying to get result set in array which is unknow to me (No of rows return by the query). For the test I will pre-define the result set so that I will able to set ArrayBindSize.
    I have read C# example but when I try to write it in VB.NET it gives me syntax error when I try to set the ArrayBindSize.
    oParam.ArrayBindSize = new int[3]{15,23,13} // individual max size of 3 outputsWill you please let me know how to set ArrayBindSize (VB.NET) because I am new to this..
    There is an example at otn "How to: Bind an Array to an ODP.NET Database Command" which does multiple INSERTs in one trip to database. This works fine. I need to do same for the SELECT statement which will return me multiple rows. I do not mean refCursor. If I use refCursor, it will make soft parse which I am trying to avoid using this Array techniq.
    Thanks
    Sameer

  • From two given tables, how do you fetch the values from two columns using values from one column(get values from col.A if col.A is not null and get values from col.B if col.A is null)?

    From two given tables, how do you fetch the values from two columns using values from one column(get values from col.A if col.A is not null and get values from col.B if col.A is null)?

    Hi,
    Use NVL or COALESCE:
    NVL (col_a, col_b)
    Returns col_a if col_a is not NULL; otherwise, it returns col_b.
    Col_a and col_b must have similar (if not identical) datatypes; for example, if col_a is a DATE, then col_b can be another DATE or it can be a TIMESTAMP, but it can't be a VARCHAR2.
    For more about NVL and COALESCE, see the SQL Language manual: http://docs.oracle.com/cd/E11882_01/server.112/e26088/functions119.htm#sthref1310
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables involved, and also post the results you want from that data.
    Explain, using specific examples, how you get those results from that data.
    Always say which version of Oracle you're using (e.g., 11.2.0.2.0).
    See the forum FAQ: https://forums.oracle.com/message/9362002

  • How to get values from a table(in jsp) for validation using javascript.

    hi,
    this is praveen,pls tell me the procedure to get values from a table(in jsp) for validation using javascript.
    thank you in advance.

    Yes i did try the same ..
    BEGIN
    select PROD_tYPE into :P185_OFF_CITY from
    magcrm_setup where atype = 'CITY' ;
    :p185_OFF_CITY := 'XXX';
    insert into mtest values ('inside foolter');
    END;
    When i checked the mtest table it shos me the row inserted...
    inside foolter .. Now this means everything did get execute properly
    But still the vallue of off_city is null or emtpy...
    i check the filed and still its empty..
    while mtest had those records..seems like some process is cleaining the values...but cant see such process...
    a bit confused..here..I tried on Load after footer...
    tried chaning the squence number of process ..but still it doesnt help
    some how the session variables gets changed...and it is changed to empty
    Edited by: pauljohny on Jan 3, 2012 2:01 AM
    Edited by: pauljohny on Jan 3, 2012 2:03 AM

  • Help: cant get values from a resultset

    i have a class that contains all my MySQL statement and i am trying to use the results found from one of my select statements to pass on into another class which displays the results in a gui form. Here is my query:
    public void profile(String user)
            try
                 Class.forName(driver);
                 Connection con = DriverManager.getConnection( url,db_user, db_pass);
                 String username, name, email, dob, bio, gender, homepage, number;
                 //find username and select all details
                 String find = "SELECT Username, Full_name, Email, dob, Biography, Gender, Homepage, Contact_number FROM users WHERE Username = ? ";
                 PreparedStatement ps1 = con.prepareStatement(find);
                 ps1.setString(1, user);
                ResultSet rs = ps1.executeQuery();
                while(rs.next())
                    //retreive information from the server
                    username = rs.getString(1);
                    name  = rs.getString(2);
                    email  = rs.getString(3);
                    dob = rs.getString(4);
                    bio = rs.getString(5);
                    gender = rs.getString(6);
                    homepage = rs.getString(7);
                    number = rs.getString(8);
                    User_Profile profile = new User_Profile(username, name, email, dob, bio, gender, homepage, number);
                    JOptionPane.showMessageDialog(null, username + bio + email, null, JOptionPane.ERROR_MESSAGE);
                  con.close();
            catch( Exception e )
                     e.printStackTrace();
                     JOptionPane.showMessageDialog(null, "error," + e.getMessage(), null, JOptionPane.ERROR_MESSAGE);
        }As you can see, i am trying to pass on the variables username, name, etc to a new instance of my user_profile class but it doesnt for some reason. i dont get any comple errors so thats ok. i created messege dialog box from within the while statement above to see if a value is stored, and yes their is a value stored in my variables
    below is the user profile class which shows my constructor that suppose to get the values from the query class in this code entered above       User_Profile profile = new User_Profile(username, name, email, dob, bio, gender, homepage, number);
        protected String username;
        protected String FullName;
        protected String Email;
        protected String DOB;
        protected String Biography;
        protected String Gender;
        protected String Homepage;
        protected String Con_Number;
        protected String crnt_user;
    public User_Profile(String user, String name, String email, String dob,
                                String bio, String gender, String homepage, String number)
            initComponents();
            addWindowListener( this );
            //get values from sql query and store them here.
            this.username = user;
            this.FullName = name;
            this.Email = email;
            this.DOB = dob;
            this.Biography = bio;
            this.Gender = gender;
            this.Homepage = homepage;
            this.Con_Number = number;
         }the code below is used to display one of the values received from the query class, in this case returns null..
    txt_name.setText(username)

    Does the user String match the database String
    exactly?
    Some databases are case sensative.Sorry posted before done.
    Also, ensure you do not have trailing spaces in one or both. I remember Oracle had this problem a few years ago using the Type 4 driver but not through ODBC.

  • How to retrieve the values from PL/SQL table types.

    Hi Every one,
    I have the following procedure:
    DECLARE
    TYPE t1 IS TABLE OF emp%ROWTYPE
    INDEX BY BINARY_INTEGER;
    t t1;
    BEGIN
    SELECT *
    BULK COLLECT INTO t
    FROM emp;
    END;
    This procedure works perfectly fine to store the rows of employee in a table type. I am not able to retrieve the values from Pl/SQL table and display it using dbms_output.put_line command.
    Can anybody help me please!!!!!
    Thanks
    Ahmed.

    You mean, you can't add this
    for i in t.first..t.last loop
    dbms_output.put_line(t(i).empno||' '||t(i).ename||' '||t(i).job);
    end loop;or you can't add this
    set serveroutput onor maybe, you are working in third party application where dbms_output is not applicable at all?
    You see, not able like very similar it is not working - both are too vague...
    Best regards
    Maxim

Maybe you are looking for

  • Upgrade Power Mac G5 Hard Drive: But New Drive Doesn't show up??

    Hello, I have a Power Mac G5 1.8 (circa 2003).  I bought it in 2003 and it has travelled all over the world with me. I love it.  It has been the best and most reliable computer I ever owned; and I'm trying to keep it humming along as long as possible

  • Scroll bar works only occasionally

    My scroll bar is very undependable. Sometimes it works (moves), but more often it doesn't. I can usually get it to move after enough time and effort have been expended, but that's  not the way it's supposed to work. I might add that I am frequently s

  • A working Browser for clam os 8.3?

    I have an old Apple G3 Clamshell  ibook os 8.3.  with an airport card.  The Browsers Internet explorer and netscape no longer work on it.  Any one know any other old donkeys browsers  that might give me internet acces in a minimal kind of way -  idea

  • QuickTime won't close.

    QuickTime Player does not close after all windows of the app are closed and the app disapears from the dock. If I try to delete the movie I was watching it says that the file is being used and then I always have to force quit QT from the finder. Usin

  • Required the HP Scanjet 8250

    We need support in getting our HP scanners working optimally. we have the HP Scanjet 8250 which was working on windows XP we migrated to window 7. We required the HP Photosmart Essential and HP Solution Center software for this scanner. Please help m