Instr inside of block pl/sql

Hi Friends,
I Have this code :
select
from 
P_EPS_anl_IFI
where
instr(':'||nvl(:P39_PRACA,:V_PRACA)||':',':'||PRACA||':') > 0
AND instr(':'||:P39_TECNO||':',':'||TECN||':') > 0
AND instr(':'||:P39_AN_EPS||':',':'||EPS||':') > 0
AND PERIODO = :P39_PERIODO
AND TP_NEGOCIO = :P39_TP_NEGOCIO  And This Code is Running correctly , But , This is a part of report and I have some conditional option and I have to put this code os Pl/sql Cod and the sql instruction inside os Variable like below :
DECLARE
V_SQL VARCHAR2(30000);
BEGIN
V_SQL :=
'SELECT
FROM 
P_EPS_ANL_IFI
WHERE
PERIODO = ''&P39_PERIODO.''';
return v_sql ;
END ;
But this part
instr(':'||nvl(:P39_PRACA,:V_PRACA)||':',':'||PRACA||':') > 0
AND instr(':'||:P39_TECNO||':',':'||TECN||':') > 0
AND instr(':'||:P39_AN_EPS||':',':'||EPS||':') > 0 I Could not to do ... Can you Help me ?
Tks ,
Zander

Hi Friends,
i Make The code but noew when i put the code without the " IF " , the code is executed very well , but when i put the cod Below , the reporte apear this error " report error:
ORA-01403: no data found "
Any Idea About it :
Tks
DECLARE
V_SQL VARCHAR2(30000);
BEGIN
-- IFI
IF :P39_INDICADOR = 'IFIPTV' THEN
V_SQL := 'select * from  P_EPS_anl_IFI '||
                ' where '||
' instr('':''||  :P39_PRACA || '':'','':''||PRACA|| '':'') > 0 '||
' AND instr('':''|| :P39_TECNO||'':'','':''||TECN||'':'') > 0' ||
' AND instr('':''|| :P39_AN_EPS||'':'','':''||EPS||'':'') > 0' ||
' AND TP_NEGOCIO = ''PAYTV'' ' ||
' AND PERIODO =  :P39_PERIODO ';
ELSIF :P39_INDICADOR = 'IFIINT' THEN
V_SQL := 'select * from  P_EPS_anl_IFI '||
                ' where '||
' instr('':''||  :P39_PRACA || '':'','':''||PRACA|| '':'') > 0 '||
' AND instr('':''|| :P39_TECNO||'':'','':''||TECN||'':'') > 0' ||
' AND instr('':''|| :P39_AN_EPS||'':'','':''||EPS||'':'') > 0' ||
' AND TP_NEGOCIO = ''INTERNET'' ' ||
' AND PERIODO =  :P39_PERIODO ';
-- REINCIDENCIA
ELSIF :P39_INDICADOR = 'REINCIDPTV' THEN
V_SQL := 'select * from  P_EPS_anl_REINCID_BC_CA '||
                ' where '||
' instr('':''||  :P39_PRACA || '':'','':''||PRACA|| '':'') > 0 '||
' AND instr('':''|| :P39_TECNO||'':'','':''||TECN||'':'') > 0' ||
' AND instr('':''|| :P39_AN_EPS||'':'','':''||EPS||'':'') > 0' ||
' AND TP_NEGOCIO = ''PAYTV'' ' ||
' AND PERIODO =  :P39_PERIODO ';
ELSIF :P39_INDICADOR = 'REINCIDPTV' THEN
V_SQL := 'select * from  P_EPS_anl_REINCID_BC_CA '||
                ' where '||
' instr('':''||  :P39_PRACA || '':'','':''||PRACA|| '':'') > 0 '||
' AND instr('':''|| :P39_TECNO||'':'','':''||TECN||'':'') > 0' ||
' AND instr('':''|| :P39_AN_EPS||'':'','':''||EPS||'':'') > 0' ||
' AND TP_NEGOCIO = ''INTERNET'' ' ||
' AND PERIODO =  :P39_PERIODO ';
-- BDS CONCL 24H
ELSIF :P39_INDICADOR = 'BDC24PTV' THEN
V_SQL := 'select * from   P_EPS_RES_PRAZO_24H '||
                ' where '||
' instr('':''||  :P39_PRACA || '':'','':''||PRACA|| '':'') > 0 '||
' AND instr('':''|| :P39_TECNO||'':'','':''||TECN||'':'') > 0' ||
' AND instr('':''|| :P39_AN_EPS||'':'','':''||EPS||'':'') > 0' ||
' AND TP_NEGOCIO = ''PAYTV'' ' ||
' AND CA_TP_OS = ''AT'' ' ||
' AND PERIODO =  :P39_PERIODO ';
ELSIF :P39_INDICADOR = 'BDC24INT' THEN
V_SQL := 'select * from   P_EPS_RES_PRAZO_24H '||
                ' where '||
' instr('':''||  :P39_PRACA || '':'','':''||PRACA|| '':'') > 0 '||
' AND instr('':''|| :P39_TECNO||'':'','':''||TECN||'':'') > 0' ||
' AND instr('':''|| :P39_AN_EPS||'':'','':''||EPS||'':'') > 0' ||
' AND TP_NEGOCIO = ''INTERNET'' ' ||
' AND CA_TP_OS = ''AT'' ' ||
' AND PERIODO =  :P39_PERIODO ';
-- ALTAS AGENDA OK PTV
ELSIF :P39_INDICADOR = 'ALTAGPTV' THEN
V_SQL := 'select * from   P_EPS_RES_CUMP_AGEN '||
                ' where '||
' instr('':''||  :P39_PRACA || '':'','':''||PRACA|| '':'') > 0 '||
' AND instr('':''|| :P39_TECNO||'':'','':''||TECN||'':'') > 0' ||
' AND instr('':''|| :P39_AN_EPS||'':'','':''||EPS||'':'') > 0' ||
' AND TP_NEGOCIO = ''PAYTV'' ' ||
' AND CA_TP_OS = ''INST'' ' ||
' AND PERIODO =  :P39_PERIODO ';
ELSIF :P39_INDICADOR = 'ALTAGINT' THEN
V_SQL := 'select * from   P_EPS_RES_CUMP_AGEN '||
                ' where '||
' instr('':''||  :P39_PRACA || '':'','':''||PRACA|| '':'') > 0 '||
' AND instr('':''|| :P39_TECNO||'':'','':''||TECN||'':'') > 0' ||
' AND instr('':''|| :P39_AN_EPS||'':'','':''||EPS||'':'') > 0' ||
' AND TP_NEGOCIO = ''INTERNET'' ' ||
' AND CA_TP_OS = ''INST'' ' ||
' AND PERIODO =  :P39_PERIODO ';
-- BDS AGENDA OK PTV
ELSIF :P39_INDICADOR = 'BDSAGPTV' THEN
V_SQL := 'select * from   P_EPS_RES_CUMP_AGEN '||
                ' where '||
' instr('':''||  :P39_PRACA || '':'','':''||PRACA|| '':'') > 0 '||
' AND instr('':''|| :P39_TECNO||'':'','':''||TECN||'':'') > 0' ||
' AND instr('':''|| :P39_AN_EPS||'':'','':''||EPS||'':'') > 0' ||
' AND TP_NEGOCIO = ''PAYTV'' ' ||
' AND CA_TP_OS = ''AT'' ' ||
' AND PERIODO =  :P39_PERIODO ';
ELSIF :P39_INDICADOR = 'BDSAGINT' THEN
V_SQL := 'select * from   P_EPS_RES_CUMP_AGEN '||
                ' where '||
' instr('':''||  :P39_PRACA || '':'','':''||PRACA|| '':'') > 0 '||
' AND instr('':''|| :P39_TECNO||'':'','':''||TECN||'':'') > 0' ||
' AND instr('':''|| :P39_AN_EPS||'':'','':''||EPS||'':'') > 0' ||
' AND TP_NEGOCIO = ''INTERNET'' ' ||
' AND CA_TP_OS = ''AT'' ' ||
' AND PERIODO =  :P39_PERIODO ';
-- OUTLIERS
ELSIF :P39_INDICADOR = 'OUTLPTV' THEN
V_SQL := 'select * from   P_EPS_RES_OUTLIER '||
                ' where '||
' instr('':''||  :P39_PRACA || '':'','':''||PRACA|| '':'') > 0 '||
' AND instr('':''|| :P39_TECNO||'':'','':''||TECN||'':'') > 0' ||
' AND instr('':''|| :P39_AN_EPS||'':'','':''||EPS||'':'') > 0' ||
' AND TP_NEGOCIO = ''PAYTV'' ' ||
' AND PERIODO =  :P39_PERIODO ';
ELSIF :P39_INDICADOR = 'OUTLINT' THEN
V_SQL := 'select * from   P_EPS_RES_OUTLIER '||
                ' where '||
' instr('':''||  :P39_PRACA || '':'','':''||PRACA|| '':'') > 0 '||
' AND instr('':''|| :P39_TECNO||'':'','':''||TECN||'':'') > 0' ||
' AND instr('':''|| :P39_AN_EPS||'':'','':''||EPS||'':'') > 0' ||
' AND TP_NEGOCIO = ''INTERNET'' ' ||
' AND PERIODO =  :P39_PERIODO ';
else
V_SQL := ' SELECT ''Consulta nao Realizada, Informe o indicador corretamente'' as AVISO FROM DUAL' ;
END IF ;
return v_sql;
end;

Similar Messages

  • Sending an email from inside a web pl/sql procedure

    Hi,
    I need to send an email to a predefined address say "[email protected]",
    and use a prefedined mail server "server11" from inside a web pl/sql procedure.
    I want this to be oblivious to the user, so no forms etc...
    Is there a way to do this using mailto:// without something popping up?
    Something like this would be first class:
    sendmail( to, from, subject, text, mailserver )
    Thanks in advance,
    Barry

    Hi,
    One needs to create a procedure or write a PL/SQL block which would do it
    Follow the commands as mentioned in this URL:
    http://www.quest-pipelines.com/newsletter-v2/smtp.htm
    http://download-east.oracle.com/otndoc/oracle9i/901_doc/appdev.901/a89852/utl_smtp.htm
    Thanks,
    Anu

  • Pl/sql block returning sql query.

    Hello,
    I am using oracle 10g apex 3.2 version.
    I am using the following return statement inside my report which is pl/sql block returning sql query.
    declare
    pid varchar2(100);
    begin
    return 'select patient_id_code from t_files_data_exp where patient_id_code not in pid';
    end;
    How am i suppose to mention the pid inside the return stmt i mean with any quotes or anything? because the above return stmt gives error
    "1 error has occurred
    Query cannot be parsed within the Builder. If you believe your query is syntactically correct, check the ''generic columns'' checkbox below the region source to proceed without parsing. The query can not be parsed, the cursor is not yet open or a function returning a SQL query returned without a value."
    Thanks

    Hello,
    I did exactly the way u told
    declare
    pid varchar2(100) := '(61092,61093)';
    begin
    return 'select patient_id_code from t_files_data_exp where patient_id_code not in ' || pid;
    end;
    patient_id_code is varchar2(100) only in table.
    For this i am getting "invalid number error".
    Thanks

  • Blocking on SQL server

    From last few days we are seeing blocking on SQL SERVER where select is taking exclusive lock and blocking the Update statement. Even Read committed snapshot Isolation is enabled.
    SQL SERVER 2012 SP2
    Windows server 2012.
    Lock pages in Memory has been enabled
    Please let me know any one can help us :)

    1) There's not really any such thing as a "blocking SQL Statement".  A query is blocked by a session because that other session holds incompatible locks.  Those incompatible locks may have been acquired by a previous query in the blocking
    session's transaction.  So the SELECT you see in the report may not be responsible for the blocking the UPDATE.
    2) In RCSI only READ COMMITTED and SNAPSHOT isolation levels use the row versioning, lock-free reading.  If you start a transaction an select a different isolation level you will acquire S locks to read data.  For instance .NET apps using
    TransactionScope, or COM+ apps using transactions can unintentionally start a SERIALIZABLE transaction.  Effectively opting-out of RCSI.  see eg
    using new TransactionScope() Considered Harmful
    David
    David http://blogs.msdn.com/b/dbrowne/

  • While local variable initialized inside try block compiler throws error???

    Check out this code where two local variables(one String and the other int type) is declared at the beginning of the method and initialized inside try block. now when i compile this app, it gives an error sayin' that Variables not been initialized. Can anyone tell me why compiler is throwin' an error message?
    Many thanks.
    import java.io.*;
    public class Test{
    public static void main(String[] args){
    String aa;
    int c;
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    System.out.println("EnterAnything:");
    try{
    aa = in.readLine();
    c = 1;
    catch(IOException e){
    System.out.println(e.getMessage());
    System.out.println(aa);
    System.out.println(c);
    }

    jfbriere,
    Thanks to u all.
    that every reference to the variable is necessarily preceded
    by execution of an assignment
    to the variable.But I've initialized the variable c and aa inside try block before referencing it as a parameter of println()?
    Can u clarify this?
    --DM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Posiibility for terminating jvm inside try block so that finally block wont

    posiibility for terminating jvm inside try block so that finally block wont execute at all ?
    But in that case what will happen?
    Is it safe for any practical situation ?
    Threads: t.stop()
    JVM : System.exit()
    which one can really help and where?

    What if security Manager comes into picture?
    class ExitCatchingSecurityManager extends SecurityManager
    public void checkExit(int status)
    Process.terminateProcessWithThreadGroup(getThreadGroup());
    throw new SecurityException();
    What if an application calls System.exit()?
    We still have one big hole in our multiprocess library. If any application calls System.exit(), the JVM terminates, and all the pseudo-processes will be destroyed with no warning. Fortunately, Java's design once again comes to our aid. Any call to System.exit() is first checked by the SecurityManager to see if the application has permission to terminate the JVM. We can install our own SecurityManager to catch the System.exit() call, disallow it, and terminate the pseudo-process instead. The SecurityManager is actually quite simple to define:
    class ExitCatchingSecurityManager extends SecurityManager
    public void checkExit(int status)
    Process.terminateProcessWithThreadGroup(getThreadGroup());
    throw new SecurityException();
    In addition, the SecurityManager should define all other checks so that they do not block pseudo-processes from running. A simple null call for all check* methods will work. We install our own SecurityManager by calling System.setSecurityManager(), i.e., by adding the following line near the startup of the multiprocess library:
    System.setSecurityManager(new ExitCatchingSecurityManager());
    The Process.terminateProcessWithThreadGroup() method is simple to define, by holding a collection of Process objects in the Process class, searching the collection to find the Process with the identical ThreadGroup, then terminating that Process.

  • How exit for a script having set of pl/sql blocks and sql queries

    HI,
    I have set of blocks and sql queries in a script.
    In some cases I want to stop the excution of next statements and blocks.
    As in pl/sql block We can use return , in case of loop we can use exit, so what is to be use in case if sql script which contain set of blocks and sql queries.
    Thanks and Regards in Advance,

    Hi,
    how to exit from the script if confirm_to_continue is set to 'N'.
    i.e in this case I want the preceding statements not to be excuted.
    Please suggest.
    script:
    declare /*BLOCK NO1*/
    begin
    IF &&confirm_to_continue = 'N'
    THEN
    ---exit from from whole script
    RETURN; -- this will only exit from this block
    END IF;
    end;
    host IF EXIST &file_name (del &file_name) ELSE (echo missing)
    declare /*BLOCK NO 2*/
    begin
    end;
    /

  • Is volatile necessary for variables only accessed inside synchronized block

    Hi,
    I am using ExecutorService to execute a set of threads. Then the calling thread needs to wait until all of them are done to reuse the thread pool to run another set of threads (so I can't use the ExecutorService.shutdown() to wait for all of the threads at this point). So I write a simple monitor as below to coordinate the threads.
    My question is: will it work? someone suggests that it might not work because it will busy spin on the non-volatile int which may or may not be updated with the current value from another thread depending on the whims of the JVM. But I believe that variables accessed inside synchronized blocks should always be current. Can anyone please help me to clarify this? Really appreciate it.
         * Simple synchronization class to allow a thread to wait until a set of threads are done.
         class ThreadCoordinator{
         private int totalActive = 0;
         public synchronized void increment(){
         totalActive++;
         notifyAll();
         public synchronized void decrement(){
         totalActive--;
         notifyAll();
         public synchronized void waitForAll(){
         while(totalActive != 0){
         try{
         wait();
         }catch (InterruptedException e){
         //ignore
         }

    Don't do that. Just save the Futures returned by the ExecutorService, and call get() on them all. This will only return when all the tasks have finished.

  • [svn:bz-trunk] 21661: Avoid calling throwNotSubscribedException() from inside synchronized blocks to prevent potential issues acquiring the lock .

    Revision: 21661
    Revision: 21661
    Author:   [email protected]
    Date:     2011-07-21 06:21:07 -0700 (Thu, 21 Jul 2011)
    Log Message:
    Avoid calling throwNotSubscribedException() from inside synchronized blocks to prevent potential issues acquiring the lock.
    Checkin-Tests: Pass
    QA: Yes
    Doc: No
    Modified Paths:
        blazeds/trunk/modules/core/src/flex/messaging/client/FlexClient.java

  • Using item values in a pl/sql block or sql query in a process

    Hi,
    I am new to apex. Developing my first application.
    I have created a form with 2 items. Based on the values in these items, when I click a button, want to execute a
    query.
    eg: emp_name(item1), deptno(item2). When I clock on find button, I want to fetch the record and disply the resultant
    columns in other created items like sal,comm etc.
    How can I do this?
    I tried the following pl/sql block in a process
    begin
    select sal,comm into p1_sal,p1_comm from emp where name=p1_name and deptno=deptno;
    end;
    But it is not accepting the page items in the block.
    How to achieve this?
    Thanks,
    Kavitha

    We have many OBEs, tutorials, etc. Please visit the <a hef="http://www.oracle.com/technetwork/developer-tools/apex/learnmore/index.html" target="_window">Learn More</a> tab of our otn site.
    This is the section of the User's Guide that discusses session state -
    -- Sharon

  • ORA-14451 : Can't do DML inside a select : PL/SQL Question

    I was just wondering if anyone had an answer to this little conundrum.
    I've got a PL/SQL function in a package which has an insert statement inside it which I only
    want to perform the insert if it's called from another PL/SQL procedure or function
    but not do the insert if it's used in a select statement.
    Does anyone know if you can work out the context in which a function is being called within
    the function as it would generally be cleaner if I only had one implementation rather than one
    for each context.
    Not desparately important but it would be nice to know....
    Thanks,
    Rob

    I don't know what the fuss it about -- but -- it seems to work for me. And I can think of a place where this would be useful. In an Oracle (ERP) Applications Alert. Alerts are limited and being able to SELECT and UPDATE a table, from inside the SELECT is useful. SQL Rules are for people who follow rules [HA :) ]
    SQL> CREATE TABLE TEST
      2  (      Id      Number
      3  ,      Num1      NUMBER
      4  );
    Table created.
    SQL> CREATE TABLE TEST2
      2  (      Id      Number
      3  ,      Num1      NUMBER
      4  );
    Table created.
    SQL>
    SQL> INSERT INTO TEST ( Id, Num1 ) VALUES ( 1, 1 );
    1 row created.
    SQL> INSERT INTO TEST ( Id, Num1 ) VALUES ( 2, 2 );
    1 row created.
    SQL> INSERT INTO TEST ( Id, Num1 ) VALUES ( 3, 3 );
    1 row created.
    SQL>
    SQL> CREATE OR REPLACE PACKAGE TEST_PK
      2  IS
      3        FUNCTION Return_X RETURN VARCHAR2;
      4  END;
      5  /
    Package created.
    SQL> show errors package test_pk;
    No errors.
    SQL>
    SQL> CREATE OR REPLACE PACKAGE BODY TEST_PK
      2  IS
      3        FUNCTION Return_X
      4            RETURN VARCHAR2
      5        IS
      6        PRAGMA AUTONOMOUS_TRANSACTION;
      7        BEGIN
      8            INSERT INTO TEST2 ( Id, Num1 ) VALUES ( 21, 21 );
      9            COMMIT;
    10            RETURN 'X';
    11        END Return_X;
    12
    13  END;
    14  /
    Package body created.
    SQL> show errors package body test_pk;
    No errors.
    SQL>
    SQL> SELECT TEST_PK.Return_X AS Test_Thing FROM TEST;
    TEST_THING
    X
    X
    X
    SQL>
    SQL> SELECT * FROM TEST2;
           ID      NUM1
           21        21
           21        21
           21        21

  • Sql greatest,decode,instr.  minimize code lines sql

    I did not write this code and please excuse me for my
    beginner questions?
    · Is there a way to make this code cleaner. Code it
    where its less lines of code?
    · Can we make the 2 conditions separate rather than a
    one after the other?
    For ex. Not like this WHEN
    INSTR(CASESTAB_1.CASENOTXT,'-ll’) > 0 THEN
    decode(CASESTAB_1.RECDT,NULL,TO_DATE('01/01/1900','mm/dd/yyyy'),CASESTAB_1.RECDT)
    · why is it in a pair like this:
    WHEN INSTR(CASESTAB_1.CASENOTXT,'-ll’) > 0 THEN
    decode(CASESTAB_1.RECDT,NULL,TO_DATE('01/01/1900','mm/dd/yyyy'),CASESTAB_1.RECDT)
    if the string to find in
    CASESTAB_1.CASENOTXT is independent to comparing date?
    Can the string search and date be separate?
    · Is the a shorter way of comparing the 4 dates.?
    Alternatives
    Greatest(
    CASE
    WHEN INSTR(CASESTAB_1.CASENOTXT,'-ll’) > 0 THEN
    decode(CASESTAB_1.RECDT,NULL,TO_DATE('01/01/1900','mm/dd/yyyy'),CASESTAB_1.RECDT)
    WHEN INSTR(CASESTAB_1.CASENOTXT,'-ss’) > 0 THEN
    decode(ERTAB.FINERDT,NULL,TO_DATE('01/01/1900','mm/dd/yyyy'),ERTAB.FINERDT)
    WHEN INSTR(CASESTAB_1.CASENOTXT,'-dd ') > 0 THEN
    decode(ERTAB.PUBLICATIONDT,NULL,TO_DATE('01/01/1900','mm/dd/yyyy'),ERTAB.PUBLICATIONDT)
    WHEN INSTR(CASESTAB_1.CASENOTXT,'-ff’) > 0 THEN
    decode(ERTAB.PUBLICATIONDT,NULL,TO_DATE('01/01/1900','mm/dd/yyyy'),ERTAB.PUBLICATIONDT)
    ELSE
    decode(CASESTAB.CPDT,NULL,TO_DATE('01/01/1900','mm/dd/yyyy'),CASESTAB.CPDT)
    END
    ,decode(CASESTAB.CPDT,NULL,TO_DATE('01/01/1900','mm/dd/yyyy'),CASESTAB.CPDT))
    sql finds the suffixes from CASESTAB_1.CASENOTXT
    AND
    compares dates 4
    · CASESTAB_1.RECDT
    · ERTAB.FINERDT
    · ERTAB.PUBLICATIONDT
    · CASESTAB.CPDT
    AND GETS THE LATER OF THE 4 DATES.
    1. \find the suffix from caseN0 field/col
    -ll
    --ss
    -dd
    -ff
    CASESTAB_1.CASENOTXT
    2. dates to find the latest date.
    · CASESTAB_1.RECDT
    · ERTAB.FINERDT
    · ERTAB.PUBLICATIONDT
    · CASESTAB.CPDT
    Using greatest function.
    3. the tables are
    1. ERTAB
    2. CASESTAB
    3. CASESTAB

    Well, I don't know how much simpler it could get and still do
    what it is designed to do. For example, the statement
    WHEN INSTR(CASESTAB_1.CASENOTXT,'-ll’) > 0 THEN
    decode(CASESTAB_1.RECDT,NULL,TO_DATE('01/01/1900','mm/dd/yyyy'),CASESTAB_1.RECDT)
    basically means that if the CASENOTXT column contains
    '-ll’, then look at the RECDT column and if it is NULL, use
    the date value of '01/01/1900', otherwise use the date value in the
    RECDT column.....
    and so on through the other WHEN clauses in your CASE
    statement. Is this what you are expecting thsi query to do?
    Phil

  • PL/SQL block to sql case

    Hello,
    I have a newbie sql question:
    I have the following pl/sql block that I want to transform in sql case code:
                 IF Num_WholesaleNonDiscountValue > 0.0 THEN
                      UsageStatus := 'CHARGE';
                      if Num_WholesaleNonDiscountValue < 1.0 then
                          WholesaleNonDiscountValue := '0' || TO_CHAR(Num_WholesaleNonDiscountValue);
                        else
                          WholesaleNonDiscountValue := TO_CHAR(Num_WholesaleNonDiscountValue);
                      end if;
                  ELSE
                      UsageStatus := 'FREE';
                      WholesaleNonDiscountValue := TO_CHAR(Num_WholesaleNonDiscountValue);
                  END IF;All I do is the following code:
    select (case when Num_WholesaleNonDiscountValue > 0.0 then
                              (case Num_WholesaleNonDiscountValue < 1.0 then  '0' || TO_CHAR(Num_WholesaleNonDiscountValue
                               else TO_CHAR(Num_WholesaleNonDiscountValue))
             else TO_CHAR(Num_WholesaleNonDiscountValue)) from table_name;I do not know how to evaluate the UsageStatus variable, where to put it in the select statement.
    This is for my learning process.
    Thanks in advanced,
    Dan
    Edited by: danut68 on Jan 13, 2010 5:52 AM

    Hi, Dan,
    I think you want something like this:
    SELECT     CASE
              WHEN  Num_WholesaleNonDiscountValue > 0
              THEN  'CHARGE'
              ELSE  'FREE'
         END                              AS UsageStatus
    ,     CASE
              WHEN  Num_WholesaleNonDiscountValue > 0
              AND   Num_WholesaleNonDiscountValue < 1
              THEN  '0'
         END || TO_CHAR (Num_WholesaleNonDiscountValue)     AS WholesaleNonDiscountValue
    FROM     table_x
    ;A CASE expression returns one value.
    In PL/SQL, you can do two or more completely separate things (set two different variables, for example) in the same IF-THEN-ELSE block.
    To get the same results in SQL requires a completely different approach.
    The clearest is to use a different CASE expression for each of the things you're trying to do, as I did above. The WHEN clauses of those CASE statements may be very similar, even identical.
    Sometimes you can factor out some of the logic (using a sub-query, perhaps) so that the logic that has to be repeated in each CASE expression is very simple.
    Another option for setting two variables is to have a single CASE expression that returns a string wihich is the concatenation of two different varibales, which you later parse into two separate variables. I would do this only as a last resort.

  • Anonymous Block in SQL Developer

    I am using SQL Developer 3.1x and trying to run a pretty simple Anonymous block and am having trouble declaring a variable. This block runs successfully:
    set SERVEROUTPUT on
    --declare
    -- V_CRT := CHR(13);
    begin
    for t in (select owner, table_name from dba_tables where owner = 'ABC123)
    LOOP
    DBMS_STATS.GATHER_TABLE_STATS(t.owner, t.table_name);
    end loop;
    DBMS_OUTPUT.PUT_LINE('Statistics Calculations complete');
    DBMS_OUTPUT.PUT_LINE('Begin Record Counts');
    -- DBMS_OUTPUT.PUT_LINE(v_crt);
    -- DBMS_OUTPUT.PUT_LINE(V_CRT);
    end;
    If I remove my comments in an effort to include my Declare statement, I receive: PLS-00103: Encountered the symbol "=" when expecting one of the following
    How do I declare / initialize the variable "v_crt"? Admittedly this is a VERY basic Block but I just started to build out a more "robust" procedure and am getting stumped.
    Thank you for your help!

    The symbol *:=* is for assignment, not variable declaration. Just give the variable name and then its type, like this:DECLARE
      V_CRT VARCHAR2(13);You can give it a default value if you want to.DECLARE
      V_CRT VARCHAR2(13) := 'Hello';Looks like you want it to be a carriage return character.DECLARE
      V_CRT VARCHAR2(1) := CHR(13);

  • Debugging PL/SQL blocks in SQL Developer

    Is there any way to debug blocks of PL/SQL in SQL Developer by setting breakpoints in the code? I'm using SQL Developer.
    I'm trying to debug some fairly complex PL/SQL blocks - they are not procedures or functions and so I'm unable to run them in debug mode.
    p.s. Apologies should have posted this in the database forum really.
    Edited by: Antilles on Sep 10, 2008 1:12 AM

    Hello,
    Sure you can, take a look at the following two links -
    http://sueharper.blogspot.com/2006/07/remote-debugging-with-sql-developer_13.html
    http://www.oracle.com/technology/oramag/oracle/08-may/o38browser.html
    Hope this helps,
    John.
    http://jes.blogs.shellprompt.net
    http://www.apex-evangelists.com

Maybe you are looking for

  • Is PE10 compatible with Windows 8? Having trouble with the organizer.

    Is PE10 compatible with Windows 8? Having trouble with the organizer

  • Required help for badi for GL tab in MIRO transaction

    Hi, I am working in MIRO transaction. I am having a requirement as below: While creating invoices, In the gl tab when we enter gl account number system should populate Tax jurisdiction code by default. I am using BADI EXTENSION_US_TAXES method MM_ITE

  • Profit Center in New GL with Document Splitting

    Hi As per my understanding, from ECC 5.0 onwards you are forced to use New GL, and we are also planning to use Document splitting as some of the period end closing of profit center accounting are avoided. Further I want to add that since document spl

  • Flicking colors !!

    Hello, I have a concern that takes my mind for several days I made a 3D animation in 3DSMax, I recorded in sequence TGA. So imported into After Effects for post-production, and there, horror, watching the footage, I see that the colors "flash" in pla

  • ROW_NUMBER and paging

    hello A simple question on paging/ROW_NUMBER. The following sql is fine. select PersonId, Logon, IsSuspended, ROW_NUMBER() OVER(ORDER BY Logon ASC) RowNumber FROM Person; Now to do paging (retrieve only record 1 to 10), I added the WHERE clause: sele