Executing SQLPLUS command from Stored Procedure

Hi,
I am trying to execute the SQLPLUS command (CONNECT) from the stored procedure.
It is throwing below error message.
Stored Procedure:
SQL> select user from dual
2 ;
USER
SYS
SQL> create or replace
2 PROCEDURE PROCEDURE1 AS
3 BEGIN
4 sqlplus sys/sys@D as sysdba;
5 --execute immediate 'create user 'kkk' identified by 'kkk';
6 END PROCEDURE1;
7 /
Warning: Procedure created with compilation errors.
SQL> show err
Errors for PROCEDURE PROCEDURE1:
LINE/COL ERROR
3/9 PLS-00103: Encountered the symbol "SYS" when expecting one of the
following:
:= . ( @ % ;
The symbol ":=" was substituted for "SYS" to continue.
3/22 PLS-00103: Encountered the symbol "AS" when expecting one of the
following:
. ( * @ & = - + ; < / > at in is mod remainder not rem
<an exponent (**)> <> or != or ~= >= <= <> and or like LIKE2_
LIKE4_ LIKEC_ between || member SUBMULTISET_
The symbol ". was inserted before "AS" to continue.
Please let me know whether it is possible to do or not.
If there is possiblility how can does this be done?
Edited by: NGK246 on Aug 28, 2012 2:21 AM

NGK246 wrote:
Hi,
I am trying to execute the SQLPLUS command (CONNECT) from the stored procedure.
It is throwing below error message.
It would not. It will always throw an error. SQLPLUS is a Utility and not a Command/Construct, that it would be available for a Stored Procedure
>
SQL> select user from dual
2 ;
USER
SYSWhich Database are you onto? Is it DMIP?
SQL> create or replace
2 PROCEDURE PROCEDURE1 AS
3 BEGIN
4 sqlplus sys/sys@DMIP as sysdba;
5 --execute immediate 'create user 'kkk' identified by 'kkk';
6 END PROCEDURE1;
7 /
Warning: Procedure created with compilation errors.
SQL> show err
Errors for PROCEDURE PROCEDURE1:
LINE/COL ERROR
3/9 PLS-00103: Encountered the symbol "SYS" when expecting one of the
following:
:= . ( @ % ;
The symbol ":=" was substituted for "SYS" to continue.
3/22 PLS-00103: Encountered the symbol "AS" when expecting one of the
following:
. ( * @ & = - + ; < / > at in is mod remainder not rem
<an exponent (**)> <> or != or ~= >= <= <> and or like LIKE2_
LIKE4_ LIKEC_ between || member SUBMULTISET_
The symbol ". was inserted before "AS" to continue.
Please let me know whether it is possible to do or not.
If there is possiblility how can does this be done?If you are at DMIP, you need not Login again. You can Login Manually to the Database and Execute the Procedure (in which you intend to create a User 'kkk').
However, if you are trying to Create a User in a Different Database, You will first require a DB Link to exist to connect to the Remote Database. You will also require Explicit privileges to create any user (Although I am not sure if you can create User onto a different Database.)
I would like to ask you, why are you creating a User on a Remote database? Can you not execute the same procedure on the Remote database and create User? Also, you are using SYS login to perform the activity. Ideally it should not be allowed. You must create a user and grant DBA rights to perform such activities.

Similar Messages

  • Issue with Executing OS commands from Stored Procedure

    I am trying to execute the scripts provided at :
    http://github.com/xtender/XT_SHELL
    provided by xtender user.
    As required, I have asked my DBAs to grant privileges by executing the following scripts:
    Begin
      --change to needed permissions and execute
      dbms_java.grant_permission( 'ODS', 'SYS:java.io.FilePermission', '/var/factiva/ODS/bin/CVIM_Rpt_ExportCSVFile’, 'read,write,execute' );
    end;
    /where CVIM_Rpt_ExportCSVFile is my script residing in the Unix server where my Oracle is installed.
    The error I am facing when I try to execute the following command is:
    select * from table(xt_shell.shell_exec('/var/scripts/CVIM_Rpt_ExportCSVFile',100))
    Exception:the Permission (java.io.FilePermission /var/scripts/CVIM_Rpt_ExportCSVFile execute) has not been granted to ODS. The PL/SQL to grant this is dbms_java.grant_permission( 'ODS', 'SYS:java.io.FilePermission', '/var/scripts/CVIM_Rpt_ExportCSVFile', 'execute' )I have asked my DBA to also execute the following scripts: - But I still see the same error as above. I am not able to figure out whats going on. Can anyone pls help me out??
    EXEC Dbms_Java.Grant_Permission('ODS', 'SYS:java.lang.RuntimePermission', 'writeFileDescriptor', '');
    EXEC Dbms_Java.Grant_Permission(ODS', 'SYS:java.lang.RuntimePermission', 'readFileDescriptor', '');
    dbms_java.grant_permission( 'ODS', 'SYS:java.io.FilePermission', '/var/scripts/CVIM_Rpt_ExportCSVFile', 'execute' )

    DUPLICATE
    ===============================================================
    Issue with Executing OS commands from Stored Procedure
    ==============================================================

  • How to execute Operating System commands from Stored procedure.

    Any help on how to execute Operating System commands from stored procedures will be appreciated.
    Nanditha.

    Search the forums for 'External Procedure' and you will find example code that has been posted before.

  • How to execute unix command from ODI Procedure

    Hi,
    I am trying to execute below unix command from ODI Procedure (Command on Target tab) but I am getting the error "java.io.IOException: Cannot run program "cd": error=2, No such file or directory" but when I try to execute the same command using OdiOSCommand, it is executing successfully. I don't want to use shell script to execute this command. Is there any specific syntax am I missing to execute this command from ODI procedure?
    cd /project3/tmt/;ls *.dmp > dmplist.lst
    Please help me on this...
    Thanks
    MT

    Hi nahlikh,
    Thank you for the reply.
    I used below command in Procedure but still getting the same error as "java.io.IOException: Cannot run program "OdiOSCommand": error=2, No such file or directory".
    OdiOSCommand "-COMMAND=cd /project3/tmt/;ls *.dmp > dmplist.lst"
    as I mentioned earlier if I use the command cd /project3/tmt/;ls *.dmp > dmplist.lst in OdiOSCommand tool it is executing successfully without any issues.
    any thoughts appreciated to get a solution for this issue.
    Thanks
    MT

  • Problem with execute SSIS package from stored procedure

    Hi,
    I would like to execute SSIS package from stored procedure. Therefore, I implemented sp which exec SSISDB.CATALOG.CREATE_EXECUTION method. When I try to test it from SSMS on remote server, I got error that
    I was able to solve by adding “WITH EXECUTE AS …”. Then I got another error: The server principal "Domain\user" is not able to access the database "SSISDB" under the current security context. On Internet, I found a couple post that describe
    how to access SSIS catalog (one of them by Ke Yang -
    http://blogs.msdn.com/b/mattm/archive/2012/03/20/ssis-catalog-access-control-tips.aspx). It didn’t help. I’m still getting the error message.
    How to debug this issue?
    Any suggestion?
    Thanks
    SQL Server 2014 BI

    SSMS does not propagate user credentials thus the error
    Arthur
    MyBlog
    Twitter

  • Executing OS command from sql procedure

    i want to execute an OS command from the procedure, can i do this way? looks like it is not executing the command move....
    declare
    begin
    dbms_output.put_line(' moving...');
    host;
    move c:\file1\test.txt C:\moved
    exit;
    /

    True. But that job is going to run in a separate session, some time after the current transaction commits (depending on the number of jobs queued up to run). So if you need to pass information back from the job, or you want the procedure to handle exceptions thrown by the job, or you want to tie job related failures back to a particular application level event, or you want the rest of your procedure to wait for the operating system command to finish, using the DBMS_SCHEDULER for this sort of thing is going to require a fair amount of additional coordination/ monitoring/ infrastructure code. It's certainly not a Herculean task to write that additional code, and it's reasonable in some situations, but the Java stored procedure approach strikes me as substantially easier to deal with in most cases.
    Justin

  • Executing a Operating System command from Stored Procedure ??

    I want to execute a Operating System command from a PL/SQL Stored Procedure, can anyone suggest me how can I do this ??
    I am on Sun-Solaris with Oracle 8.1.7 database.
    Please do email me at [email protected]
    Thanks in Advance,
    Ramesh L.

    Are you using a webserver? If so, you could make your operating system script into a CGI program, then execute it from pl/sql using utl_http.request.

  • File Ownership while executing sql script from stored procedure

    We have a test_command.sql script which is spooling the result into a file. From database we have one Store Procedure(run_sql) which is
    calling and executing the .sql script.
    When we are calling the sql script directly from the database, i e SQL > @/dccops/test_command.sql it is creating the
    file under the Ownership of OS user which is connected to the system.
    The problem we are facing is when we are executing the stored procedure i e exec run_sql(), the file is creating under
    Oracle User.
    Could u please suggest me a solution inorder to create the output file under the user who is logged to the OS.

    First of all, your usage of IM speak is NOT appreciated. Please do not address anyone as if they were a 12-year old.
    'Our Applcation is in C. So we have to call the procedure to run the sql script.'
    This is just utter nonsense!
    Oracle has Pro*C which allows Embedded SQL in C. There is also OCI (Oracle Call Interface) to call Oracle directly in C, and there is OCCI, to do the same in C++.
    Apart from that, Oracle has Ole DB for Windows platforms, to allow for a .NET compatible interface to Oracle.
    There is NO NEED AT ALL to call PL/SQL to run a SQL script.
    Sybrand Bakker
    Senior Oracle DBA

  • Call unix commands from stored procedures

    My stored procedure requires to call unix commands HOW DO I DO IT?
    null

    i do not know pl sql but in java you can use:
    Runtime.getRuntime().exec("YOUR UNIX COMMAND");
    real example:
    Runtime.getRuntime().exec("ls");
    but you must be careful with using that...
    especially if you want to wait till the process finishes..
    rgds,

  • System command execution from stored procedure

    Hello World,
    How to run System command from stored procedure ?
    For example :
    Delete a file
    running a programm,
    Is it possible ?
    H.M

    Years ago I did this by writing an output file with commands into a directory and had a cron job looking for this file. At the end of the run the file was removed.
    Never checked if there are other possibilities nowadays.
    cu
    Andreas

  • Execute Unix Mail Command from Store Procedure

    Hi Colleagues!
    I designed a store procedure that Monitoring some Critical tables in my Oracle 8.0.6.1.0 Database But I need to send some Emails from the Store Procedures to Information System Staff when the amount of rows increase too much. I read about UTL_SMTP but my database version is too old to run this package. Also I have the option of Maildemo8i that execute MS Oulook from a Client System But I looking to Send it from my Database(OS HPUX). So please take a look of this issue and I will appreciate any help.
    Your Friend.
    Emmanuel Carrillo Trejos.
    LNB, Republic of Panama(Central America).
    P.D. You can email to: [email protected]

    Do you mean that you want to execute mail or mailx unix commands to send mails.If i am right then probably you are looking for a way to execute operating system commands from your procedure.
    You can refer this link if you want to do that. You need java support in your Oracle database and i believe that Oracle 8 does have jvm running in the instance.
    http://asktom.oracle.com/pls/ask/f?p=4950:8:5079825575573830264::NO::F4950_P8_DISPLAYID,F4950_P8_CRITERIA:952229840241
    Thank you!

  • PLEASE HELP! OLE DB COMMAND - capturing Stored Procedure output run from an OLE DB Command

    I've searched through the related posts but cannot find exactly what I'm looking for.
    I have an OLE DB Source that produces multiple rows (around 200) through a stored procedure. I need to take 3 values in each row and pass them to an OLE DB Command that runs another stored procedure for each row.
    What I need is to get the output of the second stored procedure. I've read posts regarding using lookup, merge join, derived column but I still don't understand exactly how to put it all together. My destination is an excel file. Once I've obtained this output,
    I believe I can figure out how to merge the OLE DB Source results and the OLE DB Command results into one table.  The output columns of the second SP are not available to be mapped to my destination file.
    I've also explored running an Execute SQL task and passing the rowset to a variable but don't know how to pass that variable into the next stored procedure and then capture the second stored procedure results.
    OLE DB Source contains Stored Procedure X:
    DECLARE @return_value int
    declare @newdate smalldatetime
    set @newdate = convert(smalldatetime,convert(varchar(10),getdate(),101))
    EXEC @return_value = [dbo].[getnumbers]
    @dtAfterDate = @newdate,
    @dtBeforeDate = '2099-12-31 5:00:00',
    @Status = 'Any'
    NEXT IN THE PIPELINE
    OLE DB Command contains Stored Procedure Y:
    EXEC [dbo].[getaddress] ?,?,?
    One more thing, CREATING A TEMP TABLE ISN'T AN OPTION!
    Thanks!

    Thanks again for your help David!  Let me rephrase.  I'm working a server that doesn't need to be altered in anyway by me.  I just need to pull the data to my server so I can use it as needed.  I can't build any links either.  The
    only other option I'd have would be coding SQL code with some sort of cursor similar to.
    EXEC
    @return_value = [dbo].[getnumbers]
    @dtAfterDate = @newdate,
    @dtBeforeDate = '2099-12-31 5:00:00',
    @Status = 'Any'
    For every number in the resulting table:
    EXEC
    [dbo].[getaddress] something1, something2, something 3

  • How to generate a report from stored procedure

    I would like to generate a report from stored procedure.
    I used to work on sql server. this can be done as easy as put a select statement at the end of stored procedure.
    The resule can be displayed on the development IDE, like sql developer or consume by Java JDBC client.
    is there equivalent way to do this in Oracle stored procedure?

    Hi,
    What type of report you are looking..for.. ??
    As you said that "I used to work on sql server. this can be done as easy as put a select statement at the end of stored procedure. "
    When you execute it will return the result set and you will display directly on the FrontEnd.. Is my Understanding is correct Up to here.
    See, In oracle you have call some custom stored procedures as you did in SQL Sever, but you have return the Results Sets, with help of Out put paramter, Either Cursors or Varrays..
    or Else you can generate the Html reports based on your requirement, HTML can be used in the stored procedures of Oracle which will generate for your, you need to code it.
    I could not able get the relevant link for your reference.
    I will get back to you on this.
    - Pavan Kumar N

  • How to execute .sql file in Stored Procedure?

    Hi,
    I have an urgent requirement, where i have to execute .sql file form Stored Procedure.
    This .sql file will have set of update statement. I need to pass value to this update statement.
    Kindly please help me.
    Regards,
    Irfan

    This is required as part of Data Migration where  i have to do 100 of table's update. Each time update table will defer, so its better to have in separate script file (.sql). Can u paste some sample/syntax to exceute .sql file from stored procedure. I am new to this PL/SQL.
    How have you determined that it's "better" to have seperate scripts?  I assume you mean the table name will "differ" (and not "defer" - I assume that's just because English isn't your first language? no problem - I think I understand what you're asking).
    So what I think you're asking is that you have dynamic table names but each table needs to be updated in the same way?
    Question: Why do you have tables with different names that all need the same process doing to them?
    Assuming it's a valid requirement (and 99% of the time doing dynamic coding implies it's not).... you could use dynamic code, rather than 'scripts'...
    e.g.
    create procedure update_table(tbl_name varchar2) is
    begin
      execute immediate 'update '||tbl_name||' set lastupdate = null';
    end;
    As you haven't bothered to provide a database version, any example code/data or explanation of what you're actually doing, you're not going to get any detailed answer.  Please do take the time to read the FAQ and post appropriate details so people can help you.

  • Can I execute a scenario from a procedure?

    Can I execute a scenario from a procedure? I know I can execute scenarios from the command line. I was hoping to avoid that since I need my job to run in multiple envirnoments and may not reliably know where STARTSCEN is located or if it will always work. Basically, I would like to execute several jobs multiple times, depending on values in a table that will be changed between runs.

    Hi,
    Yes you can exetute an ODI scenario from an ODI procedure.
    Technology for that procedure will be Sunopsis API
    code OdiStartScen "-SCEN_NAME=<scenario name>" " -SCEN_VERSION=<scenario version>" "-CONTEXT=<context code name>"
    Thanks,
    Sutirtha

Maybe you are looking for