Using a string as sql statement in PL/SQL

Hi there,
I have a function which returns a part of a query depending on some conditions.
FUNCTION GET_REPORT_TYPE(in_report_type IN NUMBER)
RETURN VARCHAR2
AS
reporttype varchar2(50);
BEGIN
CASE in_report_type
WHEN 0 THEN
reporttype := 'C1.DATE_CLOSED != NULL';
WHEN 1 THEN
reporttype := 'C1.DATE_CLOSED := NULL';
WHEN 2 THEN
reporttype := '';
END CASE;
RETURN reporttype;
END GET_REPORT_TYPE;
Now in my procedure I would like to put this returned value in an AND clause of my query:
procedure get_cpl(p_cursor OUT rst_cur, searchcode IN VARCHAR2, reporttype IN VARCHAR2)
is
begin
open p_cursor for
SELECT C1.CIPIDI_NR,
C1.CIPIDI_NAME,
C2.TEAM_MEMBER
FROM TBL_CIPIDI C1, TBL_TEAM_MEMBERS C2
WHERE C1.CIPIDI_NR LIKE searchcode
AND C1.CIPIDI_NR = C2.CIPIDI_NR (+);
AND reporttype; -- HERE I WOULD LIKE TO USE WHAT THE FUNCTIONS RETURNED
end get_cpl;
How can I can I use reporttype to function as a part of the query? Thanks a lot
Chris

scott@ORA92> -- test data:
scott@ORA92> SELECT * FROM tbl_cipidi
  2  /
CIPIDI_NR CIPIDI_NAME DATE_CLOS
         1 name1       30-MAY-05
         1 name2
scott@ORA92> SELECT * FROM tbl_team_members
  2  /
CIPIDI_NR TEAM_MEMBER
         1 team1
scott@ORA92> -- function:
scott@ORA92> CREATE OR REPLACE FUNCTION GET_REPORT_TYPE
  2    (in_report_type IN NUMBER)
  3    RETURN            VARCHAR2
  4  AS
  5    reporttype       varchar2(50);
  6  BEGIN
  7    CASE in_report_type
  8        WHEN 0 THEN reporttype := 'C1.DATE_CLOSED IS NOT NULL';
  9        WHEN 1 THEN reporttype := 'C1.DATE_CLOSED IS NULL';
10        ELSE reporttype := '1 = 1';
11    END CASE;
12    RETURN reporttype;
13  END GET_REPORT_TYPE;
14  /
Function created.
scott@ORA92> SHOW ERRORS
No errors.
scott@ORA92> -- packaged with procedure:
scott@ORA92> CREATE OR REPLACE PACKAGE your_pkg
  2  AS
  3    TYPE rst_cur IS REF CURSOR;
  4    procedure get_cpl
  5        (p_cursor   OUT rst_cur,
  6         searchcode IN  VARCHAR2,
  7         reporttype IN  VARCHAR2);
  8  END your_pkg;
  9  /
Package created.
scott@ORA92> SHOW ERRORS
No errors.
scott@ORA92> CREATE OR REPLACE PACKAGE BODY your_pkg
  2  AS
  3    procedure get_cpl
  4        (p_cursor   OUT rst_cur,
  5         searchcode IN  VARCHAR2,
  6         reporttype IN  VARCHAR2)
  7    is
  8    begin
  9        OPEN p_cursor FOR
10        'SELECT C1.CIPIDI_NR,
11             C1.CIPIDI_NAME,
12             C2.TEAM_MEMBER
13         FROM      TBL_CIPIDI C1, TBL_TEAM_MEMBERS C2
14         WHERE  C1.CIPIDI_NR = :b_searchcode
15         AND      C1.CIPIDI_NR = C2.CIPIDI_NR (+)
16         AND ' || get_report_type (reporttype)
17        USING searchcode;
18    end get_cpl;
19  END your_pkg;
20  /
Package body created.
scott@ORA92> SHOW ERRORS
No errors.
scott@ORA92> -- tests:
scott@ORA92> VARIABLE g_ref REFCURSOR
scott@ORA92> SET AUTOPRINT ON
scott@ORA92> EXECUTE your_pkg.get_cpl (:g_ref, 1, 0)
PL/SQL procedure successfully completed.
CIPIDI_NR CIPIDI_NAME TEAM_MEMBER
         1 name1       team1
scott@ORA92> EXECUTE your_pkg.get_cpl (:g_ref, 1, 1)
PL/SQL procedure successfully completed.
CIPIDI_NR CIPIDI_NAME TEAM_MEMBER
         1 name2       team1
scott@ORA92> EXECUTE your_pkg.get_cpl (:g_ref, 1, 2)
PL/SQL procedure successfully completed.
CIPIDI_NR CIPIDI_NAME TEAM_MEMBER
         1 name1       team1
         1 name2       team1
scott@ORA92>

Similar Messages

  • How to reference the Instance name using Substitution string or SQL

    All:
    We have an Application that will be replicated in multiple Apex instances and would like to display the current Oracle Apex Instance name ( Similar to the &APP_USER. on the Welcome portion of the page ) .
    Is there a substitution string for this ?
    We plan on using a Show/Hide region on the splash page titled [About], that when clicked displays an HTML region with the subsitution strings.
    If no substitution strings, can someone help with an SQL that returns the Instance name ?
    Thanks for all the help.
    Aubrey Fernandes

    Aubrey Fernandes wrote:
    I currently have 3 URLs to get to my Development, QA and Production servers & will have many more production servers with different Application Ids.
    Development = http://canqa101:7777/pls/ngcrmd01/apex
    QA = http://canqa101:7777/pls/ngcrmq01/f?p=100:1
    Production = http://cancs105:7777/pls/ngcrmp01/f?p=100:1
    What I need are the portions before the final forward slash ( canqa101:7777/pls/ngcrmd01 ) which I assumed is the Oracle Apex instance.That information is determined by the web server configuration (e.g. the DADs when using OHS) rather than through APEX itself. There are no built-in substitution strings for this. Create an application item and an On New Instance (new session) computation to set the value using the function<tt>owa_util.get_cgi_env</tt> function to get the CGI environment variables <tt> HTTP_HOST</tt> and <tt>SCRIPT_NAME</tt>. You can then reference the value in the region using substitution string syntax.

  • How to build dynamic query strings in the query using DB adapter 'Pure SQL'

    Dear Forum,
    I am building an application which will access DB to fetch some result set. The query involves retrieving data from multiple tables(nearly 10 tables). So I have created a DB adapter using 'execute pure sql' option. With this query works fine, but my inputs parameters will vary. So I need to make my query dynamic to append the query strings at runtime depending on the inputs.
    For example I have 3 input variables - input1,input2 and input3 (in my request xsd) which are used in the pure sql query. Now if I get a 4th input parameter input4 in the request, I need to append this to query string as 'AND input4=[some value]' at runtime. Otherwise my query should have only 3 parameters. Please suggest how this can be achieved.
    Regards,
    Satya.

    This is a strange requirement, depending on the columns you have and what are optional in them, one way is to have separate operations and each opeartion will have different inputs and for each operation , a different DB Adapter is called. But this way, it results in more number of operations for the service as well as more number of references in the composite. Even if you pass the column inputs to the SQL procedure, it will result in a large number of if-else cases..
    Thanks,
    N

  • Using Collection in a sql statement.

    Hi I want to perform the following statement:
    DELETE FROM ALLOCATION_ELEC_MATRIX
    WHERE dgo_ean_id in (lt_inter_dgos);
    The collection lt_inter_dgos holds my dgo_ean_id's(varchars).
    I can't find a way to get it to work.
    The collection is declared as follows:
    TYPE Interface_param_dgos IS TABLE OF VARCHAR2(20);
    lt_inter_dgos Interface_param_dgos := Interface_param_dgos();
    then later on the collection gets filled. But how can i get it to work to use it in my sql statement?
    I don't won't to use a for loop around it since it would give me problems if I use more collections with a different amount of values in it.

    The standard approach is to use SQL collection type and table function,
    for example
    SQL> create TYPE Interface_param_dgos IS TABLE OF VARCHAR2(20);
      2  /
    Type created.
    SQL> create or replace package my_pkg
      2  is
      3   lt_inter_dgos Interface_param_dgos := Interface_param_dgos();
      4   function get_coll return Interface_param_dgos;
      5  end;
      6  /
    Package created.
    SQL> create or replace package body my_pkg
      2  is
      3   function get_coll return Interface_param_dgos
      4   is
      5   begin
      6    return lt_inter_dgos;
      7   end;
      8  end;
      9  /
    Package body created.
    SQL> begin
      2   my_pkg.lt_inter_dgos.extend(3);
      3   my_pkg.lt_inter_dgos(1) := 'SMITH';
      4   my_pkg.lt_inter_dgos(2) := 'KING';
      5   my_pkg.lt_inter_dgos(3) := 'ALLEN';
      6  end;
      7  /
    PL/SQL procedure successfully completed.
    SQL> select ename from emp;
    ENAME
    SMITH
    ALLEN
    WARD
    JONES
    MARTIN
    BLAKE
    CLARK
    SCOTT
    KING
    TURNER
    ADAMS
    JAMES
    FORD
    MILLER
    14 rows selected.
    SQL> delete from emp where ename in (select column_value from table(my_pkg.get_coll));
    3 rows deleted.
    SQL> select ename from emp;
    ENAME
    WARD
    JONES
    MARTIN
    BLAKE
    CLARK
    SCOTT
    TURNER
    ADAMS
    JAMES
    FORD
    MILLER
    11 rows selected.Rgds.

  • Using variables in PL/SQL function body returning SQL query

    h4. okay so I have this procedure POSTCODE_TO_LAT_LNG_GM_API(postcode  IN  VARCHAR2, lat  OUT NUMBER,  p_long OUT NUMBER) to convert a postcode into lat/long values. I then need to add them to the returned SQL statement so I used the string concat operator || with to_char but it comes up with this error when I try to apply the changes: Query cannot be parsed within the Builder. If you believe your query is syntactically correct, check the ''generic column'' checkbox below the region source to proceed without parsing.
    ORA-00936: missing expressionh4. Does anyone know what I am doing wrong here I have tried so many different ways round and none seem to work!! :/
    h4. btw I'm using Oracle 11g release 11.2.0.3.0 and Apex version 4.1.1.00.23
    DECLARE
    l_lat NUMBER;
    l_lng NUMBER;
    l_SDO_GEOMETRY SDO_GEOMETRY;
    l_query VARCHAR2(30000);
    BEGIN
    POSTCODE_TO_LAT_LNG_GM_API (:P1_POSTCODE, l_lat, l_lng);
    l_query := 'select
    CAR_ID, CAR_NAME, CAR_POSTCODE,
    SDO_GEOM.SDO_DISTANCE(car_location, SDO_GEOMETRY(2001,
                                        8307,
                                        SDO_POINT_TYPE(' || to_char(l_lng) || ','
                                                         || to_char(l_lat) || ',
                                                         NULL),
                                        NULL,
                                        NULL),
    0.005, ''UNIT=MILE'') DISTANCE
    from   CARS';
    RETURN l_query;
    END;

    Okay so did a little playing around and eventually got it to work, the SQL Command didn't help with the function FYI (maybe something to do with it testing SQL statements and not PL/SQL?).
    My 1st problem was that one of my columns relied on an apex text box which isn't always filled in so the SQL Compiler didn't like that. To solve this I did an IF NOT NULL, ELSE statement.
    My 2nd problem was after I did that i didn't have a value for Distance in the ELSE statement and so APEX didn't know weather or not to add a Distance column. I solved this by making the distance column NULL.
    Here is my final working code:
    DECLARE
    l_lat NUMBER;
    l_lng NUMBER;
    l_SDO_GEOMETRY SDO_GEOMETRY;
    l_query VARCHAR2(30000);
    BEGIN
    IF :P1_POSTCODE IS NOT NULL THEN
    POSTCODE_TO_LAT_LNG_GM_API (:P1_POSTCODE, l_lat, l_lng);
    l_query := 'select
    CAR_ID, CAR_NAME, CAR_DESC, CAR_MAKE, CAR_MODEL, CAR_MILEAGE, CAR_PRICE, CAR_YEAR, CAR_POSTCODE,
    SDO_GEOM.SDO_DISTANCE(car_location, SDO_GEOMETRY(2001,
                                        8307,
                                        SDO_POINT_TYPE(' || l_lng || ','
                                                       || l_lat || ',
                                                       NULL),
                                        NULL,
                                        NULL),
                                        0.005, ''UNIT=MILE'') DISTANCE,
    dbms_lob.getlength(CAR_IMAGE_SMALL) CAR_IMAGE_SMALL,
    CAR_FUEL_TYPE, CAR_TRANSMISSION, CAR_ENGINE_SIZE, CAR_NUM_DOORS, CAR_BODY_TYPE, CAR_COLOUR
    from   CARS';
    ELSE
    l_query := 'select
    CAR_ID, CAR_NAME, CAR_DESC,
    NULL Distance,
    dbms_lob.getlength(CAR_IMAGE_SMALL) CAR_IMAGE_SMALL,
    CAR_FUEL_TYPE, CAR_TRANSMISSION, CAR_ENGINE_SIZE, CAR_NUM_DOORS, CAR_BODY_TYPE, CAR_COLOUR
    from   CARS';
    END IF;
    RETURN l_query;
    END;So yer problem solved now, thanks to you guys for trying to help out!! =)

  • Can getGeneratedKeys() be used when executing batches of statements?

    Hi all,
    this question was posted in this thread:
    Can getGeneratedKeys() be used when executing batches of statements?
    but unfortunately I didn't find the answered appropriate.
    That thread is now locked, so I would like to start it again here.
    This is a summary of the other thread:
    Can you retrieve keys generated by a batch of insert statements? The following code produces an ArrayIndexOutOfBoundsException from the Oracle T4CNumberAccessor.unmarshalOneRow() method (see stack trace at the bottom of this message).
    The code is:
    String sql = "INSERT INTO FOO (ID, NAME) VALUES (FOO_SEQ.NEXTVAL, ?)";
    String generatedColumns[] = {"ID"};
    PreparedStatement pstmt = connection.prepareStatement(sql, generatedColumns);
    pstmt.setString(1, "A");
    pstmt.addBatch();
    pstmt.setString(1, "B");
    pstmt.addBatch();
    pstmt.setString(1, "C");
    pstmt.addBatch();
    //EXCEPTION OCCURS HERE
    pstmt.executeBatch();
    The exception is:
    java.lang.ArrayIndexOutOfBoundsException: 22
    at oracle.jdbc.driver.T4CNumberAccessor.unmarshalOneRow(T4CNumberAccessor.java:190)
    at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:610)
    at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:216)
    at oracle.jdbc.driver.T4CPreparedStatement.executeForRows(T4CPreparedStatement.java:955)
    at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:10580)
    The only answer given was:
    "You should directly specify how big your batching is. For that reason you may use ExecutionContext where you can set setBatchingLimit(int) and setBatching(bool). This operation will tell execution context the size of supposed batching and also should be batching performed at all or not. You can add batching jobs but you can not execute the jobs without proper initialization of batching job size - it will fail with out of bounds."
    ExecutionContext is not something I found in jdbc drivers, so I'm a bit confused about this answer.
    Did anyone solve the problem?
    Thanks,
    Michele

    >
    We have the same problem. No solution so far.
    >
    I never found a definitive solution but testing seems to show that this is not possible.
    There is no code that can be written to get the generated keys if batching is used.
    This is because the 'getGeneratedKeys' method must be called on the prepared statement and would return the generated keys as a ResultSet object. But when batching there is only one prepared statement but multple sets of parameters, one for each batch entry.
    Thus there could only be one call to 'getGeneratedKeys' since there is only one prepared statement. This strongly implies that it is not possible to use 'getGeneratedKeys' when batching.
    See Retrieval of Auto-Generated Keys in the JDBC Dev guide
    http://docs.oracle.com/cd/B19306_01/java.102/b14355/jdbcvers.htm#CHDEGDHJ

  • Error accesing/using a String object.......

    Hi again folks!
    Well now I have other problem, I don?t know what's happening, but I have simple C++ program as shared object which retrieves information from a Database, with the query results it makes a single string with all the data retrieved.
    This C++ program is called by a Java program using JNI, but when my Java program receives the string and tries to parse it with the StringTokenizer object I get an error like this:
    SIGSEGV 11* segmentation violation
    si_signo [11]: SIGSEGV 11* segmentation violation
    si_errno [0]: Error 0
    si_code [1]: SEGV_ACCERR [addr: 0x45cb2448]
    stackbase=DFFFF0A0, stackpointer=DFFFD0CC
    Full thread dump:
    "SIGQUIT handler" (TID:0xdd300190, sys_thread_t:0x42020, state:R, thread_t:
    t@5, sp:0x0 threadID:0xdeaf0dd8, stack_base:0xdeaf0d6c, stack_size:0x20000) prio
    =0
    "Finalizer thread" (TID:0xdd3000d0, sys_thread_t:0x41fb8, state:CW, thread_t
    : t@4, sp:0x0 threadID:0xdebb0dd8, stack_base:0xdebb0d6c, stack_size:0x20000) pr
    io=1
    "main" (TID:0xdd3000a8, sys_thread_t:0x42908, state:R, thread_t: t@1, sp:0x0
    threadID:0x20a18, stack_base:0xdffff0a0, stack_size:0x800000) prio=5 *current t
    hread*
    ObjectFactory.createObject(Compiled Code)
    Test.main(Compiled Code)
    Registered Monitor Dump:
    PCMap lock: <unowned>
    Thread queue lock: <unowned>
    Name and type hash table lock: <unowned>
    String intern lock: <unowned>
    JNI pinning lock: <unowned>
    JNI global reference lock: <unowned>
    BinClass lock: <unowned>
    Class loading lock: owner "main" (0x42908, 1 entry)
    Java stack lock: <unowned>
    Code rewrite lock: <unowned>
    Heap lock: <unowned>
    Has finalization queue lock: <unowned>
    Finalize me queue lock: <unowned>
    Waiting to be notified:
    "Finalizer thread"
    Monitor cache expansion lock: <unowned>
    Monitor registry: owner "main" (0x42908, 1 entry)
    Abort (core dumped)
    I dont know if I have to do something special before use the String, what's happening?
    Any comment will be welcome.
    Thanks in advance.

    I hope this could help to clarify the scenario
    In a previous query I get the number of rows returned by the next query
    this number is stored at SQL_NUM_SEGS.arr variable. When I have the number of rows I reserve memory for the char array that I'm going to return with all the information.
    AC01_TRAMA=(char *)malloc(atol(SQL_NUM_SEGS.arr) * INT02_TAM_SEG);
    /*embedded PL/SQL code*/
    EXEC SQL DECLARE CUR_EMISORA CURSOR FOR
    SELECT rtrim(to_char(NUM_EMISORA)) || '|' || rtrim(SERIE) || '|' || EMISORA || '|' || STATUS FROM NUCL_EMISORA WHERE STATUS NOT LIKE 'BAJA';
    EXEC SQL OPEN CUR_EMISORA;
    The next lines of code generate a string like this:
    "UTIL0000|366|239|93-1|FINASA |VIGE|243|3-90|BONSER |VIGE|248|2-94|BONSER |VIGE|287|970403|GOBFED |VIGE|362|93-4|BANOBRA |VIGE|404|2-90|BONSER |VIGE|407|2-95|FINASA |VIGE|633|95|BANMEXI |VIGE|641|2-94|PROMEX |VIGE|645|1-95|FINASA |VIGE|647|1-96|FINASA |VIGE|660|92|BANORTE |VIGE|677|93-3|BANOBRA |VIGE|678|1-90|BIATLAN |VIGE|736|2-95|BONSER |VIGE|786|1-94|BNCI |VIGE|1007|021024|GOBFED |VIGE|1008|021121|GOBFED |VIGE|"
    this string is assigned to AC01_TRAMA(char pointer)and then I return this string in the next way:
    return ( (env)->NewStringUTF(AC01_TRAMA) );
    My java program is this:
    public class Monitor
    public native String consultaGeneral();
    static
    System.load("/afs/invermexico.com.mx/usr2/salponce/gustavo/jni/src_db/Monitor.so");
    public String getTrama()
         String strTrama=consultaGeneral();
    return strTrama;
    public static void main(String []args)
    String strEmisora, strNumEmisora, strStatus,strSerie;
    Monitor m=new Monitor();
    System.out.println(m.getTrama());
    /*java.util.StringTokenizer STk = new java.util.StringTokenizer(m.getTrama(),"|");
    while(objSTk.hasMoreTokens())     
    strEmisora = objSTk.nextToken();
    strNumEmisora = objSTk.nextToken();
    strStatus = objSTk.nextToken();
    strSerie = objSTk.nextToken();
    System.out.println("\n<------>\n"+ strEmisora+"\n"+strNumEmisora+"\n"+strStatus+"\n"+strSerie);
    }//while
    Well, this java program works fine but if I try to create an String tokenizer with it the program crashes, even if I assign the result into a new String object.
    I'm going to put all the code rigth here
    C++ program
    #include "ast_bd.h"
    #include "Monitor.h"
    #include <stdlib.h>
    #include <stdio.h>
    #include <strings.h>
    #include <jni.h>
    #define CHA01_NOMBRE_APP "UTIL0000"
    #define CHA02_FIN_DE_SEG "|"
    #define INT01_TAM_LONG 20
    #define INT02_TAM_SEG 52 /*52 BYTES; Tama�o de los 4 datos en conjunto*/
    Prop�sito :-Determinar cuales son las emisoras con estado de vigente
    o bloqueado.
    -Obtener los datos de una emisora espec�fica.
    -Actualizar los datos de una emisora espec�fica.
    JNIEXPORT jstring JNICALL Java_Monitor_consultaGeneral
    (JNIEnv *env, jobject obj)
    long LO01_STATUS=1;
    char CH01_NUM_SEGS[INT01_TAM_LONG];
    char AC01_TRAMA, AC02_SEG;
    EXEC SQL BEGIN DECLARE SECTION;
    VARCHAR SQL_NUM_SEGS[INT01_TAM_LONG],
    SQL_RESULT[INT02_TAM_SEG];
    EXEC SQL END DECLARE SECTION;
    EXEC SQL WHENEVER SQLERROR CONTINUE;
    open_db();
    EXEC SQL SELECT to_char(COUNT(1)) INTO:SQL_NUM_SEGS FROM NUCL_EMISORA WHERE STATUS NOT LIKE 'BAJA';
    LO01_STATUS = sqlca.sqlcode;
    if( !LO01_STATUS ) /*si todo sali� bien*/
    strcpy(CH01_NUM_SEGS,SQL_NUM_SEGS.arr);
    CH01_NUM_SEGS[SQL_NUM_SEGS.len]='\0';
    AC01_TRAMA=(char *)malloc(atol(SQL_NUM_SEGS.arr) * INT02_TAM_SEG);
    sprintf(AC01_TRAMA,"%s|%s|\0", CHA01_NOMBRE_APP, CH01_NUM_SEGS);
    EXEC SQL DECLARE CUR_EMISORA CURSOR FOR
    SELECT rtrim(to_char(NUM_EMISORA)) || '|' || rtrim(SERIE) || '|' || EMISORA || '|' || STATUS FROM NUCL_EMISORA WHERE STATUS NOT LIKE 'BAJA';
    EXEC SQL OPEN CUR_EMISORA;
    LO01_STATUS = sqlca.sqlcode;
    if( !LO01_STATUS ) /*si todo sali� bien*/
    do
    EXEC SQL FETCH CUR_EMISORA INTO :SQL_RESULT;
    LO01_STATUS = sqlca.sqlcode;/*Recuperamos el estado de la operacion fetch*/
    if( !LO01_STATUS )
    AC02_SEG=(char *)malloc(SQL_RESULT.len);
    strcpy(AC02_SEG,SQL_RESULT.arr);
    AC02_SEG[SQL_RESULT.len]='\0';
    strcat(AC01_TRAMA,AC02_SEG);
    strcat(AC01_TRAMA,CHA02_FIN_DE_SEG);
    }/*if fetch correcto*/
    else
    LO01_STATUS=1;
    }while(!LO01_STATUS);
    EXEC SQL CLOSE CUR_EMISORA;/*Cerramos el cursor*/
    Si no se recuperaron registros, se indicara en el numero de segmentos
    al inicio de la trama.
    }/*if open cursor*/
    }/*if conteo*/
    puts(AC01_TRAMA);
    return ( (env)->NewStringUTF(AC01_TRAMA) );
    }/*consulta_general*/
    Java programs
    public class Monitor
    public native String consultaGeneral();
    static
    System.load("/afs/invermexico.com.mx/usr2/salponce/gustavo/jni/src_db/Monitor.so");
    public String getTrama()
         String strTrama=consultaGeneral();
    return strTrama;
    public static void main(String []args)
    String strEmisora, strNumEmisora, strStatus,strSerie;
    Monitor m=new Monitor();
    System.out.println(m.getTrama());
    /*java.util.StringTokenizer STk = new java.util.StringTokenizer(m.getTrama(),"|");
    while(objSTk.hasMoreTokens())     
    strEmisora = objSTk.nextToken();
    strNumEmisora = objSTk.nextToken();
    strStatus = objSTk.nextToken();
    strSerie = objSTk.nextToken();
    System.out.println("\n<------>\n"+ strEmisora+"\n"+strNumEmisora+"\n"+strStatus+"\n"+strSerie);
    }//while
    Thank's

  • Using MapViewer from PL/SQL vs Java

    Hi group!
    The MapViewer User's Guide has this to say about using MapViewer from PL/SQL:
    "The usage model for the SDO_MVCLIENT package is almost identical to that of
    MapViewer JavaBean-based API" etc etc .. "For usage and reference information about specific functions or procedures, see the description of the associated JavaBean-Based API. methods and interfaces in Chapter 4"
    If I don't misunderstand the basic concept, in a Java Web App (using the MapViewer Bean) you create a MapViewer object for each HTTP-user-session, like so:
    MapViewer mv = new MapViewer("http://my_corp.com:8888/mapviewer/omserver");
    ... which you would then store in the user's session object, so that the MapViewer Bean conveniently holds the map's state on the user's behalf.
    To do the equivalent in PL/SQL, the User's Guide suggests:
    "connect scott/tiger
    call sdo_mvclient.createmapviewerclient(
    'http://www.mycorp.com:8888/mapviewer/omserver') ;
    The preceding example creates, in the current session, a unique MapViewer client
    handle to the MapViewer service URL"
    Does "current session" refer to the HTTP-user-session? While I've used PL/SQL before, I've not used the PL/SQL Web Toolkit. Is the session handling implicit here (and invisible?) or should the sdo_mvclient be subsequently stored in the PL/SQL equivalent of a (J2EE) HttpSession object?
    YT

    Part of the answer will depend on how you plan to deploy the application. If you have a few, local clients you could go with the traditional client/server model. If you have a lot of clients and/or they are spread out over a relatively large area (like a campus setting), a web front-end will save you a lot of hassels down the road when it comes time to upgrade.
    Regardless of the the front end, I can tell you that I have been greatly impressed with the throughput you can get by moving most of the code to PL/SQL packages. A few years ago we reworked a VB/Oracle app by moving a lot of the code out of VB and into packages, leaving the client to essentially call procedures and format the output. We had more than a 3x performance increase on the same hardware and our network utilization decreased noticably.
    I am now in the process of replacing the client code with Java servlets/JSP, primarily because of the maintenance hassles I mentioned earlier. There are some limitations with an HTML page but most of these have been cosmetic so far.
    We are still relying heavily on PL/SQL packages. The servlet code basically gets a request, calls a package to get the data, then hands the results to a JSP page. The JSP then formats the output and sends it to the client. We are little more than halfway through the re-write, but it appears performance will increase again. Not as noticably as before, but I will take what I can get. As you have seen, once something is rolled out it always ends up getting used more than you anticipated. Better to over-engineer now than have to patch it once it is live.
    HTH

  • Using a string or char as a class when calling a method

    Is there a way to take the string.charAt(int) method and use it as a stand in for a class that is one character long? (Examples below, as I'm sure that question makes no sense out of context.)
    Something like (note the last line):
    import java.util.Scanner;
    public class DRV
         public static void main(String[] args)
              Scanner inpt = new Scanner(System.in);
              String stringy;
              A a = new A();
              System.out.println("Enter 'a': ");
              stringy = inpt.next();
              [stringy.charAt(0)].lineOne();
    }Or will I just have to use a lot of if statements:
    import java.util.Scanner;
    public class DRV
         public static void main(String[] args)
              Scanner inpt = new Scanner(System.in);
              String stringy;
              A a = new A();
              System.out.println("Enter 'a': ");
              stringy = inpt.next();
              if (stringy.charAt(0) == 'a')
                   a.lineOne();
                   System.out.println();
    }I doubt this is possible, but it would be totally awesome if there was something like [stringy.charAt(0)].classmethod();. This would allow me to just use a couple for loops instead of a cluster of if's.
    Thanks for any help.
    Edited by: 797223 on Sep 28, 2010 11:21 PM

    What Kayaman said.
    Another suggestion, slightly more elaborate, is to use class.forName() and reflection to create an instance of the correct class:
    stringy = inpt.next();
    Class clazz = Class.forName(makeClassCase(stringy));
    Object o = clazz.newInstance();
    SomeInterface i = (SomeInterface)o;
    i.lineOne();This assumes that you write a method private String makeClassCase(String s) that returns the correctly cased class name (e.g. transforms 'a' to 'A') and adds the appropriate package name if applicable, and that you define method lineOne() in an interface SomeInterface and in all classes that implement it (assuming I have correctly understood that all your classes do expose the same lineOne() method).
    You'll have to make special provisions for error cases (e.g. the user types a class name that doesn't exist, or that doesn't implement the common interface).

  • Powershell use Connection String to query Database and write to Excel

    Right now I have a powershell script that uses ODBC to query SQL Server 2008 / 2012 database and write to EXCEL
    $excel = New-Object -Com Excel.Application
    $excel.Visible = $True
    $wb = $Excel.Workbooks.Add()
    $ws = $wb.Worksheets.Item(1)
    $ws.name = "GUP Download Activity"
    $qt = $ws.QueryTables.Add("ODBC;DSN=$DSN;UID=$username;PWD=$password", $ws.Range("A1"), $SQL_Statement)
    if ($qt.Refresh()){
    $ws.Activate()
    $ws.Select()
    $excel.Rows.Item(1).HorizontalAlignment = $xlCenter
    $excel.Rows.Item(1).VerticalAlignment = $xlTop
    $excel.Rows.Item("1:1").Font.Name = "Calibri"
    $excel.Rows.Item("1:1").Font.Size = 11
    $excel.Rows.Item("1:1").Font.Bold = $true
    $filename = "D:\Script\Reports\Status_$a.xlsx"
    if (test-path $filename ) { rm $filename }
    $wb.SaveAs($filename, $xlOpenXMLWorkbook) #save as an XML Workbook (xslx)
    $wb.Saved = $True #flag it as being saved
    $wb.Close() #close the document
    $Excel.Quit() #and the instance of Excel
    $wb = $Null #set all variables that point to Excel objects to null
    $ws = $Null #makes sure Excel deflates
    $Excel=$Null #let the air out
    I would like to use connection string to query the database and write results to EXCEL, i.e.
    $SQL_Statement = "SELECT ..."
    $conn = New-Object System.Data.SqlClient.SqlConnection
    $conn.ConnectionString = "Server=10.10.10.10;Initial Catalog=mydatabase;User Id=$username;Password=$password;"
    $conn.Open()
    $cmd = New-Object System.Data.SqlClient.SqlCommand($SQL_Statement,$conn)
    do{
    try{
    $rdr = $cmd.ExecuteReader()
    while ($rdr.read()){
    $sql_output += ,@($rdr.GetValue(0), $rdr.GetValue(1))
    $transactionComplete = $true
    catch{
    $transactionComplete = $false
    }until ($transactionComplete)
    $conn.Close()
    How would I read the columns and data for $sql_output into an EXCEL worksheet. Where do I find these tutorials?

    Hi Q.P.Waverly,
    If you mean to export the data in $sql_output to excel document, please try to format the output with psobject:
    $sql_output=@()
    do{
    try{
    $rdr = $cmd.ExecuteReader()
    while ($rdr.read()){
    $sql_output+=New-Object PSObject -Property @{data1 = $rdr.GetValue(0);data2 =$rdr.GetValue(1)}
    $transactionComplete = $true
    catch{
    $transactionComplete = $false
    }until ($transactionComplete)
    $conn.Close()
    Then please try to use the cmdlet "Export-Csv" to export the data to excel like:
    $sql_output | Export-Csv d:\data.csv
    Or you can export to worksheet like:
    $excel = New-Object -ComObject Excel.Application
    $excel.Visible = $true
    $workbook = $excel.Workbooks.Add()
    $sheet = $workbook.ActiveSheet
    $counter = 0
    $sql_output | ForEach-Object {
    $counter++
    $sheet.cells.Item($counter,1) = $_.data1$sheet.cells.Item($counter,2) = $_.data2}
    Refer to:
    PowerShell and Excel: Fast, Safe, and Reliable
    If there is anything else regarding this issue, please feel free to post back.
    Best Regards,
    Anna Wang

  • Using a string to reference a variable

    hi all,
    i've encountered an interesting scenario where i need to use a string to reeference the value of a variable...the following would show the scenario in a simpler way...
    let's say we have such function called foo:
    void foo(String aString)
    int a = 20;
    int b = 20;
    system.out.println(?????);
    now let's say i run the function as:
    foo("a")
    and i want it to return:
    20
    what should be put to replace those "?????" in my function above?
    please note that variables "a" and "b" are arbitary and so having a conditional statement like the following would NOT be useful:
    void foo(String aString)
    int a = 20;
    int b = 20;
    if (aString.equals("a"))
    system.out.println(a);
    if (aString.equals("b"))
    system.out.println(b);
    thank you very much!

    There are two possibilities here.
    The preferable one, if you have control over the names and nature of the variables, then don't use individual variables - use a Hashtable (or any implementation of Map). Your code would then look something like:void foo(String aString)
        Map table = new Hashtable();
        table.put("a", new Integer(20));
        table.put("b", new Integer(30));
        system.out.println(table.get(aString));
    }The down side to this is that you have to use Integers - Maps can't take primitives.
    If, on the other hand, you have to have variables, then take a look at using reflection. It's more complicated than using Maps, and less efficient, so I would recommend the first technique if possible.
    RObin

  • Problems using Quick Migrate in SQL Developer 1.5 for MySQL to Oracle 10g

    Hi all,
    I am trying to use SQL Developer 1.5 migration tools (Quick Migrate) to perform online capture and build source model to migrate from MySQL 5.x to Oracle 10g on Windows platform. I get these errors and the Quick Migrate process fails:
    oracle.dbtools.metadata.persistence.PersistableObject.doInsert(PersistableObject.java:238)
    I did a search and used the sqldeveloper.cmd script but still fails. Then I created a new database and truncated the repository. I now get the above error plus two new ones listed below:
    oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
    Error loading nls:OALL8 is in an inconsistent state
    Error occurred during capture: Protocol violation
    It fails during the capture process for MySQL 5.1 database
    when it begins to capture the tables from MySQL.
    Does anyone know how to resolve these issues when migrating from MySQL to Oracle 10g using Quick Migrate with SQL Developer 1.5 release?
    Regards,
    Ben Prusinski
    Message was edited by:
    benprusinski
    Message was edited by:
    benprusinski

    Hi all,
    I put the following in my sqldeveloper.cmd file:
    SET ORACLE_HOME=%CD%
    What is very confusing is that with SQL Developer 1.5, there are several levels and several SQL Developer executables! I am really not sure which of these to use:
    I created the SQLDeveloper 1.5 directory called SQLDeveloper1_5 on Windows:
    1) cd C:\sqldeveloper1_5\sqldeveloper-5338
    there exists a sqldeveloper.exe
    2) cd c:\sqldeveloper1_5\sqldeveloper-5338\sqldeveloper\sqldeveloper.exe
    3) cd c:\sqldeveloper1_5\sqldeveloper-5338\sqldeveloper\sqldeveloer\bin\sqldeveloper.exe
    Which SQLDeveloper 1.5 executable should I be using and where should I place the
    sqldeveloper.cmd file?
    Also I did try to use a different database and schema for the repository with Quick Migrate but it appears a bug exists in SQL Developer 1.5 version that causes errors with Quick Migrate for MySQL to Oracle? Is this correct?
    As an update, I ran the following commands:
    cd to
    c:\sqldeveloper1_5\sqldeveloper-5338\sqldeveloper\sqldeveloper\bin
    sqldeveloper.cmd sqldeveloper.exe
    Start sqldeveloper.exe
    Perform standard capture for MySQL using the new mig2 schema as the new repository
    It starts the capture but fails on the errors below:
    Error loading nls:OALL8 is in an inconsistent state
    UPDATE
    ============================
    I tried this again and it worked with the exception of one error message listed below:
    Here are the steps that I followed:
    1. Create a Windows cmd script
    Put the following entries in the script:
    SET ORACLE_HOME=%CD%
    save the command windows script as sqldeveloper.cmd
    Copy this script to the base installation directory for SQLDeveloper
    Example:
    1. cd c:\SQLDeveloper1_5\sqldeveloper-5338\sqldeveloper
    2. Start SQLDeveloper with the command script that you created earlier
    Example:
    Open a Windows shell prompt window and execute the following scripts:
    a) sqldeveloper.cmd sqldeveloper.exe
    b) sqldeveloper.exe
    3) In SQL Developer 1.5
    From the Migrate menu,
    a) Delete current repository and create a new schema in Oracle target database call it mig2.
    b) Then create a new repository in SQL Developer 1.5
    c) Right mouse click on the MySQL 5.x database and choose capture
    It worked with the exception of one error message:
    o.jdbc.driver.OracleDriver     
    Error while registering Oracle JDBC Diagnosability MBean.
    So it looks like something is screwed up with my JDBC drivers and configuration for MySQL. How do I diagnose the JDBC driver issue for MySQL?
    Thanks!!!
    Ben
    Thanks
    Ben

  • How to include lexical parameters in IN string in SQL QUERY BUILDER ?

    Hi,
    I have to write an SQL Query in SQL QUERY BUILDER in Reports 6i to retrieve all details pertaining to donor codes i insert randomnly at runtime.
    The Statement is like this
    SELECT TITLE_TAB.TITLE_CODE,DONOR_TAB.DONOR_CODE, DONOR_TAB.FIRST_NAME,DONOR_TAB.MIDDLE_NAME,DONOR_TAB.LAST_NAME,CITY_MASTER_TAB.CITY_CODE FROM DONOR_TAB,CITY_MASTER_TAB,TITLE_TAB
    WHERE DONOR_CODE IN (1,2,6,70,....)
    I cannot use lexical parameter '&' in SQL QUERY BUILDER as i have to use bind variable donor_code.
    How do i do it?

    How do i do that? Can you give me an example of how i can go about with it?

  • How to use SET ID in select statement of SQ02

    Hi,
    I have a infoset, where for one of my Zfield, i have writen a select statement in order to get my ouput.
    if aufk-aufnr = 'XYZ'.
      select sum( FKBTR ) from fmifiit into zfmifiit
      where fikrs = aufk-kokrs
      and fipex IN capex
      and wrttp NE '51'.
    endif.
    For the above statement, i have created (with 10 single values, table name FMCI, field name FIPEX)  a SET id named CAPEX and used with IN operator.
    But when i generating the infoset i am getting error like below
    The IN operator with "CAPEX" is followed neither by an internal table nor by a value list
    I was using IN opeartor for set ids during validation / substitutions, where if i have to validate multiple single values.
    What to do here?
    Regards,
    Srinu

    [OPEN-SQL|http://help.sap.com/abapdocu_70/en/ABENOPEN_SQL_GENERAL.htm] set of statement, [SELECT|http://help.sap.com/abapdocu_70/en/ABAPWHERE.htm] statement, [WHERE|http://help.sap.com/abapdocu_70/en/ABENWHERE_LOGEXP.htm] addition requires a selection table (type range, [WHERE - IN seltab |http://help.sap.com/abapdocu_70/en/ABENWHERE_LOGEXP_SELTAB.htm]) of parameter and not a set. We are in Abap here, not in a Customizing screen
    You have to convert the set to a selection table in an ABAP coding before using it in a SELECT statement.
    (Check FM like G_SET_TREE_IMPORT to import definition of set (values and intervals) and map them to a select-table, or ask a developper to perform it, look at G_SET_TREE_IMPORT -> select statement)
    Regards,
    Raymond

  • Error using Data Miner on SQL Developer

    Dear all.
    I'm trying to use Data Miner on SQL Developer (3.1.06) with Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 -
    64bit Production, with the Partitioning, OLAP, Data Mining and Real Application Testing options.
    I created a project, a workflow, a data source, a classification model and connected them.
    I tried to show the Decision Tree generated as described in the tutorial "Using Oracle Data Miner 11g Release 2".
    But, I receive the message "It's not possible to load the data mining model because it does not exist" in a dialog box entitled "Model not found".
    It seems that something was missing either during installation or granting my user.
    Does anybody have seen this message and know what causes it?
    Any other suggestion is welcome.
    Regards,
    Duncan
    PUCRS-Brazil

    Hi Mark.
    Thank you on replying my post.
    I'm not the DBA of Oracle repository here. So, if possible, I'd like to address my issue without having to do anything in it.
    I'll try to state better what we have here.
    When I try to use latest SQL Developer version, 11.2.1.1.7.42, it got me a message stating current repository isn't compatible with this SQLDev version
    Repository version is: 11.2.1.1.3
    I don't know what type of upgrade SQL Developer wants to do...
    About your other questions.
    "Is the model not found error occurring for all models or just the DT model?" -- The error occurs for all 4 standard models: SVM, GLM, NB and DT. But, I'm able to see all other options: "show tests results", "Compare tests results".
    You did not report that the workflow failed, so you must be seeing a successful completion status for each of the nodes. -- Yes, all steps are executed and finished OK.
    Are you using a proxy user or some other connection definition other than a standard connection. -- No.
    There is currently some problems supporting proxy based connections that will be fixed in a upcoming SQL Developer release.
    So, if you can provide me some details on how your connection is defined, that will be helpful.
    How was the product installed and the user granted rights? -- I need to ask PUCRS DBA team to answer these questions.
    Was it done through the UI or by running the scripts in the dataminer/scripts directory?
    Lastly, what is your client operating system and are you using the SQL Dev 64 bit or 32 bit release? -- I tested in 2 different computers, both with Windows 7 Professional. In my notebook, it's 64 bits OS version.
    Thank you for your attention and kind reply.
    Regards,
    Duncan

Maybe you are looking for

  • How Can I Achieve Sliding Out Social Icons on Left side of Page?

    I have been trying to find free plugins, but ways to work with the various states in Muse, but am having trouble deciding which was is best. Here is an example of what I mean,,, but all are only for Wordpress. http://smartcatdesign.net/sliding-social

  • Iplanet LDAP with Weblogic

    Hello All, I forgot the subject line. I'm trying to set up iPlanet Directory 4.1 with WebLogic 5.1 Sp3 on Solaris7. Weblogic will see the users I specify (username,groupname) but not the group, additionally it will allow you to login if you know the

  • Word to InDesign 画像のリンクのトラブル

    環境:Win2000 Word2003 InDesignCS Wordドキュメント上でテキストと画像を使っています. ○○○○○○○○←テキスト ○○○○○○○○ ○○○○○○○○ ■■■■■■■■←画像(ABC.JPEG) ○○○○○○○○ ○○○○○○○○ 表を作り(後でInDesignに配置した際に文字がきちんと画像に回りこむように)その中に画像を挿入→リンクで配置します. このドキュメントをリッチテキスト形式(.rtf)で書き出したものを.InDesignCSで配置します. すると画像は

  • Layout Problem (Flash)

    Hi, I'm doing a site for a friend and I've added some flash to the site (my first time)..lol Anyway if you look at www.web999.co.uk you can see my problem when I have the nested layer positioned as absolute there isnt a big gap at the top of the scre

  • Eclipse Axis and Webservices in SAP

    Hi ! Im trying to write a small Web Application that whold be able to call webServices. I Created Web project in Eclipse and irts ok. Now i add new WebService Client  to a project, define Axis as provider - supply WSDL URL from ES discovery site. Ecl