Write a pl/sql block

Hi Everyone,
I have three tables. Student table, bookDetails table and bookIssue records table.
This is my question
Write a pl/sql block to display like
Title01 has taken by zero students.
Title02 has taken by ten students.
Title03 has taken by five students.
Oracle Database 10g Express Edition Release 10.2.0.1.0 - Product
PL/SQL Release 10.2.0.1.0 - Production
CORE 10.2.0.1.0 Production
TNS for 32-bit Windows: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production
Thank you,
    Bala

1011271 wrote:
Hi Everyone,
I have three tables. Student table, bookDetails table and bookIssue records table.
This is my question
Write a pl/sql block to display like
Title01 has taken by zero students.
Title02 has taken by ten students.
Title03 has taken by five students.
Oracle Database 10g Express Edition Release 10.2.0.1.0 - Product
PL/SQL Release 10.2.0.1.0 - Production
CORE 10.2.0.1.0 Production
TNS for 32-bit Windows: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production
Thank you,
    Bala
begin
dbms_output.put_line('Title01 has taken by zero students.');
dbms_output.put_line('Title02 has taken by ten students.');
dbms_output.put_line('Title03 has taken by five students.');
end;
I have now officially put as much effort in to answering the question as you did in asking it.
How productive has this been? Please take some time and provide ALL the information you have and EXACTLY what you need.
Cheers,

Similar Messages

  • Conditional SQL ( Want to avoid having to write a PL/SQL block )

    I have a SQL statement and I was hoping to not have to write an IF-THEN-ELSE condition. Here is the SQL in hand which I need to expand.
    I need to list the personal information including address of all the employees. However, in the event that I encounter any address ( Home or Office ) where my State is *"NY"*, I should not list the "NY" Address but instead list the address where my address_location = 'O' and address_state_code = *"CA"*.
    Here is my code below. Now, the DB procedure call could retrieve the latest address id as a "NY" location and hence my question.
    SELECT '"'||emp.employee_name,
                  ||'","'||TO_CHAR(emp.birth_date,'YYYY/MM/DD')
                  ||'","'||emp.gender
                  ||'","'||RTRIM(ead.address_line1)
                  ||'","'||RTRIM(ead.address_line2)
                  ||'","'||RTRIM(ead.address_line3)
                  ||'","'||RTRIM(ead.address_location) -- 'O': Office; 'H': Home
                  ||'","'||RTRIM(ead.adh_city)
                  ||'","'||ead.address_zip_code
                  ||'","'||ead.address_state_code
    FROM    employee             emp,
                employee_address ead
    WHERE  emp.emp_num = ead.emp_num
    -- The proccedure db_get_address_id returns me the most recent Address with Max Effective Date
    AND      ead.address_id = db_get_address_id( emp.emp_num )
    ORDER BY v.effective_date DESC, emp.employee_name ASC;
    {code}
    Thanks in advance !                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    SELECT  emp_address
      FROM  (
             SELECT  '"'||emp.employee_name,
                            ||'","'||TO_CHAR(emp.birth_date,'YYYY/MM/DD')
                            ||'","'||emp.gender
                            ||'","'||RTRIM(ead.address_line1)
                            ||'","'||RTRIM(ead.address_line2)
                            ||'","'||RTRIM(ead.address_line3)
                            ||'","'||RTRIM(ead.address_location) -- 'O': Office; 'H': Home
                            ||'","'||RTRIM(ead.adh_city)
                            ||'","'||ead.address_zip_code
                            ||'","'||ead.address_state_code emp_address,
                            ROW_NUMBER() OVER(ORDER BY v.effective_date DESC, emp.employee_name ASC) RN,
                            CASE
                              WHEN ead.address_state_code = 'NY' THEN CASE MAX(
                                                                               CASE ead.address_state_code
                                                                                 WHEN 'CA' THEN 1
                                                                               END
                                                                              ) OVER(PARTITION BY emp.emp_num)
                                                                        WHEN 1 THEN 0
                                                                        ELSE 1
                                                                      END
                              ELSE 1
                            END TAKE_IT -- 0 means it is NY address for employee who also has CA address, 1 otherwise.
               FROM  employee emp,
                     employee_address ead
               WHERE emp.emp_num = ead.emp_num
                 -- The proccedure db_get_address_id returns me the most recent Address with Max Effective Date
                 AND ead.address_id = db_get_address_id(emp.emp_num)
      WHERE TAKE_IT = 1
      ORDER BY RN
    {code}
    SY.
    Edited by: Solomon Yakobson on Aug 13, 2009 1:38 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Help in solving this pl/sql block

    Hi
    Could some one help me in solving my problem
    i want some data to be extracted by a sql its not fetching it so i prefered to write a pl/sql block for it ...
    the block is as follows
    begin
    cursor opunit is
    select code from fmg_operating_units;
    cursor pak_code is --- those are the 3 codes which i require
    select 'BNL' from dual
    union select 'HNA' from dual
    union select 'HNL' from dual;
    cursor data1(opunit,pak_code) is
    select mas.name ,
    cl.id ,
    opup.oun_code ,
    fmg_phone_no(mas.id),
    clpk.pak_code ,
    clpk.id
    from fmg_op_unit_positions opup,
    fmg_clients cl,
    fmg_client_paks clpk,
    fmg_masters mas,
    fmg_policies po,
    fmg_policy_items pi
    where mas.id=cl.mas_id
    and cl.id=clpk.cli_id
    and clpk.oup_id=opup.id
    and opup.oun_code = opunit
    and clpk.id=po.ctp_id
    and po.id=pi.pol_id
    and pi.current_status='AC'
    and clpk.pak_code = pak_code;
    loop opunits
    loop pak_code
    open data1
    fetch data1(opunit,pak_code) ;
    end loop;
    end loop;
    could some one help me in extracting the data and put it on the CSV file ...
    i would be very thank full to you if some one take some time to full fill this task..
    thanks in advance

    Declare
         cursor opunit is
              select distinct code
              from fmg_operating_units;
         cursor pak_code is --- those are the 3 codes which i require
              select 'BNL' codes from dual
              union
              select 'HNA' codes from dual
              union
              select 'HNL' codes from dual;
         cursor data1(opunit,pak_code) is
              select mas.name ,
                   cl.id ,
                   opup.oun_code ,
                   fmg_phone_no(mas.id),
                   clpk.pak_code ,
                   clpk.id
              from fmg_op_unit_positions opup,
              fmg_clients cl,
                   fmg_client_paks clpk,
                   fmg_masters mas,
                   fmg_policies po,
                   fmg_policy_items pi
              where mas.id     =     cl.mas_id
              and cl.id     =     clpk.cli_id
              and clpk.oup_id =     opup.id
              and opup.oun_code =      opunit
              and clpk.id     =     po.ctp_id
              and po.id     =     pi.pol_id
              and pi.current_status=     'AC'
              and clpk.pak_code =      pak_code;
    begin
         FOR opunits IN opunit LOOP
              FOR pak_codes IN pak_code LOOP
                   OPEN data1;     
                        fetch data1(opunits.code,pak_codes.codes) ;
                        EXIT WHEN data1%NOTFOUND;
                        < Rest of your code here > -- You can insert processed data into a temp table &
                                       -- extract data from that table afterwards via select statement
                                       -- & saving the data in a .cvs file extension.
                   CLOSE data1;
              END LOOP;
         END LOOP;
         <Some more code here if applicable>
    EXCEPTION
         <Exception handling code section here>
    END;

  • PL/SQL block to populate a table

    Hello Gurus,
    Need help to write a pl/sql block as per below:
    1. Write a PL/SQL block which will populate the RESULTS table as described below. Consider performance implications (specifically where would you commit the queries) as we are dealing with millions of records.
    The PL/SQL will:
    - insert into the RESULTS table each customer id, and the number of unique products purchased by that customer.
    - update the recently_purchased column of the customer table to 'Y' (yes if they have purchased a product in the last 12 months) or 'N' (if they have not purchased a product in the last 12 months).
    Listed below are the tables & definitions:
    table: CUSTOMER
    columns:
    customer_id NUMBER,
    customer_name VARCHAR2(100),
    recently_purchased VARCHAR2(1) -- 'Y' or 'N'
    table: CUST_PRODUCTS
    columns:
    product_id NUMBER,
    customer_id NUMBER,
    date_purchased DATE
    table: RESULTS
    columns: customer_id NUMBER, product_count NUMBER
    Thanks a lot..

    Hi Guys,
    I've tried this to my best but I feel like something's definately wrong with my update statement.
    Please help..
    --create customer table
    create table customer (
    customer_id number(6),
    customer_name varchar2(100),
    recently_purchased varchar2(1));
    -- describe to see if it is created as required
    desc customer
    --populate customer table with random values
    Begin
    For i in 1..20
    Loop
    Insert into customer(customer_id,customer_name,recently_purchased)
    values(i, dbms_random.string('U',5),'N');
    If mod(i, 100000) = 0 then
    Commit;
    End if;
    End loop;
    End;
    --create cust_products table
    create table cust_products
    (product_id number (6),
    customer_id number(6),
    date_purchased date);
    --describe to see if table is created as required
    desc cust_products
    --populate cust_products with custome_id 1 to 10 and dates
    Begin
    For i in 1..20
    Loop
    Insert into cust_products
    values(dbms_random.value(555,999),i,add_months('04-Nov-08',i));
    If mod(i, 100000) = 0 then
    Commit;
    End if;
    End loop;
    End;
    select * from cust_products
    --update customer table as required
    Begin
    For i in 1..10
    Loop
    update customer set recently_purchased = 'Y';
    commit;
    update customer C set recently_purchased = 'N' where exists (select date_purchased from cust_products P where C.customer_id = P.customer_id );
    commit;
    End loop;
    End;
    --Insert into results table
    select customer_id,count(product_id)
    from cust_products
    group by customer_id
    Edited by: user497841 on Feb 4, 2010 2:12 PM

  • Write an UPdate statement using the logic used in PL/SQL block (oracle 10g)

    Hi All,
    I have written the following PL/SQL block. I want to write an UPDATE statement using the logic used in the following PL/SQL block. can any one please help me out in this regards.
    DECLARE
       v_hoov_fag   gor_gold_post.hoov_flg%TYPE;
       v_b49n          gor_gold_post.b49n%TYPE;
       CURSOR c
       IS
          SELECT bs_id, loyalty_date, loyalty_period, contract_date
            FROM gor_gold_post
           WHERE tariff_code IN (169, 135, 136);
    BEGIN
       FOR rec IN c
       LOOP
          IF    (TRUNC (ADD_MONTHS (rec.loyalty_date, rec.loyalty_period)
                        - SYSDATE) < 304
             OR (    TRUNC (  ADD_MONTHS (rec.loyalty_date, rec.loyalty_period)
                            - SYSDATE
                           ) IS NULL
                 AND (SYSDATE - TO_DATE (rec.contract_date, 'YYYYMMDD')) > 91.2
          THEN
             v_hoov_flg := 1;
          ELSE
             v_hoover_flag := 99;
          END IF;
          IF    (TRUNC (ADD_MONTHS (rec.loyalty_date, rec.loyalty_period)
                        - SYSDATE) < 121.6
             OR (    TRUNC (  ADD_MONTHS (rec.loyalty_date, rec.loyalty_period)
                            - SYSDATE
                           ) IS NULL
                 AND (SYSDATE - TO_DATE (rec.contract_date, 'YYYYMMDD')) > 91.2
          THEN
             v_b49n := 1;
          ELSE
             v_b49n := 99;
          END IF;
          UPDATE gor_gold_post
             SET hoov_flg = v_hoov_flg,
                 b49n = v_b49n
           WHERE bs_id = rec.bs_id AND tariff_code IN (169, 135, 136);
          COMMIT;
       END LOOP;
    END;Thank you,

    Using case statement.
    UPDATE gor_gold_post
       SET hoov_flag = CASE WHEN TRUNC (ADD_MONTHS (rec.loyalty_date, rec.loyalty_period) - SYSDATE) < 304
                                   OR
                                   (TRUNC (ADD_MONTHS (rec.loyalty_date, rec.loyalty_period) - SYSDATE) IS NULL
                                AND (SYSDATE - TO_DATE (rec.contract_date, 'YYYYMMDD')) > 91.2)
                           THEN 1
                           ELSE 99
                         END,
           b49n      = CASE WHEN TRUNC (ADD_MONTHS (rec.loyalty_date, rec.loyalty_period) - SYSDATE) < 121.6
                             OR
                             (TRUNC (ADD_MONTHS (rec.loyalty_date, rec.loyalty_period) - SYSDATE) IS NULL
                                AND (SYSDATE - TO_DATE (rec.contract_date, 'YYYYMMDD')) > 91.2)
                           THEN 1
                           ELSE 99
                         END
    WHERE tariff_code IN (169, 135, 136);Note: Code not tested.

  • Q: how can i write PL/SQL block to check prerequisite?

    Hello...
    I designed an application using sql*plus statment for creating database and developer for creating forms, for on-line registration system for universties,
    so I need to teach me how can I write pl/sql block to check the prerequisite, taken courses, and complete hours for the students who wants register the courses via Internet.
    thanks alot in advance
    kindly send the answers a.s.a.p

    please repost this in the SQL & PL/SQL forum
    thanks - OTN

  • Performance: Operations in Cursor vs. Operations in PL/SQL block

    Why does I have a better performance when I program operations in complex cursors instead of programming the same statement in a pl/sql block in a stored procedure?
    Operation in a Cursor:
    CURSOR c IS
      DECODE(name,'Peter','dog','cat') animal
      ...The same Operation in a PL/SQL block:
    begin
      if name = 'Peter'
      then
          animal = 'dog';
      else
          animal = 'cat';
      end if;
    end;
    ...I know that a parsed cursor is placed in the Shared Pool and reference
    a context area in the PGA.
    Does anybody have an idea?
    Message was edited by:
    mad

    Maybe because if you can write only a SQL query, it is faster than to write PL/SQL code that will do the same job. See following thread for a analog discussion: Re: pl/sql table

  • Creating a PL/SQL-Block with Boolean-Return and Check

    Hello folks,
    I have some kind of tricky problem. Actually, I want to integrate a small Task-System on my Apex 2.2 installation. Every task is intended to have a field with a anonymous PL/SQL-block in the shape of:
    Declare
    Begin
    return true/false;
    End;
    It is comparable to the condition-PL/SQL-block you can set for almost ev'ry item.
    It's not the problem to write this block half-automated, but how do I check it? Is there any kind of Database-Function?
    Thanks for your replies.
    Matthias.

    I believe Struct is basically used for SQL types , and your 'T_NACHRICHT' is a type of Objects so please pass the objects array to STRUCT.
    For example if type is :
    CREATE OR REPLACE TYPE T_NACHRICHT AS OBJECT
    ID_Nachricht NUMBER,
    ID_Vorgang NUMBER,
    --datum                 TIMESTAMP(6),
    Betreff VARCHAR2(400),
    -- Nachricht CLOB,
    ID_Antwort NUMBER,
    ist_neu VARCHAR2(5),
    CONSTRUCTOR FUNCTION T_NACHRICHT(
    p_ID_Vorgang NUMBER,
    p_Betreff VARCHAR2) RETURN SELF AS RESULT
    then call the struct in below way:
    STRUCT nachrichtSTRUCT = null;
    StructDescriptor structDesc = StructDescriptor.createDescriptor("T_NACHRICHT", conn);
              Object [] obj = {123456,123456,"ABC",123456,"ABCD"};
    nachrichtSTRUCT = new STRUCT(structDesc, conn, obj);

  • PL/SQL Block for Data Formatting

    I have created a Report that will pull all times that a person clocks in and clocks out. It works great but now accounting wants me to do some "conditional formatting" that can't be done by Report's built in conditional formatting capabilities. I talked to tech support yesterday and they suggested a PL/SQL block to format my times to do what accounting needs. Here is the skinny: All times in the database are done in 100ths of an hour. I need to the times up or down to the next quarter hour depending on when they clocked in. If they clocked in one minute late, it rounds down the the previous quarter hour and anything later and it rounds up. Can someone help me? Thanks, Jeremy

    In the data model, enter your query and create the groups you need.
    Let's say you have the number column my_time in a group named g_times.
    Then create a formula column in the group g_times and look at its
    properties. Change the name to cf_time.
    Click on the property PL/SQL-Formula, and in the pl/sql editor you can
    write something like
    function CF_TIMEFormula return Number is
    begin
      return trunc((:my_time + 0.23) * 4) / 4;
    end;As you see, you can access query columns by using the colon.
    Afterwards, you can display :cf_time in your Layout model.

  • Spooling from PL/SQL Block

    Hi,
    Is it possible to do spooling from a pl/sql block.The spool cannot be the first command because I want to give the spool file name in a loop and each time the spool name should change based on the value.
    I tried all possiblities,but I couldn't can anyone give me some idea on how to do this.
    I cannot use UTL_FILE option ,because the client agreed only for spooling.
    Is it possible to write the spool data is excel format..
    Please find below an example of my requirement..
    DECLARE
    CurSor Cur_Designation IS
    Select Designation from tbl_Designation;
    N_Desig Cur_Designation%RowType;
    Cursor Cur_Emp(Desig Number) IS
    Select Emp_no,Emp_name
    From Employee Where Emp_Designation = Desig;
    N_Emp Cur_Emp%RowType;
    BEGIN
    Open Cur_Designation ;
    Loop
    Fetch Cur_Designation INTO N_Desig;
    EXIT WHEN Cur_Designation %NOTFOUND;
    --Here I want to give the spool file name
    Spool --Should be designation name
    Open Cur_Emp(N_Desig.Designation);
    Loop
    Fetch Cur_Emp INTO N_Emp ;
    EXIT WHEN Cur_Emp %NOTFOUND;
    -- All employee details I need to come to log file
    End Loop;
    Close Cur_Emp;
    End Loop;
    Close Cur_Desingnation;
    End;
    Please advice me how to do this..
    Thanks,
    Bindu

    << I cannot use UTL_FILE option ,because the client agreed only for spooling. >>
    << I want to use it in a PL/SQL Block.I have some variables to declare and some cursors to be used.
    So where should I use the spool command.
    I tried to given after a fetch command ,but it is not working. >>
    you can't use SPOOL inside PLSQL
    you may use dbms_output calls in PLSQL
    so create a procedure test2 instead of sqlscript test2 and you will be fine
    rem =========== procedure test2 ================
    create or replace
    procedure test2 (p_param number) is
    begin
                 dbms_output.enable (1000000);
                 dbms_output.put_line('A' || chr(9) || 'B' || chr(9) || 'C' ) ;
                 FOR i_rec in (select a,b.c from xyz where a = p_param) LOOP
                     dbms_output.put_line (to_char(a) || chr(9) || b || chr(9) || c ) ;
                 END LOOP ;
    end ;
    REM ====================================================                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • How to pass parameter to pl/sql block

    Hi,
    I am getting following error when trying to create staging table from shell script by passing parameter.
    SQL*Loader-941: Error during describe of table T1_1DAY_STG
    ORA-04043: object T1_1DAY_STG does not existThis is PL/SQL block being called inside shell script
    begin
    execute immediate 'create table t1_&1._stg as select * from t1_rpt_tmt';
    endShell Script Call
    load_data_to_oracle()
    for i in 1DAY 7DAY 15DAY
    do
    ${ORACLE_HOME}/bin/sqlplus ${ORACLE_USER}/${ORACLE_PASSWD}@${ORACLE_SID} << EOF > ${TMP_LOG_FILE} 2>&1
    set serveroutput on
    @${CREATE_STAGE_SQL} "$i"
    COMMIT;
    QUIT;
    EOF
    ########Main#######
    load_data_to_oraclethanks
    sandy

    i dont understand why you want run it from shell script. you can write procedure like this :
    SQL>
    SQL> CREATE OR REPLACE PROCEDURE mytestProc(p_in VARCHAR2) AS
      2  begin
      3    FOR i IN (select REGEXP_SUBSTR(p_in,'[^,]+',1,ROWNUM) tblName
      4                from dual
      5                CONNECT BY INSTR(p_in, ',', 1, level - 1) > 0)
      6    LOOP
      7      execute immediate 'create table t1_'||i.tblname||'_stg as select * from myt2';
      8    END LOOP;
      9  end;
    10  /
    Procedure createdand run it
    SQL> exec mytestProc('1day,7day,15day');
    PL/SQL procedure successfully completed
    SQL> select * from t1_15day_stg
      2  union all
      3  select * from t1_1day_stg
      4  union all
      5  select * from t1_7day_stg;
    T                  N
    SQL>
    SQL> drop table t1_15day_stg;
    Table dropped
    SQL> drop table t1_1day_stg;
    Table dropped
    SQL> drop table t1_7day_stg;
    Table dropped
    SQL> purge table t1_15day_stg;
    Done
    SQL> purge table t1_1day_stg;
    Done
    SQL> purge table t1_7day_stg;
    Done
    SQL>

  • Calling sql script from pl/sql block

    Hi
    I want to call a sql script from pl/sql block.
    like
    CREATE OR REPLACE procedure DataBaseExport(user_name in varchar2, pwd in varchar2)
    as
    begin
    execute immediate  '@ C:\Documents and Settings\umesh\emp.sql';
    end DataBaseExport;
    /

    Try something like this -
    CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED "Host" AS
    import java.io.*;
    public class Host
         public static void executeCommand(String command)
         try {
                String[] finalCommand;
                   if (isWindows())
                        finalCommand = new String[4];
                        // Use the appropriate path for your windows version.
                        finalCommand[0] = "C:\\windows\\system32\\cmd.exe"; // Windows XP/2003
                        //finalCommand[0] = "C:\\winnt\\system32\\cmd.exe"; // Windows NT/2000
                        finalCommand[1] = "/y";
                        finalCommand[2] = "/c";
                        finalCommand[3] = command;
                   else
                        finalCommand = new String[3];
                        finalCommand[0] = "/bin/sh";
                        finalCommand[1] = "-c";
                        finalCommand[2] = command;
              final Process pr = Runtime.getRuntime().exec(finalCommand);
             pr.waitFor();
             new Thread(new Runnable()
                public void run()
                      BufferedReader br_in = null;
                   try
                        br_in = new BufferedReader(new InputStreamReader(pr.getInputStream()));
                        String buff = null;
                        while ((buff = br_in.readLine()) != null)
                                  System.out.println("Process out :" + buff);
                               try {Thread.sleep(100); } catch(Exception e) {}
                        br_in.close();
                   catch (IOException ioe)
                        System.out.println("Exception caught printing process output.");
                        ioe.printStackTrace();
                 finally
                     try {
                              br_in.close();
                          } catch (Exception ex) {}
         ).start();
         new Thread(new Runnable()
           public void run()
                BufferedReader br_err = null;
                try
                   br_err = new BufferedReader(new InputStreamReader(pr.getErrorStream()));
                   String buff = null;
                   while ((buff = br_err.readLine()) != null)
                        System.out.println("Process err :" + buff);
                        try
                           Thread.sleep(100);
                         } catch(Exception e) {}
                   br_err.close();
               catch (IOException ioe)
                   System.out.println("Exception caught printing process error.");
                   ioe.printStackTrace();
              finally
                  try
                          br_err.close();
                   catch (Exception ex) {}
          ).start();
         catch (Exception ex)
                  System.out.println(ex.getLocalizedMessage());
      public static boolean isWindows()
              if (System.getProperty("os.name").toLowerCase().indexOf("windows") != -1)
              return true;
              else
              return false;
    CREATE OR REPLACE PROCEDURE Host_Command (p_command IN VARCHAR2)
    AS LANGUAGE JAVA
    NAME 'Host.executeCommand (java.lang.String)';
    --- THE PERMISSIONS ---
    call dbms_java.grant_permission('SYSTEM', 'SYS:java.io.FilePermission', '<<ALL FILES>>', 'read ,write, execute, delete');
    call dbms_java.grant_permission('SYSTEM', 'SYS:java.lang.RuntimePermission', 'writeFileDescriptor', '');
    call dbms_java.grant_permission('SYSTEM', 'SYS:java.lang.RuntimePermission', 'readFileDescriptor', '');And, finally,
    create or replace procedure call_sql_file(usr  in varchar2,
                                              pwd  in varchar2,
                                              host_str in varchar2)
    is
    begin
       host('sqlplus -s usr/pwd@host_str C:\UAX_Auto_Count.sql');
    exception
      when others then
        dbms_output.put_line(sqlerrm);
    end;Now, you can pass all the argument in order to execute that file.
    N.B.: Not Tested...
    Regards.
    Satyaki De.

  • Select query inside PL/SQL block.

    Hello Experts,
    I am just a beginner with PL/SQL.
    If I write a select query from client like SQL dev and fire it against a database, it gives me result.
    Eg: select * from employee;
    Now when I use the same Query inside a PL/SQL block suppose:
    Declare
    begin
    select * from employee;
    end;
    This gives error on execution, mentioning that an INTO is expected etc...
    I have doubts here:
    1. Can't I use a plain select inside a PL/SQL block (if so why?)
    I know this is kind of very basic question, I tried searching this on the forum but could not find the thread, please redirect me to the link if this is already answered.

    user8578271 wrote:
    Hello Experts,
    I am just a beginner with PL/SQL.
    If I write a select query from client like SQL dev and fire it against a database, it gives me result.
    Eg: select * from employee;
    Now when I use the same Query inside a PL/SQL block suppose:
    Declare
    begin
    select * from employee;
    end;
    This gives error on execution, mentioning that an INTO is expected etc...
    I have doubts here:
    1. Can't I use a plain select inside a PL/SQL block (if so why?) Because when you run a query in a tool like SQL Developer, or SQL*Plus or TOAD etc. then it opens up a cursor and fetches the data into internal memory structures before displaying it, and that is all done automatically and hidden from you. In PL/SQL, there is no interface to display the results of SQL queries, so you have to specifically tell it what to put the data into.
    The syntax is (in basic terms)...
    SELECT column1, column2... columnX
    INTO variables or record structure
    FROM ...Though that can only select a single row of data. If your query returns more than 1 row it will give a TOO_MANY_ROWS exception. If your query returns no rows you will get a NO_DATA_FOUND exception.
    If you need to select multiple rows into variables etc., then you would need to "BULK COLLECT" into a collection/array structure, though this takes up valuable memory on the server and shouldn't be used unless necessary (and you understand the implications of doing it).

  • Accepting user input and executing a PL/SQL block using it

    Hi All,
    I am working on a requirement wherein I have to accept values from the user for the various arguments to be supplied to a PL/SQL block and then execute it using these values. For now, I am using the following logic:
    PROMPT Enter value for the Category
    ACCEPT cCategory CHAR PROMPT 'Category:'
    DECLARE
    cCategry CHAR(1) := '&cCategory';
    BEGIN
    DBMS_OUTPUT.PUT_LINE('The value of the Category as entered by you is' || cCategory);
    END;
    PROMPT Press y if you want to proceed with the current values, or press n if you want to re-enter the values
    ACCEPT cChoice CHAR Prompt 'Enter y or n:'
    DECLARE
    cCategry CHAR(1) := '&cCategory';
    sErrorCd VARCHAR2(256);
    sErrorDsc VARCHAR2(256);
    BEGIN
    IF '&cChoice' = 'y'
    THEN
    DBMS_OUTPUT.PUT_LINE('Starting with the process to execute the stored proc');
    --- schema1.package1.sp1(cCategry, sErrorCd, sErrorDsc);
    --- DBMS_OUTPUT.PUT_LINE('Error Code :' || sErrorCd);
    --- DBMS_OUTPUT.PUT_LINE(' Error Description :' || sErrorDsc);
    ELSIF '&cChoice' = 'n'
    THEN
    Now I want that the proc again start executing in the loop from the 1st line i.e. PROMPT Enter value for the Category. However i see that this is not possible to do that PROMPT statements and accepting user inputs execute only on the SQL prompt and not inside a PL/SQL block.
    Is there an alternate method to establish this?
    Thanks in advance.

    Hi,
    You can write a genric procedure to achive the desired output. Pass 'Y' or 'N' in the procedure.
    Call that procedure in simple pl/sql block during runtime using substituton operator.
    For ex
    create or replace procedure p1(category_in in varchar2)
    IS
    BEGIN
    if (category_in='Y')
    then
    prcdr1()
    /** Write your logic here ***/
    elsif(category_in='N') then
    prcdr2()
    /** write your logic here***/
    end if;
    exception
    /***write the exception logic ***/
    end p1;
    Begin
    p1('&cat');
    end;Regards,
    Achyut K
    Edited by: Achyut K on Aug 6, 2010 5:20 AM

  • Commit in pl/sql block;

    Hi Gurus,
    I have a task to delete Parent/child table records (On Delete: No action). I was getting integrity constraint error while I was trying to delete a parent record(this is obvious).
    I wrote a pl/sql block to perform this action.
    Version: 11.2
    begin
    delete from child;
    Commit; -- --> Can I ignore it ?
    delete from Parent;
    Commit;
    end;
    Do I need to write a commit after deleting the record from child table ?.
    Thanks in Advance.
    --Herndon.
    Edited by: Herndon on Jan 31, 2013 3:29 PM

    Herndon wrote:
    Hi Gurus,
    I have a task to delete Parent/child table records (On Delete: No action). I was getting integrity constraint error while I was trying to delete a parent record(this is obvious).
    I wrote a pl/sql block to perform this action.
    Version: 11.2
    begin
    delete from child;
    Commit; -- --> Can I ignore it ?
    delete from Parent;
    Commit;
    end;
    Do I need to write a commit after deleting the record from child table ?.
    Thanks in Advance.
    --Herndon.
    Edited by: Herndon on Jan 31, 2013 3:29 PMYou should remove the first COMMIT. You need to carry out the deleation of child and parent as a single transaction. So your delete statements must be like
    begin
      delete from child;
      delete from parent;
      commit;
    end;
    /Because if your parent delete fails then the child records that are already deleted will be ROLLBACK'ed.

Maybe you are looking for

  • How do I update Java.exe?

    I'm using Secunia CSI, which detects out of date software on my PC.  It flagged Java.exe in december as out of date becuase Java 6 update 30 was release do to a security update.  My local install by my browser updated itself via the Java updater just

  • "Optimize to file size" script

    Hi everyone, I am currently writing an applescript to circumvent Photoshop's lack of scripting support for the "Optimize to File Size" option in the Save for Web command, but I'm having trouble with targeting the file sizes correctly. Here is the cod

  • FF not the best anymore

    I'm a long time user of FF but the last months this browser is quite sucky. Constant updates, when I close tabs they keep "hanging"/take a few seconds to close, and the old problem I once had when going to certain sites (Facebook amongst others) the

  • Remove channel banner ad

    With the new software upgrade to STB.  I now have a very annoying BRIGHT RED ad banner on the bottom of my guide.  How do i remove it. I have Interactive TV --> Disabled. I sure hope there is a setting to disable the the ad.  I know what services I h

  • Display only one row for distinct columns and with multiple rows their valu

    Hi, I have a table having some similar rows for some columns and multiple different rows for some other columns i.e o_mobile_no o_doc_date o_status d_mobile_no d_doc_date d_status 9825000111 01-jan-06 'a' 980515464 01-feb-06 c 9825000111 01-jan-06 'a