Running PL/SQL scripts...

Hello:

I'm new to PL/SQL and am learning by writing that a few basic Queries.I using TOAD as a tool to write queries I got stuck in this query I posted below.

Here I have a table with data.

EMPLOYEE_ID SALARY BONUS

----------- ---------- ----------

90-1000

100 2000

110 1890

130 2132

120 1255

I wrote a query which take the value from the table (of particular employee_id) salary and multi with 0.01 and once again will store in the variable bonus (so far everything works fine).

but when I execute the script with the function to update its time consuming process (ends without result).

DECLARE

bonus NUMBER (8.2);

emp_id NUMBER (6): = 100;

BEGIN

SELECT salary * 0.10 IN bonus

Employees

WHERE employee_id = emp_id;

dbms_output.put_line (bonus);

update set employees.bonus = bonus employees where employee_id = emp_id;

END;

I tried the same thing through the sql-plus tool.


I stored the file above in note ++ (.sql extension) and through sql-plus I tried to run

SQL > @[path] [file]


but this does not work please help me in this. Please help me solve both ways...



See you soon...

It shouldn't take long at all.

SQL > create table emp2 in select * from emp;

Table created.

SQL > ed c:\give_bonus.sql

In my case, I have...

>
declare
number of bonuses;
emp_id number: = 7788;
Start
Select sal * 1.1
as a bonus
from emp2
where empno = emp_id;

dbms_output.put_line ('Sal with bonus: ' | bonus);

Update emp2
Sal value = give_bonus.bonus
where empno = emp_id;

commit;
end;
/

And then again in SQL * more I call it...

SQL > set timing on
SQL > @c:\give_bonus.sql
SAL with bonus: 3300

PL/SQL procedure successfully completed.

Elapsed time: 00:00:00.03

Very fast.

Perhaps you lack the ' / ' the end of your script that tells SQL * Plus to run the code?  And he's sitting there waiting for input?

Tags: Database

Similar Questions

  • I choose the computer name of the machine running a SQL script

    Hello. I am looking for a way to select the computer name of the machine running a SQL script. Is this possible?

    I tried the following, but it does not work. Any suggestions?

    Select % computername % of double;

    http://www.Oracle.com/technology/oramag/code/tips2003/011903.html

    Check this link see if it helps.

    Concerning

    REDA

  • Compensation of the sequences, run the sql script

    Hello

    I use OWB 10.1.0.4.0 and I use a sequence to create a surrogate key in my paintings. For the tabels deleted during the process, I want these sequences set to 1 again.

    Is it possible to run an sql script in a mapping or the flow of process (with a drop, create, grant the declaration for the sequence)?

    Thanks in advance,

    Arjan

    Write these SQL statements in a procedure and the procedure in the import map.

  • How to view and current directory to run an SQL script

    Hello
    Questions about a few simple things in sql command line plusent, but they are really hard to find in the documentation:

    1. is there an easy way to set an environment variable changing a working directory where a script is running?
    2. How can I view path environment?

    Kind regards
    Valerie

    SQLPATH? Example:

    C:\>type \tmp\test.sql
    select 1 from dual;
    
    C:\>sqlplus test/test
    
    SQL*Plus: Release 10.2.0.1.0 - Production on Fri Aug 28 11:47:56 2009
    
    Copyright (c) 1982, 2005, Oracle.  All rights reserved.
    
    Connected to:
    Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production
    
    SQL> @test
    SP2-0310: unable to open file "test.sql"
    SQL> exit
    Disconnected from Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production
    
    C:\>set SQLPATH=c:\tmp
    
    C:\>sqlplus test/test
    
    SQL*Plus: Release 10.2.0.1.0 - Production on Fri Aug 28 11:48:19 2009
    
    Copyright (c) 1982, 2005, Oracle.  All rights reserved.
    
    Connected to:
    Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production
    
    SQL> @test
    
             1
    ----------
             1
    
    SQL>
    
  • can the run/run .sql script in another application?

    Hello..

    I have a problem to run my .sql script (for example: @c:\Users\test.sql) in my netbeans application. There is no problem when I want to run/run my sql query (for example: "select * from...").

    But when I want to run my script, no presentation of the result. my script content my query to export to the csv file.

    script: @c:\Users\test.sql

    in the script:

    coil c:\Users\test.csv;

    ' Select ' ' ' | LOT_NUMBER | « «, » » || DEVICENUMBER | « «, » » || DEVICENAME | « «, » » || STEP_NAME | « «, » » || INSERT_DATE | « «, » » || STATUS | « «, » » || DISPOSEDBY | « «, » » || ACCEPTBY | « «, » » || AVAILABLE | « «, » » || GENDISPOSITION | » » »

    of RF_LOT_ON_HOLD_LIST;

    spool off;

    Thank you.

    bunch

    Yes, we know what talking about your question.

    a .sql script is just a plain text file containing everything you want.  The code in it can be a pure SQL statements, it may contain of the PL/SQL code, and it can also include SQL * more specific orders (keep in mind SQL * more is a tool, not a language, so that these commands are specific to this tool and other tools which can also interpret the same commands).

    Not quite sure how your question relates to this blog, as this blog is showing the code that gets the data in JSON format in a jqGrid (jQuery grid?) and then exports the data in an Excel file.

    What you're trying to do is to take a series of SQL * Plus and SQL statements in a text file and generate a CSV file from them.

    As already mentioned, SPOOL is a SQL * more order, specific to SQL * more command line tool.  The database itself has no idea what "spool" means, while passing to the database somehow does not work.  I also doubt that netbeans knows what that means, either.

    So, in short, how you try to do, not you cannot.

  • How to format the output of a .sql script that has select statements.

    Hello

    I have a .sql script which is having several select statements. Each Select statement is to have hundreds of Table columns.

    When we run the .sql script, we are unable to read the output.

    Please let know us the commands that we include for better readable output format.

    You work with the lin standard set 80.
    Increase this setting to set lin 3000 or more.

  • executing sql script in ApplicationModule before processing a request

    Hello

    I have an obligation to run a sql script, just after the application module is read to process the request and before it actually processes the request.
    Basically, I View object in the AM based on a guaranteed table, that script allows the user to access the data in the table.

    Is there a particular method in ApplicationModuleImpl that I can replace to add the execution of the script. Or is there another way to do it.

    Thank you
    Anil

    Just replace prepareSession, it is executed each time an appmodule is associated with a user session. If you have just run the code on a specific VO, simply substitute the method executeQuery or executeQueryForCollection (in the VOImpl).

  • End of table SQL script

    I have a sql script, someone else wrote, and there a lot of create table scripts. Some end with a semicolon and a goal with a slash /. What is the difference?
    I need to clean up the code and didn't know what I should take all scripting of table. Can I use the semicolon after the last)?

    I have to run multiple SQL scripts more eventually, so I want to make sure I have the correct syntax.

    Thank you

    for sqlplus no difference between the slash (/) and semicolon (;)
    but the slight difference see http://www.orafaq.com/forum/t/163141/0/

  • How to break in a SQL script.

    I'm using Oracle 11 g. I run a sql script called Queries.sql. The script has a lot of create and insert. I want to put a few delays in the execution of the script (e.g. delays 5 seconds) for that I can watch the output because the script is run. How to do this?

    Hello

    EXEC  dbms_lock.sleep (5);
    

    goes into pause for 5 seconds. You don't have any EXECUTE privileges on dbms_lock; Otherwise, log in as SYS and grant them or ask your DBA to grant them for you.

    Another thing to do is the SQL * Plus command:

    ACCEPT  dmy  PROMPT "Press [Enter] to continue ..."
    

    who waits indefinitely as the user presses the key [Enter] before continuing.

    Published by: Frank Kulash, April 26, 2011 19:59

  • How to run multiple parallel sql scripts?

    I try to execute multiple sql scripts parallel to the short run of the process via sqlplus. Are there opportunities to do? LINUX ORACLE 5. XX

    I do it too via Scheduler, but now I need to do this via sqlplus or shell + sqlplus?

    How do I start using shell script several xterminals and ech session begins all the sql scripts?

    nohup./SQL1.sh &

    nohup./sql2.sh &

    nohup./SQL3.sh &

    The '&' causes the script1.sh to run in the background so that the command prompt is returned immediately.  This means that sql2.sh can start immediately and at the same time as sql1.sh.  It doesn't have to wait for sql1.sh.   This assumes that there are no dependencies between scripts!  This meets your need to run scripts in parallel.

    The nohup untie your shell script.  So, even if you disconnect, the script continues to run.  Without the nohup, if you were to close your session before the end of the scripts running, they would get fired.

    Hemant K Collette

  • Running SQL scripts on different databases

    Hello!

    At my work we have many databases on a server. I have to make a request so that users can run the application on a selected database SQL scripts.

    So my question may be separated into 2 sections:

    1 - is possible to let users SQL scripts run directly from the application?

    I think a database to create a page that displays the list of all the SQL scripts, that we want to use, and when you click on a specific script name in the list, it asks something like "Where the database you want to run the script?", and then, as confirmed by the user, it would show results running the script on a different page.

    is 2 - possible to let users choose what database to run these scripts?

    Any information would be helpful, I'm at the beginning of the project and am not sure at all about how to proceed, or if it is at all possible.

    Thank you!

    Fallen_Kaede wrote:

    Thanks for the quick response. I confirm that we are talking about databases on a server.

    The request is to "debug" to other databases. For example, be run scripts to the locks on the list, to show the different indexes on a table, etc. to help diagnose problems.

    It looks like the 'users' are DBA who should use OEM/Grid Control to do so.

    1 - is possible to let users SQL scripts run directly from the application?

    Lol the only way to run scripts in the APEX is the use of the SQL Scripts for SQL workshop component.

    The key word in your question is 'application '. SQL * more and Developer SQL are applications that allow users to run SQL scripts on the desktop. Scripts SQL is an APEX integrated application that allows developers to run SQL scripts on the web. However, there is no documented way supported for end users to run SQL scripts in a custom of APEX application that you created. Therefore, rethink your approach. Rather than create an application APEX runs scripts, you must convert the scripts in PL/SQL, APEX packages, pages, components and applications leverage features of the APEX and reports, graphics and interactivity (e.g. exploration links; timed refreshes etc.). This will give you a user experience improved, beyond what is possible using static SQL scripts.

    is 2 - possible to let users choose what database to run these scripts?

    The APEX applications would exist on an instance of the APEX in a database and access other databases using the database links (which can have a performance impact). It would be possible to create a LOV based on the view of the USER_DB_LINKS dictionary and use in a selection set to a global page list to provide a control to set the current context of the database. Region data sources will have to be generated dynamically in the packages of PL/SQL use the links from relevant database based on this value LOV.

  • Run the PL/SQL Script

    I am trying to run the following script from pl/sql with sql developer:


    declare

    Start
    Dbms_output.put_line ("'Hello world!");
    end;


    but I'm so: "anonymous block filled" and not the message expected...

    What can I do?

    Thank you!

    You need to activate the "DBMS output.

    One way to do, is "View/DBMS Output" and add new Dbms output tab by clicking on "+" more singing.

    And the re - run the script.

  • How to run SQL scripts using OWB process flows?

    Hello
    I have a few SQL Scripts. I run them using process flow OWB.

    Can I get a document or a link that helps me to achieve this?

    Thanks in advance,
    SriGP

    Hi SriGP,

    You can call SQLPLUS using the external process activity.

    Order: Give the full path of the SQLPLUS executable
    Script: specify what you want to do in SQLPLUS

    Thank you
    Fati

  • Where the SQL Scripts running after the installation of the ODAC for Oracle Client?

    I just installed ODAC for Oracle Client on a windows server that runs a database of sql server, allowing developers to connect to a web application to an Oracle/Unix database. The installation States to run SQL scripts, located in the $ORACLE_HOME\ASP.NET\SQL directory after installation. I don't know where to run them? On the ORACLE DB on the Unix server? If someone could let me know, I'd appreciate it. Thank you.

    You must run on the Oracle database server, but they are necessary only if you use Oracle for ASP.NET providers.

    If you just install the software, so you can use OLEDB with SQL Server linked server, for example, you don't need them. What do you need to run although if this is the case is the oramtsadmin.sql script that creates the objects used by the Oracle MTS Recovery Service (if you do not have these objects created on the database) that SQL Server uses a distributed transaction for Oracle connections I think.

    It will be useful,
    Greg

  • Update SQL script

    Hi friends,

    I started this thread yesterday, but for some reason that I'm not able to answer/continue on this old thread. Here are the details from the old thread

    I need help with a sql script to update sid_no_new column with values based on sid_no for about 6000 + records.

    Here is an example below...

    SQL > select * from test1;

    SID_NO SID_NO_NEW UNIT_NO

    --------------------         --------------------           --------------------

    2000                                                          unit1

    2000                                                          unit3

    2000                                                          unit4

    2002                                                          unit16

    4500                                                          unit22

    In the example above, there are 3 sid_no consecutive '2000'. Sid_no_new must be 2000_1, 2000_2, 2000_3, respectively.

    It should be like:

    SQL > select * from test1;

    SID_NO SID_NO_NEW UNIT_NO

    --------------------      --------------------           --------------------

    2000 2000_1 unit1

    2000 2000_2 unit3

    unit4 2000_3 2000

    2002 2002 unit16

    4500 4500 unit22

    I ran the script (thanks to the experts who have contributed to) below, it works very well for the above documents, but I get ORA-30926 error when I run on the table with 6000 records...

    Fusion IN test1 tgt USING

    (SELECT sid_no,

    sid_no_new,

    unit_no,

    Count (sid_no) over (partition BY sid_no) cnt,

    ROW_NUMBER() over (partition BY order of sid_no to unit_no) rn

    OF test1

    ) CBC ON(tgt.sid_no=src.sid_no AND tgt.unit_no=src.unit_no)

    WHEN matched THEN

    UPDATE SET Sid_no_new = CASE WHEN cnt > 1 THEN sid_no |' _'. RN ELSE sid_no END;

    ERROR on line 1:

    ORA-30926: failed to get a stable set of rows in the source tables

    Please give your suggestions... Thank you very much

    In fact, this could be done easier:

    SQL > select *.

    test1 2

    3.

    SID_ SID_NO UNIT_N

    ---- ------ ------

    2000 2000_1 unit1

    2000 2000_2 unit3

    unit4 2000_3 2000

    2002 2002 unit16

    4500 4500 unit22

    SQL > select *.

    2 of test4

    3.

    UID_NO TYP RULE_DUE

    ---------- --- ----------

    RAF 2000 90

    3140 TH 100

    6712 JUL 21

    233 12 H6

    SQL > fusion

    2 in d of test4

    3 use)

    4 with as t4)

    5. Select uid_no,

    6                               type,

    7                               rule_due,

    8 rowid RID,

      9                               uid_no || '_' || ROW_NUMBER() over (partition by uid_no by 1 order) sid_no_new

    10 of test4

    11                      )

    12. Select t1.sid_no_new,

    T4.type 13,

    T4.rule_due 14,

    15 cases

    16 when t1.sid_no = t1.sid_no_new then t4.rid

    17 when t4.sid_no_new = t1.sid_no_new then t4.rid

    18 end rid

    19 of t4,

    Test1 20 t1

    21 where t1.sid_no = t4.uid_no

    22          ) s

    23 on)

    24 d.rowid = s.rid

    25       )

    26 when matched

    27 then

    Update 28

    29 set d.uid_no = s.sid_no_new

    30 when no match

    31 then

    32 insert

    33 values)

    s.sid_no_new 34,

    s.type 35,

    36 s.rule_due

    37                )

    38.

    3 lines merged.

    SQL > select *.

    2 of test4

    3.

    UID_NO TYP RULE_DUE

    ---------- --- ----------

    2000_1 RAF 90

    3140 TH 100

    6712 JUL 21

    233 12 H6

    2000_3 RAF 90

    2000_2 RAF 90

    6 selected lines.

    SQL >

    SY.

Maybe you are looking for

  • When you open a new tab, placing default text in the address bar, a way to change to the new page (like Google)?

    When I click on the 'plus' for a new tab, which automatically takes me to google.com so beautiful, but the cursor is in the address bar. It seems that the cursor is in the google search box, but it's not. When I click on "Home" the default cursor, th

  • Air the fan runs all the time help please

    Hello my air fan macbookbook just Can not stop, its rotation at high speed that I can't use my laptop comfortably I tried to reset the SMC, but did not work it runs fast even before the charging system I've included screenshots of istat cpu and senso

  • failure to display screen

    I have the g2 bike dual sim in India. Recently updated East of the lollipop.Since then, the phone has become very slow and observed a new problem. Whenever I double tap the homescreen it suddenly zoomed in and comes from an orange outline. I have to

  • Lack of available disk space; does not recognize that I have deleted files

    Today I found out, I had 2 GB left on my hard drive 150 GB (Windows XP Home edition, HP mini, purchased mid-2010).  I deleted about 20 GB of different files is no longer needed.  The properties of my C drive still say it be only 2 GB of free space, a

  • OfficeJet 4500: Solution Center

    Sinds last update windows 10 wil het Solution Center van op geen some wijze openen, reeds opnieuw geinstalleerd maar dat van geen Holland. Weet iemand wel Holland?