Procedure runs in SQL Plus, but not when called from my Oracle Form

Hi. I have this code to send an email alert as the user updates a record on my base table from my Oracle Form. I use dbms_scheduler so that it's submitted as a background job and so the email processing does not delay my Oracle Form from saving quickly. If I submit this code in SQL Plus it executes and I receive the email as expected.
begin
dbms_scheduler.create_job ( 
     job_name            => 'IMMEDIATE_JOB', 
     job_type            => 'PLSQL_BLOCK', 
     job_action          => 'begin TTMS.dropperVacationConflict_Notify (62547, ''01-SEP-11'', ''02-SEP-11''); end;', 
     number_of_arguments => 0, 
     start_date          => sysdate +1/24/59, -- sysdate + 1 minute 
     enabled             => TRUE, 
     auto_drop           => TRUE, 
     comments            => 'Immediate, one-time run');
end;However if I submit this code from a Post-Update trigger in my form the code runs without error, but my email is never received (the same parameter values would be passed to this trigger):
begin
-- Submit the email notification in the background so as to not slow down the screen while saving.   
dbms_scheduler.create_job ( 
     job_name            => 'IMMEDIATE_JOB', 
     job_type            => 'PLSQL_BLOCK', 
     job_action          => 'begin TTMS.dropperVacationConflict_Notify (:dropper_vacations.dropper_id, :dropper_vacations.begin_dt, :dropper_vacations.end_dt); end;', 
     number_of_arguments => 0, 
     start_date          => sysdate +1/24/59, -- sysdate + 1 minute 
     enabled             => TRUE, 
     auto_drop           => TRUE, 
     comments            => 'Immediate, one-time run');
end;     Any ideas why this might be happening?

Wow, so I changed the two procedures so that I'm only passing in one number parameter and one char parameter...
CREATE OR REPLACE procedure TTMS.job_vacationconflict_notify (p_dropper_id number, p_other char) IS
CREATE OR REPLACE PROCEDURE TTMS.dropperVacationEmailURL_new (in_dropper_id number, in_other char) ISIf I execute it like this it works and I get the email:
TTMS.job_vacationconflict_notify(62547, 99999);or like this it works and I get the email:
TTMS.job_vacationconflict_notify(62547, '99999');But if I execute it like this (I get no errors) the email is not sent:
TTMS.job_vacationconflict_notify(62547, 'ababa');So this problem really has nothing to do with date formats. It seems to have to do with whether parameter two has characters in it!!! What the heck.
Any ideas on this?
Here is the procedure I'm calling:
CREATE OR REPLACE procedure TTMS.job_vacationconflict_notify (p_dropper_id number, p_other char) IS
begin
  dbms_scheduler.create_job ( 
     job_name            => 'IMMEDIATE_JOB', 
     job_type            => 'PLSQL_BLOCK', 
     job_action          => 'begin TTMS.dropperVacationemailurl_new ('||p_dropper_id||','||p_other||'); end;', 
     number_of_arguments => 0, 
     start_date          => sysdate +1/24/59, -- sysdate + 1 minute 
     enabled             => TRUE, 
     auto_drop           => TRUE, 
     comments            => 'Immediate, one-time run');
end;
/And the above procedure is calling this procedure which should be sending the email alert:
CREATE OR REPLACE PROCEDURE TTMS.dropperVacationEmailURL_new (in_dropper_id number, in_other char) IS
      myguid varchar2(15):=null;
      pcm_contact varchar2(3):=null;
      guid_contact varchar2(15):=null;
      conflict_cnt number(8):=0;
      -- Various declarations
      PSENDER VARCHAR2(200);            --  From
      PRECIPIENT VARCHAR2(200);         --  To
      P_CC_RECIPIENT VARCHAR2(200);     --  CC
      P_BCC_RECIPIENT VARCHAR2(200);    --  BCC
      PSUBJECT VARCHAR2(200);           --  Subject
      PMESSAGE VARCHAR2(6000);          --  Message Body
      PPARAMETER NUMBER;                --  Parameter Value
      guid_valid varchar2(15);          --  Used to grab the validation value of
      -- Grab name details of e-mail targets
      cursor targets is
      select guid, initcap(first_name) first_name, initcap(first_name)||' '||initcap(last_name) fullname
      from pwc_employee
      where upper(guid) = upper(guid_contact);
BEGIN
        select count(*)
        into conflict_cnt
        from dropper_bundle_assign
        where
            dropper_sched = in_dropper_id and
            trunc(sched) <> '31-DEC-29' AND        
            trunc(sched) between '01-SEP-11' and '02-SEP-11' and
            trunc(sched) > trunc(sysdate);
        select distinct pcm
        into pcm_contact
        from dropper_bundle_assign
        where
              dropper_sched = in_dropper_id and
              trunc(sched) <> '31-DEC-29' AND        
              trunc(sched) between '01-SEP-11' and '02-SEP-11' and
              trunc(sched) > trunc(sysdate);
        select guid
        into guid_contact
        from pwc_employee
        where initials = pcm_contact;
    -- Ensure required parameters have been passed
    if guid_contact is not null
       and in_dropper_id is not null then
           Begin
                select guid
                into guid_valid
                from pwc_employee
                where upper(guid) = upper(guid_contact);
           Exception
                when no_data_found then
                raise_application_error(-20000,'Invalid Recipient.  Please check the employee table.  Please try again.');
           End;
           -- In the event there are multiple targets then we will loop thru and send individual emails
           for thisone in targets loop
                PSENDER := lower(user)||'@us.ibm.com';
                PRECIPIENT := lower(thisone.guid)||'@us.ibm.com';
                P_CC_RECIPIENT := lower(thisone.guid)||'@us.ibm.com';
                P_BCC_RECIPIENT := 'ssbuechl'||'@us.ibm.com';
                PPARAMETER := TO_NUMBER(lower(in_dropper_id));
                PSUBJECT := 'TEST: Dropper Vacation '||in_other||' Conflict Notification for dropper '||in_dropper_id||' - Action Required';
                PMESSAGE := thisone.first_name||'-<br><br>There is an induction conflict due to a new or updated dropper vacation.<br><br>Click here to the dropper''s vacation conflicts: <u><a href="http://9.35.32.205:7777/forms/frmservlet?config=TTMSMENU&form=dropper_vacations&otherparams=p_dropper='||PPARAMETER||'">Dropper Id: '||PPARAMETER||'</a></u> (note: use your Oracle credentials when prompted for log-on information).<br><br>Thanks.';
                SEND_MAIL ( PSENDER, PRECIPIENT, P_CC_RECIPIENT, P_BCC_RECIPIENT, PSUBJECT, PMESSAGE );  -- Procedure to physically send the e-mail notification
           end loop;
    else
          raise_application_error(-20001,'Recipient and Parameter Value are required. Please try again.');
    end if;
exception
    when no_data_found then
         raise_application_error(-20002,'Note: Email will not be sent because no PCM was identified as the manager or the PCM does not have a record in the Employee table.  See ITS for assistance.');
     when too_many_rows then
         raise_application_error(-20003,'Note: Email will not be sent because multiple PCMs manage this dropper. Please notify each PCM manually.');
END dropperVacationEmailURL_new;
/Edited by: sharpe on Aug 17, 2011 4:38 PM
Edited by: sharpe on Aug 17, 2011 5:03 PM

Similar Messages

  • Able to connect to database from SQL plus but not from Oracle SQL developer

    Hi
    I have two database editions in my system Oracle XE and Oracle EE. I am able to connect to EE database through SQL plus but not through SQL developer.Please tell me how to do it.
    All settings are good.I am able to connect to the database before installing XE.I need both for my work(different projects).
    And the default listener started is XE's.Please tell me how to change the default one to EE or tell me how to connect through SQL developer??
    Regards
    Harsha

    I Solved it.
    I copied the text from listener.ora for EE
    and added it in the other one.
    It works after restart.

  • Wifi works at home but not when away from home

    My Wifi works at home but not when away from home, what is wrong?  I thought with a phone plan I didn't need to have a wifi connection.

    You either need WiFi or Cellular (or both). If you have neither, you can't connect to the internet.
    Most people use WiFi at home and Cellular while away from home, or connect to public WiFi networks where there are some.

  • Java works stand alone does not when called from PL/SQL

    I have this piece of code, which works as a standalone program: It takes in the en_var and returns a path.
    But it wont work when called from a store procedure the line of code p = rt.exec("echo "+envar); returns a path as a standalone program returns null when called from a Oracle store procedure.
    Thanks for any help just going around and round in circles.
    import java.util.*;
    class translate
    public static String translatePath(String envar)
    Runtime rt = Runtime.getRuntime();
    int bufSize = 4096;
    byte buffer[] = new byte[bufSize];
    String path = null;
    Process p = null;
    String os = null;
    String name = null;
    String home = null;
    String dir = null;
    SecurityManager sm = null;
    int len = 0;
    try
    System.out.println("Calling echo "+envar);
    os = System.getProperty("os.name");
    name = System.getProperty("user.name");
    home = System.getProperty("user.home");
    dir = System.getProperty("user.dir");
    sm = System.getSecurityManager();
    p = rt.exec("echo "+envar);
    BufferedInputStream bis = new BufferedInputStream(p.getInputStream());
    while ((len = bis.read(buffer, 0, bufSize)) != -1)
    System.out.write(buffer, 0, len);
    path = new String(buffer);
    //p.waitFor();
    bis.close();
    return path;
    catch(Exception e)
    System.out.println("Exception "+e);
    return "ProcessProblem";
    //path = "/rims/live/log";

    Still cant get it to work, it doesnt fall over anymore, but when I input $PATH, it will output $PATH instead of the path for $PATH i.e /rims/live: What does your program output please:
    Here is my code:
    import java.io.*;
    import java.util.*;
    class translate
         public static String translatePath(String envar)
              Runtime rt = Runtime.getRuntime();
              Process p = null;
              String echoOutput = null;
              int len = 0;
              try
                   System.out.println("Calling echo "+envar);
                   p = rt.exec(new String[]{"/bin/echo",envar});
                   InputStreamReader isr = new InputStreamReader(p.getInputStream());
                   BufferedReader br = new BufferedReader(isr);
                   echoOutput = br.readLine();
                   br.close();
                   isr.close();
                   return echoOutput;
              catch(Exception e)
                   System.out.println("Exception "+e);
                   return "ProcessProblem";
              //path = "/rims/live/log";
    Thanks for all your help so far.
    Tony

  • Executing a procedure - Works on Isql Plus but not SQL Developer??

    Hi folks.
    I am playing around with some design and structure stuff, mostly just passing values around procedures. I have one procedure (procedure1) which takes a sysdate and then passes it to another procedure (procedure2) which takes the parameter and does a dbms_output.put_line.
    Both objects are valid, and compile correctly. I use
    exec procedure1;
    in iSql Plus and it works perfectly. It prints the dates out and all.
    However if I use the exact same command in SQL Developer it gives me error "ORA-00900: invalid SQL statement"
    I don't understand why this happens?? The code executes perfectly in one but not the other...

    Remember that SQL*Plus commands don't work in the worksheet. So, this would fail
    exec my_procIn the worksheet you have to declare an anonymous block....
    begin
        my_proc;
    end;
    /If you right-click on the procedure in the Navigator and select Run then SQL*Dev will throw up a harness for you. Very handy if you want to get DBMS_OUTPUT, set variables, etc.
    Cheers, APC
    http://radiofreetooting.blogspot.com

  • Report runs OK through concurrent program, but not when called through URL

    We have a custom 6i report developed that works successfully 100% of the time when run through a concurrent program.
    We are now attempting to integrate this into an OAF application. To do this, we build the necessary call to the reports server by reading different profile options, etc and come up with a URL like this:
    http://ebsd777.xxxxx.com:8000/dev60cgi/rwcgi60?d777_APPS+report=XXMFG_ESPEC_REPORT.rdf+P_SPEC_ID=43+DESFORMAT=PDF
    This report works 90% of the time when called like this, but the other 10%, we get the following error:
    "Error: The requested URL was not found, or cannot be served at this time.
    Incorrect usage."
    Trying to find what the differences are between the reports that work and those that don't - found that reports which fail seem to extend out further to the right than the reports that do work. But, these reports still fit on standard letter paper in landscape format - as we can verify through the concurrent program call.
    Is there some sort of report server setting or parameter which we can change to get this to work when called through the reports server URL?
    Any thoughts would be appreciated!
    Thanks,
    Craig

    Hi,
    Please post the application release along with the database version and OS.
    But when i call the same program through the pl/sql executable of another concurrent program , it does not print the pdf output by defaultHow do you call the program? What is the value of the number of copies profile option?
    Please see if these docs help.
    Note: 757901.1 - How To Restrict The Number Of Copies To 1?
    Note: 729117.1 - How To Specify the Number of Copies to Print by Report?
    Thanks,
    Hussein

  • SQL statement works with SQL/Plus - but not with ODBC

    Hi all,
    I have a rather copmplex SQL statement:
    BEGIN
    UPDATE ContentDataTable
    SET SYMBOLIC_PATH_PARENT = N'/Test',
    SYMBOLIC_NAME = N'HAWK01.GIF',
    VERSION_NUMBER = 1 +
    SELECT MAX(VERSION)
    FROM
    (SELECT MAX(VERSION_NUMBER) AS VERSION
    FROM ContentDataTable WHERE
    SYMBOLIC_PATH_PARENT = N'/Test' AND
    SYMBOLIC_NAME = N'HAWK01.GIF'
    UNION
    SELECT MAX(VERSION_NUMBER) AS VERSION
    FROM RevisedContentDataTable WHERE
    SYMBOLIC_PATH_PARENT = N'/Test' AND
    SYMBOLIC_NAME = N'HAWK01.GIF'))
    WHERE SYMBOLIC_PATH_PARENT = N'/Test' AND SYMBOLIC_NAME = N'HAWK02.GIF' AND VERSION_NUMBER = 1;
    END;
    It works fine in SQL/Plus or SQL Worksheet and does what it should do ;-)
    But when using it via ADO (ODBC Driver) I get the following error:
    PLS-00103 found 'string' but expected one of the following: 'string'"}
    Any idaes?
    Thanx,
    Christian
    null

    Pardon my ignorance, but what's the significance of the N'<string>' construction? That's not one I'm familar with.
    Justin

  • Java class files works on middle tier but chokes when called from pl/sql

    Hi,
    I have 2 class files WorkOrder and xxWorkOrder. xxWorkOrder creates an instance of WorkOrder. Both classes are under the /classes directory. Both compile fine and I have used loadjava to upload/resolve both in the database. I can see them as valid under the user_objects table. I created a function using Pl/sql which calls a method in xxWorkOrder. If I remove the line in xxWorkOrder where it creates an instance of WorkOrder, the pl/sql function works fine via sql plus. If I add the line in, it gives me ORA-29532: Java call terminated by uncaught Java exception: java.lang.ExceptionInInitializerError if i run my test again I get a No classdef found error.
    If i run the xxWorkOrder class file directly from the server using java, the code works fine with the instantiation of WorkOrder within it.
    I'm not sure which step I am missing ? For some reason when the pl/sql function calls the java method in xxWorkOrder and it sees the line where the instance of WorkOrder is created, it chokes.
    Please help!
    Preeti

    ExceptionInInitializerError means that whatever is being done at the time it occurs is trying to use some class for the first time so that an attempt to initialize that class is occurring and failing. Such a failure typically means that there is code in a static initializer, such as the foo(); in
    static SomeType someVarName = foo();
    or just any thing within
    static { ... }
    in the class being initialized which signals an uncaught exception. It's impossible to say why this would be happening in your particular case without seeing the code. Depending on the release you are using there may be more information (such as a backtrace of the original error) in the .trc file. An example of what I am describing in your case would be if the constructor for WorkOrder invoked a method on some class N, where N hadn't previously been used and where N contained
    static Class loser = Class.forName('no/such/Class');
    In this (admittedly goofy) case you might expect to see in the .trc file a backtrace for the ExceptionInInitializer error with a sub backtrace identified with "Caused by" that starts with a NoClassDefFound exception or the like. This might work outside the server if "no/such/Class" was present there but had not been loaded into the database.

  • CommandAction works through OnDeviceDebug, but not when installed from jar

    Hi everybody,
    I'm trying to run a HelloMIDlet example and if I run it on emulator it works fine, also when I run it on mobile through OnDeviceDebug from eclipse it works fine, but when I install a jar file and run the application it ends with Application Error message and it exits. I found out that the problem might be in the CommandAction method, because when I use this:
    public void commandAction(Command c, Displayable s) {
              notifyDestroyed();
    }then the application works also when installed from jar, but when I use this:
    public void commandAction(Command c, Displayable s) {
       String label = new String("Exit");   //just for test
       if (label.equals("Exit"))
         notifyDestroyed();
    }then it ends with Application Error right after I run the program (and it works when I use OnDeviceDebug). I'm using jdk1.5.0_06 and WTK from Sony Erricsson (my target device is W800i, which supports CLDC1.1 and MIDP2.0)
    My manifest file is
    Manifest-Version: 1.0
    MicroEdition-Configuration: CLDC-1.1
    MIDlet-Name: HelloMIDlet
    Created-By: Sun Microsystems Inc.
    MIDlet-Vendor: Sun Microsystems, Inc.
    MIDlet-1: HelloMIDlet, , HelloMIDlet
    MIDlet-Version: 1.0
    MicroEdition-Profile: MIDP-2.0
    MIDlet-Description: Hello Worldand I don't use the jad file when installing the application (seems to be unecessary when you have a manifest file inside the jar). And I'm unable to debug it because when debugging then it works normally. Also I tried to recompile the BluetoothDemo and the same error(and works through OnDeviceDebug). And when I installed the jar file, which is originally distributed with BluetoothDemo then it worked. When I compared original jar file and my jar file then the only difference was in the size the class files (class files compiled by me were bigger then the class files in original jar file (which work)).
    Any ideas guys and girls?

    I tried that approach but it doesn't work either. I think maybe my directory structure is wrong.
    C:\IRS\IRS.jar
    C:\IRS\irs.hs
    referenced: jar:file://C:/IRS/IRS.jar!/irs.hs
    Am I doing this right?

  • SQL script works in SQL Developer but not when scheduled

    I have a script that I can run, logged onto my server as a user with full permissions and into my database as SYSDBA, that produces a CSV file on the server when I run it from SQL Developer ON the server. HOWEVER, when I set it up as a scheduled job, using those SAME CREDENTIALS (same Windows/network user; same database user), I get no output. The job indicates that it's running successfully, but no file gets created.
    Any advice is greatly appreciated.
    Here's the script:
    WHENEVER SQLERROR EXIT FAILURE;
         set serveroutput on
         DECLARE
         my_query varchar2(5000);
         BEGIN
         my_query := q'[
    SELECT client_id, JOB_NAME, SCHEDULE_TYPE, TO_CHAR(START_DATE,'MM/DD/YYYY HH24:MM') AS START_DATE,
    REPEAT_INTERVAL, ENABLED, STATE, RUN_COUNT,
    TO_CHAR(LAST_START_DATE,'MM/DD/YYYY HH24:MM') AS LAST_START, LAST_RUN_DURATION,
    TO_CHAR(NEXT_RUN_DATE,'MM/DD/YYYY HH24:MM') AS NEXT_RUN
    FROM DBA_SCHEDULER_JOBS
    WHERE instr(client_id,'10.') is not null
    ORDER BY LAST_START_DATE DESC
         p2k.ccsd_any_query_to_csv('HRISEDB_E_OUTPUT_MK', 'dbserver_job_output.csv',my_query);
         end;
    =================================================================
    Here's the called procedure (I don't really understand it -- I gleaned it from others on the internet):
    -- DDL for Procedure CCSD_ANY_QUERY_TO_CSV
    set define off;
    CREATE OR REPLACE PROCEDURE "CCSD_ANY_QUERY_TO_CSV" (p_dir in varchar2, p_filename in varchar2, p_query in varchar2) AUTHID CURRENT_USER
    is
    l_output utl_file.file_type;
    l_theCursor integer default dbms_sql.open_cursor;
    l_columnValue varchar2(4000);
    l_status integer;
    l_query long;
    l_colCnt number := 0;
    l_separator varchar2(1);
    l_col_desc dbms_sql.desc_tab;
    l_col_type varchar2(30);
    l_datevar varchar2(8);
    BEGIN
    l_query := 'SELECT SYSDATE FROM DUAL; ';
    dbms_sql.parse(l_theCursor, p_query, dbms_sql.native);
    dbms_sql.describe_columns(l_theCursor, l_colCnt, l_col_desc);
    l_output := utl_file.fopen( p_dir, p_filename, 'w' );
    dbms_sql.parse( l_theCursor, p_query, dbms_sql.native );
    for i in 1..l_col_desc.count LOOP
    utl_file.put( l_output, l_separator || '"' || l_col_desc(i).col_name || '"' );
    dbms_sql.define_column( l_theCursor, i, l_columnValue, 4000 );
    l_separator := ',';
    end loop;
    utl_file.new_line( l_output );
    l_status := dbms_sql.execute(l_theCursor);
    while ( dbms_sql.fetch_rows(l_theCursor) > 0 ) loop
    l_separator := '';
    for i in 1 .. l_colCnt loop
    dbms_sql.column_value( l_theCursor, i, l_columnValue );
    utl_file.put( l_output, l_separator || '"' || l_columnValue || '"');
    l_separator := ',';
    end loop;
    utl_file.new_line( l_output );
    end loop;
    dbms_sql.close_cursor(l_theCursor);
    utl_file.fclose( l_output );
    execute immediate 'alter session set nls_date_format=''dd-MON-yy'' ';
    exception
    when others then
    execute immediate 'alter session set nls_date_format=''dd-MON-yy'' ';
    raise;
    end;
    /

    hello,
    does oracle showing any errors in user_scheduler_job_run_details for this job ? I would advise try inserting some debug statement to identify where exactly its stuck. Also please check sample configurations syntax for user_scheduler_jobs.
    Cheers
    Sush

  • Select from sys.all_ind_columns works in sql*plus but not in stored proc

    I'm writing a query to find duplicate rows in a temporary table which has no unique index defined before I insert the data into the real table. I'm trying to query the sys.all_ind_columns view for the target table which belongs to a different schema:
    SELECT column_name colnm
    FROM sys.all_ind_columns i
    WHERE i.table_owner = 'SUSDB'
    AND i.index_name LIKE '%LUK'
    AND i.table_name = &tbnm
    ORDER BY i.column_position;
    This works from my GUI interface and returns five rows but when I put it into a stored procedure I get now data returned. I have granted my userid SELECT ANY DICTIONARY authority. What else do I need?

    CREATE OR REPLACE FUNCTION bog_elsa2_leslie.diag_msg_1000_cursor(i_rept_inst IN VARCHAR2,
    i_rept_time_frame IN VARCHAR2,
    i_table_name IN VARCHAR2,
    i_column_name IN VARCHAR2,
    i_domain_table IN VARCHAR2,
    i_domain_column IN VARCHAR2,
    i_domain_code IN VARCHAR2,
    i_trace_flg IN NUMBER := 0)
    RETURN VARCHAR2 IS
    cursor_stg VARCHAR2(4000);
    || File name: diag_msg_1000_cursor.fnc
    || Created by: ELSA.LESLIE
    || Created on: 20071215 4:08:20 AM
    || Purpose: Build the string that will retrieve PRIKEY and CONTENTS
    || from the target table, university, time frame, submission
    || and table passed as parameters for the 1000 dignostic.
    || Diagnostic 1000:
    || Validate that the table's logical unique key constraint
    || is not violated.
    || In: ***
    || *** ALL INPUT VARIABLES MUST BE DECLARED EVEN IF THEY ARE
    || *** NOT USED IN THIS PARTICULAR FUNCTION BECAUSE THE
    || *** EDIT_ANY_TABLE PROCEDURE CALLS THE FUNCTION IN AN
    || *** EXECUTE IMMEDIATE STATEMENT THAT REQUIRES THE 'USING'
    || *** PHRASE BE PART OF THE CALLING PROGRAM RATHER THAN BEING
    || *** INCLUDED IN THE RETURNED CURSOR_STG.
    || ***
    || i_rept_inst = reporting institution (eg. UF, FSU)
    || i_rept_time_frame = reporting time frame (eg., 200608, 20062007)
    || i_table_name = target table to be edited (eg. BUILDINGS, ENROLLMENTS)
    || i_trace_flg is optional and is used for debugging (values: TRUE/FALSE)
    || [not used] i_column_name = eg. ALTER_YR, BASE_YR
    || [not used] i_domain_table = the name of the domain table containing valid values
    || [not used] (eg. DOMAIN_MAIN_VALUES, DOMAIN_UNIV)
    || [not used] i_domain_column = the name of the column in the domain table that
    || [not used] contains the valid values (eg. CODE, OPEID_CD)
    || [not used] i_domain_code = the 5-digit domain code (eg. 10021, 01045)
    || Out: cursor_stg = executable SQL to return error row information
    || Dependencies: Logical Unique Key for tables must be have the string 'LUK'
    || postpended to it's name.
    || Exceptions: none
    || Copyright: BOG 2007
    || ***************************************************
    || Modifications:
    || Userid - Date - Modification description
    -- Constants and special assignments
    rept_inst VARCHAR2(4) := upper(i_rept_inst);
    rept_time_frame VARCHAR2(8) := i_rept_time_frame;
    table_name VARCHAR2(30) := upper(i_table_name);
    column_name VARCHAR2(30) := upper(i_column_name);
    domain_table VARCHAR2(30) := upper(i_domain_table);
    domain_column VARCHAR2(30) := upper(i_domain_column);
    domain_code VARCHAR2(5) := upper(i_domain_code);
    trace_flg NUMBER := i_trace_flg;
    file_name VARCHAR2(100) := 'diag_msg_1000_cursor: ';
    unq_cols VARCHAR2(1000) := NULL;
    unq_contents VARCHAR2(4000) := NULL;
    unq_where VARCHAR2(4000) := NULL;
    -- Accounting of process n/a all contained in the for loop
    row_num NUMBER := 0;
    -- Object types - n/a
    -- Cursors
    CURSOR ix_cols_curr(tbnm VARCHAR2 := table_name) IS
    SELECT column_name colnm
    FROM sys.all_ind_columns i
    WHERE i.table_owner = 'SUSDB'
    AND i.index_name LIKE '%LUK'
    AND i.table_name = tbnm
    ORDER BY i.column_position;
    -- Cursor variables n/a
    -- errors and exceptions
    sql_code NUMBER;
    sql_errm VARCHAR2(255);
    BEGIN
    -- output trace information if requested
    IF trace_flg = 1
    THEN
    dbms_output.put_line(file_name || 'rept_inst = ' || rept_inst);
    dbms_output.put_line(file_name || 'rept_time_frame = ' || rept_time_frame);
    dbms_output.put_line(file_name || 'table_name = ' || table_name);
    dbms_output.put_line(file_name || 'column_name = ' || column_name);
    dbms_output.put_line(file_name || 'domain_table = ' || domain_table);
    dbms_output.put_line(file_name || 'domain_column = ' || domain_column);
    dbms_output.put_line(file_name || 'domain_code = ' || domain_code);
    END IF;
    -- ix_cols_loop builds a string of the columns contain in the
    -- logical unique key which is then later incorporated into the
    -- select cursor returned to the calling program.
    FOR this_col IN ix_cols_curr(table_name)
    LOOP
    <<ix_cols_loop>>
    -- output trace information if requested
    IF trace_flg = 1
    THEN
    row_num := ix_cols_curr%ROWCOUNT;
    dbms_output.put_line(file_name || 'row=' || row_num ||
    'column_name=' || this_col.colnm);
    END IF;
    IF unq_cols IS NOT NULL
    THEN
    unq_cols := unq_cols || ', ';
    unq_contents := unq_contents || ', ';
    END IF;
    unq_cols := unq_cols || this_col.colnm;
    unq_contents := unq_contents || q'[']' || this_col.colnm ||
    q'['=]' || this_col.colnm;
    unq_where := unq_where || 'AND tbl.' || this_col.colnm ||
    ' = dups.' || this_col.colnm;
    END LOOP ix_cols_loop;
    IF trace_flg = 1
    THEN
    dbms_output.put_line(file_name || 'unq_cols =' || unq_cols);
    dbms_output.put_line(file_name || 'unq_contents =' || unq_contents);
    dbms_output.put_line(file_name || 'unq_where =' || unq_where);
    END IF;
    cursor_stg := 'SELECT prikey, ' || unq_contents || ' AS contents ' ||
    'FROM univdb.' || table_name || ' tbl, (SELECT ' ||
    unq_cols || ', COUNT(*) FROM univdb.' || table_name ||
    q'[ WHERE rept_inst = ']' || rept_inst || q'[']' ||
    q'[AND rept_time_frame = ']' || rept_time_frame || q'[']' ||
    ' GROUP BY ' || unq_cols || ' HAVING COUNT(*) > 1) dups' ||
    q'[ WHERE tbl.rept_inst = ']' || rept_inst || q'[']' ||
    q'[ AND tbl.rept_time_frame = ']' || rept_time_frame ||
    q'[']' || unq_where;
    -- output trace information if requested
    IF trace_flg = 1
    THEN
    dbms_output.put_line(file_name || 'cursor_stg = ' || cursor_stg);
    END IF;
    RETURN(cursor_stg);
    EXCEPTION
    -- block exception
    WHEN OTHERS THEN
    sql_code := SQLCODE;
    sql_errm := SQLERRM;
    IF trace_flg = 1
    THEN
    dbms_output.put_line(file_name || ' ROW NUM ' || row_num || ' sql code ' ||
    sql_code || ' sql message ' || sql_errm);
    END IF;
    END diag_msg_1000_cursor;

  • Stored procedure runs fine from SSMS but fails when called from the C# app

    I'm using SS Express 2012 so I doubt I have all possible debugging capabilities at my disposal, although I'm still trying to figure this out myself.
    The compiled C# application has logging to insure that the the SP is being invoked, the appropriate line of code is  definitely being reached. The logging always reports 'success' suggesting that the SP was successfully executed (and no exception is thrown
    to the C# app), but the indexes aren't getting rebuilt (I have a fragmentation query proving they are not rebuilt). Yet it runs successfully if I
        (1) set a breakpoint in the C# app and step through the code line by line OR
        (2) run the SP from the SSMS GUI.
    The fragmentation query confirms sucess for both 1 and 2.
    -I can't rely on the GUI because I want to run this overnight immediately after the C# app is finished inserting new records.
    - The SP loops through all the tables, and all the indexes in each table, checking for fragmentation and rebuilding any indexes over 7% fragmented.
    ALTER Procedure [dbo].[usp_RebuildIndexes]
    AS
    Declare @fetch_TableName NVARCHAR(256)
    DECLARE Cursor_Tables CURSOR FOR
    SELECT Name FROM sysobjects WHERE xtype ='U'
    OPEN Cursor_Tables
    While 1 = 1 -- Begin to Loop through all tables
    BEGIN
    FETCH NEXT FROM Cursor_Tables INTO @fetch_TableName -- fetches the next table
    if @@FETCH_STATUS <> 0 break
    print '---------' + @fetch_TableName
    Declare @fetch_indexName NVARCHAR(256) -- loops through al indexes of the current table
    DECLARE Cursor_Indexes CURSOR FOR -- Looking for indexes fragmented more than 7 percent.
    SELECT name as indexName
    FROM sys.dm_db_index_physical_stats (DB_ID(DB_Name()), OBJECT_ID(@fetch_TableName), NULL, NULL, NULL) AS a
    JOIN sys.indexes AS b ON a.object_id = b.object_id AND a.index_id = b.index_id
    Where Name is not null and avg_fragmentation_in_percent > 7
    OPEN Cursor_Indexes
    WHILE 1= 1 -- Begin to Loop through all Indexes
    BEGIN
    FETCH NEXT FROM [Cursor_Indexes] INTO @fetch_indexName
    if @@FETCH_STATUS <> 0 break
    Declare @SqL nvarchar(2000) = N'ALTER INDEX ' + @fetch_indexName + ' ON ' + DB_Name() + '.dbo.' + @fetch_TableName + ' Rebuild'
    print @Sql
    Begin TRy
    Execute sp_executeSQL @sql
    End Try
    Begin Catch
    Declare @err nvarchar(2000) = ERROR_MESSAGE();
    throw 51000, @err, 1
    End Catch
    End -- Ends looping through all indexes
    CLOSE [Cursor_Indexes]
    DEALLOCATE [Cursor_Indexes]
    End -- Ends looping through all tables
    CLOSE Cursor_Tables
    DEALLOCATE Cursor_Tables
    foreach (objDB DB in oUserPrefs.DBs) {
    report += DB.Real_Name;
    if (DB.cn == null) DB.cn = sqlCn(DB.Real_Name, SystemInformation.ComputerName);
    try {
    if (DB.cn.State != ConnectionState.Open) DB.cn.Open();
    } catch (Exception ex) {
    report += " - Failed because can't open a connection.\r\n";
    continue;
    DB.OpenedAConnection = true;
    DataTable dt = null;
    try {
    dt = oParam.fillDt("dbo.usp_RebuildIndexes", DB.cn, null);
    } catch (Exception ex) {
    report += " -failed because " + ex.Message + "\r\n\r\n";
    continue;
    report += " - success.\r\n";
    DB.LastTimeRebuiltIndexes = DateTime.Now;

    Your proc is a bit of a mess and hard to read. This should get you what you need though. I added a little logic in the middle that determines if the index should be reorged, or rebuilt.
    You were right that my script was too messy and I used your code/logic to rewrite mine. Thanks! I tried it this morning and it worked fine, but I will have to see how it runs overnight to be sure.
    Here's the weird thing. My original code should have worked. In fact I'm actually using it in 3 c-sharp apps each of which has 3 to 7  Express 2012 databases (about 10 million records per database). For about a month it's been working fine on two of the
    apps. Furthermore this morning I used a commercial file-comparison tool to verify that the 3rd app has been running an identical version of the SP. So I'm at a total loss as to what went wrong in the 3rd app.
    Here's my rewrite.
    Alter Procedure [dbo].[usp_RebuildIndexes]
    As
    Declare @Messages Table(Msg nvarchar(2000))
    Declare @IndexName nvarchar(256), @TableName NVARCHAR(256)
    DECLARE Cursor_Indexes CURSOR FAST_FORWARD FOR -- GEt a list of all indexes for all tables.
    select idxs.name as indexName, o.Name as TableName
    from sys.indexes idxs
    inner join sysobjects o on idxs.object_id = o.id
    inner join sys.dm_db_index_physical_stats (DB_ID(), NULL, NULL,NULL,NULL) as stats
    on stats.object_id = idxs.object_id and stats.index_id = idxs.index_id
    where xtype = 'u' and idxs.name is not null And avg_fragmentation_in_percent > 7
    OPEN Cursor_Indexes
    While 1 = 1
    BEGIN
    FETCH NEXT FROM Cursor_Indexes INTO @IndexName, @TableName
    if @@FETCH_STATUS <> 0 break
    Declare @SqL nvarchar(2000) = N'ALTER INDEX ' + @IndexName + ' ON ' + DB_Name() + '.dbo.' + @TableName + ' Rebuild'
    insert @Messages(Msg)VALUES(@sql)
    Execute sp_executeSQL @sql
    End
    CLOSE [Cursor_Indexes]
    DEALLOCATE [Cursor_Indexes]
    Select * From @Messages

  • 'lag' works in normal SQL statement, but not when in a view (resolved)

    hi,
    got a problem when using 'lag' in a view.
    if i set up a select statement using 'lag' and execute it, all the results are correct.
    when i stick the exact same select into a view, then the results for the 'lag' entries are not correct any more.
    has anyone experienced this ?
    any hints would be good.
    thanks
    Martin
    using Oracle 10g Express
    version 10.2.0.1.0
    can not download the patch because i can not log into metalink - no CSI
    setting to resolved.
    Message was edited by:
    user614086

    Hi again,
    I think the problem is more with your expectation of what LAG should be doing than with LAG itself.
    LAG must calculate based on the result set, in your stand alone query that means what's left after the WHERE clause is applied.
    In the view that means across all rows the view produces. THEN you apply the where clause to the calculated values. You can see this in the example below.
    So what you'd need to do is define this view in a manner in which the WHERE clause won't make a difference to the logical window produced.
    That would mean using some columns in the partition by clause and order by clause, or leaving the lag function outside the view.
    create table test_lag (column1 number, column2 varchar2(10), column3 date);
    insert into test_lag values (1, 'ONE', trunc(sysdate,'DD') - 1);
    insert into test_lag values (2, 'TWO' trunc(sysdate,'DD') );
    insert into test_lag values (3, 'THREE', trunc(sysdate,'DD') + 1);
    insert into test_lag values (4, 'FOUR', trunc(sysdate,'DD') + 2);
    commit;
    create or replace view test_lag_v
    as
    select column1, column2, lag(column2, 1) over (order by column1 asc) AS laggery, lag(column1) over (order by column3 desc) as laggery_2
    from test_lag;
    ME_XE?select *
      2  from test_lag_v
      3  where column1 <> 3;
               COLUMN1 COLUMN2                        LAGGERY                                 LAGGERY_2
                     4 FOUR                           THREE
                     1 ONE                                                                            3
    2 rows selected.
    Elapsed: 00:00:00.50
    ME_XE?
    ME_XE?select *
      2  from test_lag_v;
               COLUMN1 COLUMN2                        LAGGERY                                 LAGGERY_2
                     4 FOUR                           THREE
                     3 THREE                          ONE                                             4
                     1 ONE                                                                            3
    3 rows selected.
    Elapsed: 00:00:00.68

  • Can connect to DB via SQL plus but not Toad!

    I have installed: 10GR2 on D drive on XP machine, on C drive i have toad and Dev suite 6i (for connecting to old db's). Now, I can sqlplus from command line no problem, but when I try to connect through toad it says no listener, I also cannot tnsping my 10G db. Any idea's?

    steve contents of Devsuite tnsnames are here: the 10G db is LOCAL
    LOCAL =
    (DESCRIPTION =
    (ADDRESS_LIST =
    (ADDRESS =
    (PROTOCOL = TCP)
    (HOST = weres09023)
    (PORT = 1521)
    (CONNECT_DATA =
    (SERVICE_NAME = LOCAL)
    EISPATCH =
    (DESCRIPTION =
    (ADDRESS_LIST =
    (ADDRESS =
    (PROTOCOL = TCP)
    (HOST = rmerptest)
    (PORT = 2011)
    (CONNECT_DATA =
    (SERVICE_NAME = EISPATCH)
    MKPEURT =
    (DESCRIPTION =
    (ADDRESS_LIST =
    (ADDRESS =
    (PROTOCOL = tcp)
    (HOST = KARL)
    (PORT = 1521)
    (CONNECT_DATA =
    (SID = MKPEURT)
    MKPEUR =
    (DESCRIPTION =
    (ADDRESS_LIST =
    (ADDRESS =
    (PROTOCOL = tcp)
    (HOST = BARNEY)
    (PORT = 1521)
    (CONNECT_DATA =
    (SID = MKPEUR)
    UAT =
    (DESCRIPTION =
    (ADDRESS_LIST =
    (ADDRESS =
    (PROTOCOL = tcp)
    (HOST = rmdbtest)
    (PORT = 1800)
    (CONNECT_DATA =
    (SID = UAT)
    DEV11 =
    (DESCRIPTION =
    (ADDRESS_LIST =
    (ADDRESS =
    (PROTOCOL = tcp)
    (HOST = drerptest)
    (PORT = 1700)
    (CONNECT_DATA =
    (SID = DEV11)
    PROD =
    (DESCRIPTION =
    (ADDRESS_LIST =
    (ADDRESS =
    (PROTOCOL = tcp)
    (HOST = rmdbprod)
    (PORT = 1600)
    (CONNECT_DATA =
    (SID = PROD)
    UPGD =
    (DESCRIPTION =
    (ADDRESS_LIST =
    (ADDRESS =
    (PROTOCOL = tcp)
    (HOST = rmdbtest)
    (PORT = 2200)
    (CONNECT_DATA =
    (SID = UPGD)
    which net manager? the 10G home or the Devsuite home?

  • FM CRM_PRIDOC_READ_OW works in source system but not when executed from BW

    Hello All,
    I have extended an extractor in the source system by adding additional fields.
    One of the FM I've used is CRM_PRIDOC_READ_OW. When I run an extraction test in the source system eveything works and data does populates into the new fields.But when I run the infopackage from the BW side, I get an error message which saids the transaction has been terminated. I've been able to trace and pinpoint the possible cause of the error. When I do not call this FM, the infopackage finishes but I do not get data for the new fields and when I do call this FM, I get the error.
    Has anyone experiance this issue before?
    Your assistance will be much appreciated. Here is a portion of the code I wrote:
      loop at I_TABLE into l_s_ZASCRM_OPPT_I.
        lv_guid = l_s_ZASCRM_OPPT_I-GUID.
        lv_item_guid = l_s_ZASCRM_OPPT_I-ITEM_GUID.
        call function 'CRM_PRIDOC_READ_OW'
          exporting
          iv_header_guid = lv_guid
          importing
          ES_PRIDOC = ls_pridoc.
        loop at ls_pridoc-PRIC_COND into ls_pric_cond.
          if ls_pric_cond-kposn = lv_item_guid.
            case ls_pric_cond-STUNR.
              when '40'.
                l_s_ZASCRM_OPPT_I-zz_gpm_ttl_i = ls_pric_cond-kwert.
              when '55'.
                l_s_ZASCRM_OPPT_I-zz_gpd_ttl_i = ls_pric_cond-kwert.
              when '60'.
                l_s_ZASCRM_OPPT_I-zzfy_sp_i = ls_pric_cond-kwert.
              when '70'.
                l_s_ZASCRM_OPPT_I-zzfy_gpm_i = ls_pric_cond-kwert.
              when '80'.
                l_s_ZASCRM_OPPT_I-zzfy_gpd_i = ls_pric_cond-kwert.
            endcase.
          endif.
        endloop.
        append l_s_ZASCRM_OPPT_I to l_s_ZASCRM_OPPT_Itab.
        clear l_s_ZASCRM_OPPT_I.
      endloop
    Thanks,
    Jeff

    Hello Geo!
    Thank you for your question. I think we mapped all the systems you show. Always the same error. Concerning your systems my transport log would say:
    Source system R3DEV does not exist
    We mapped this.
    Any ideas? Is there maybe something in customizing to do what could be forgetten? The system is newly connected and there have never been a transport compounded to this source system before.
    Best regards,
    Peter

Maybe you are looking for