Booleans API Functions into SQL SELECT

Hello,
our API is using a huge set of boolean «is_{what we want to check}» functions. These simple atomic functions are used into more sophisticated PL/SQL funcs or procs.
Sometime, we need to use these bool funcs directly into our SQL queries.
Here is a simplified example we want:
SELECT id1, id2, is_valid(id1, id2)
FROM table
WHERE ... stuff ...;
or
SELECT col1, col2, ...
FROM table
WHERE is_valid(id1, id2) IS TRUE ;
or
SELECT col1, col2, ...
FROM table
WHERE is_valid(id1, id2) = TRUE ;
to be valid queries....
I know that booleans aren't supported natively in the SQL, I created a function that translate bool to char:
FUNCTION bool_to_char (p_bool IN BOOLEAN)
RETURN VARCHAR2
IS
v_retour VARCHAR2 (5);
BEGIN
v_retour := CASE p_bool
WHEN TRUE
THEN 'TRUE'
WHEN FALSE
THEN 'FALSE'
END;
RETURN v_retour;
END;
So, when I call this func into my sql, it's not working anymore:
SELECT id1, id2, bool_to_char(is_valid(id1, id2))
FROM table
WHERE ... stuff ...;
or
SELECT col1, col2, ...
FROM table
WHERE bool_to_char(is_valid(id1, id2)) = 'TRUE';
I'm searching for a solution to make this possible... The only fast solution that came in my mind is to encapsulate every boolean functions to return a corresponding varchar value. Not that good....
Any ideas or suggestions?

SQL standards have been developed over the years and whilst some vendors have tweaked SQL functionality to make their database better than others, one thing that is not part of SQL standards is support for BOOLEAN. 3GL and 4GL languages most often support boolean values, which are represented internally as a binary number.
For those interested, in some languages the BOOLEAN is represented as -1 for TRUE and 0 for FALSE. In binary, -1 is represented as all the bits set to 1 whilst 0 is all the bits set to 0. There was a nice feature in one of the BASIC versions (I think it was BBC Basic if I remember correctly) that allowed you to use booleans within assignments such as...
x := y + (z AND (y < 100))If the "y<100" condition evaluated to TRUE, this would translate as...
x := y + (z AND TRUE)which, in binary terms (let's assume all numbers are single bytes for illustrative purposes) would be...
x := y + (z AND 11111111)The "z AND 11111111" would perform a logical AND between the z value and the binary 11111111 resulting in a value of z... giving...
x := y + zIf the condition evaluated to false on the other hand it would go as follows...
x := y + (z AND FALSE)
x := y + (z AND 00000000)So, "z AND 00000000" would logically AND to give a result of 0 and thus giving...
x := ySo it was useful to use in conditional arithmetic, avoiding having to put IF statements in the code.
Getting back to the thread...
Using PL/SQL functions so extensively in SQL is a bad idea as it will inevitably cause a lot of context switching between the SQL and PL/SQL engines. This will have a noticable effect on performance of queries. Where possible, if the test can be done within SQL, then it should be done there rather than calling PL/SQL.
;)

Similar Messages

  • Calling a BOOLEAN returning function from SQL

    Hello All,
    I have created below function which return BOOLEAN value :
    CREATE OR REPLACE FUNCTION FUNC_1
    P_EMPID IN emp.empno%type
    )RETURN BOOLEAN
    AS
    L_VAR NUMBER;
    BEGIN
    SELECT 1 INTO L_VAR
    FROM EMP
    WHERE EMPNO = P_EMPID;
    IF L_VAR = 1 THEN
    RETURN TRUE;
    ELSE
    RETURN FALSE;
    END IF;
    END;Now I want to call this function from SELECT but I know that SQL does not support BOOLEAN value so I tried in other way i.e. via CASE
    SELECT CASE FUNC_1(7788)
           WHEN TRUE THEN 'TRUE'
           WHEN FALSE THEN 'FALSE'
           ELSE 'NULL'
           END CASE
    FROM DUALBut it is giving me error "ORA-00904: "FALSE": invalid identifier'
    How can I achieve this ?
    Thanks & Regards,
    Rakesh

    Hi Rakesh,
    Why cant you try something like this, When BOOLEAN type is not supported in SQL.
    Here I have made the return value a number. And, at case comparison, we get the BOOLEAN
    result as TRUE of FALSE.
    CREATE OR REPLACE FUNCTION func_1 (p_empid IN emp.empno%TYPE)
       RETURN NUMBER
    AS
       l_var   NUMBER;
    BEGIN
       SELECT count(*)
         INTO l_var
         FROM emp
        WHERE empno = p_empid;
       IF l_var = 1
       THEN
          RETURN 1;
       ELSE
          RETURN 0;
       END IF;
    END;And,
    SELECT CASE func_1 (55656)
              WHEN 1
                 THEN 'TRUE'
              WHEN 0
                 THEN 'FALSE'
           END
      FROM DUAL;Which return TRUE if the Employee Number Exists and FALSE if doesnot.
    Thanks,
    Shankar.

  • Problem in Calling a function in sql statement.

    hi,
    I am having a function ops_safex_utl.EDIT_ASSC_CNTR_LOG(id number);
    when i am trying to use this inside a sql statement as shown below, it is giving error (exception part inside the function).
    SQL> select ops_safex_utl.EDIT_ASSC_CNTR_LOG(688) from dual;
    OPS_SAFEX_UTL.EDIT_ASSC_CNTR_LOG(688)
    -1 (-- exception )
    when i am trying to call this function using a PL/SQL Block then it is woking fine as shown below.
    SQL> DECLARE
    2
    3 x NUMBER(2);
    4
    5 BEGIN
    6
    7 x := ops_safex_utl.EDIT_ASSC_CNTR_LOG(688);
    8
    9 dbms_output.put_line('x '||' '||x);
    10
    11 END;
    12 /
    hi
    insert into ops_assc_cntr_log
    insert into ops_ac_ex_gratia_log
    insert into ops_ac_sls_dlvry_slab_dtls_log
    insert into ops_ac_sls_dlvry_slab_dtls_log
    insert into ops_ac_sls_dlvry_slab_dtls_log
    insert into ops_ac_sls_dlvry_slab_dtls_log
    insert into ops_ac_sls_dlvry_slab_dtls_log
    insert into ops_ac_spl_acct_dtls_log
    insert into ops_ac_spl_acct_slab_dtls_log
    insert into ops_ac_spl_acct_slab_dtls_log
    insert into ops_ac_spl_acct_slab_dtls_log
    insert into ops_ac_spl_acct_dtls_log
    insert into ops_ac_spl_acct_slab_dtls_log
    insert into ops_ac_spl_acct_slab_dtls_log
    insert into ops_ac_spl_acct_slab_dtls_log
    update ops_assc_cntr
    success
    x 0
    PL/SQL procedure successfully completed.
    when i am trying to run the SQL statement it is returning a exception from the function.
    SELECT ops_safex_utl.EDIT_ASSC_CNTR_LOG(688) from dual --it is returning -1 (i.e exception).
    My sql client version is 9.2.0.1.0. and my data base version is 10.2.0.2.0.
    Please advice.

    Could you post the exception handler within the function.
    It sounds like you return -1 if you experience an error - it would be easier to determine the cause of the problem if you return the Oracle error details, E.g:
    EXCEPTION
       WHEN OTHERS THEN
          RETURN dbms_utility.format_error_backtrace;This will then return a meaningful error, identifying exactly what is causing the error to be generated.

  • IF function in a Select

    I would like to know if there is the possibility to use an IF function into a Select.
    I would like to count a column and IF this counter is greater than 1 the select should return a NULL value,or a value that I can give, IF the counter is
    0 then the select should give the value of the column.
    The column is a CLOB data
    :)

    A part of the select I have is:
    SELECT PCMS_CHDOC_DATA.CH_DOC_ID,
    PCMS_CHDOC_DATA.CH_UID,
    PCMS_CHDOC_DATA.CH_DOC_TYPE,
    PCMS_CHDOC_DATA.STATUS,
    PCMS_CHDOC_DATA.TOOL,
    PCMS_CHDOC_DATA_2.CH_DOC_ID,
    PCMS_CHDOC_DATA_2.CH_UID,
    PCMS_CHDOC_DATA_2.CH_DOC_TYPE,
    PCMS_CHDOC_DATA_2.STATUS,
    PCMS_CHDOC_DATA_2.TOOL,
    PCMS_CHDOC_DATA_2.DROP_TRIGGER,
    PCMS_CHDOC_DETAIL_DESC.CH_DOC_ID,
    PCMS_CHDOC_DETAIL_DESC.CH_UID,
    PCMS_CHDOC_DETAIL_DESC.FILE_VERSION,
    COUNT(CAST(PCMS_CHDOC_DETAIL_DESC.DATA AS VARCHAR2(3500)))
    FROM PCMS_CHDOC_DATA,
    PCMS_CHDOC_DATA PCMS_CHDOC_DATA_2,
    PCMS_CHDOC_DETAIL_DESC
    WHERE PCMS_CHDOC_DATA.TOOL='ICD'
    AND PCMS_CHDOC_DATA.CH_DOC_ID = PCMS_CHDOC_DATA_2.DROP_TRIGGER
    AND PCMS_CHDOC_DATA.CH_DOC_ID = PCMS_CHDOC_DETAIL_DESC.CH_DOC_ID
    GROUP BY PCMS_CHDOC_DATA.CH_DOC_ID,
    PCMS_CHDOC_DATA.CH_UID,
    PCMS_CHDOC_DATA.CH_DOC_TYPE,
    PCMS_CHDOC_DATA.STATUS,
    PCMS_CHDOC_DATA.TOOL,
    PCMS_CHDOC_DATA_2.CH_DOC_ID,
    PCMS_CHDOC_DATA_2.CH_UID,
    PCMS_CHDOC_DATA_2.CH_DOC_TYPE,
    PCMS_CHDOC_DATA_2.STATUS,
    PCMS_CHDOC_DATA_2.TOOL,
    PCMS_CHDOC_DATA_2.DROP_TRIGGER,
    PCMS_CHDOC_DETAIL_DESC.CH_DOC_ID,
    PCMS_CHDOC_DETAIL_DESC.CH_UID,
    PCMS_CHDOC_DETAIL_DESC.FILE_VERSION
    but it doesn't work because of the CLOB data.
    At the moment I didn't write the CASE bacause I would like first to convert the CLOB data.
    I wrote VARCHAR2(4000) but it doesn't work,
    The select I would like is that if the count return 1 the value is returned instead if the counter is greater than 1 is returned a null or a string more or less like in COALESCE function

  • Calling Function in  SQL

    Hi,
    I wrote a function like below:
    create or replace function test_ref_cur
    return sys_refcursor is
    l_ref_cur sys_refcursor;
    begin
    open l_ref_cur for
    select 'Tom' ename from dual
    union
    select 'John' from dual
    union
    select 'Jim' from dual;
    return l_ref_cur;
    end;
    When I call this function in Sql: Select test_ref_cur from dual; it returns 1 row as below
    Test_REF_CURSOR
    (CURSOR)
    I can see the data only when I double click on (CURSOR).
    Is there a way to show the data directly in the result window: like
    Ename
    Jim
    Tim
    John
    Thanks,
    DD

    dd_ram wrote:
    Hi,
    I wrote a function like below:
    create or replace function test_ref_cur
    return sys_refcursor is
    l_ref_cur sys_refcursor;
    begin
    open l_ref_cur for
    select 'Tom' ename from dual
    union
    select 'John' from dual
    union
    select 'Jim' from dual;
    return l_ref_cur;
    end;
    When I call this function in Sql: Select test_ref_cur from dual; it returns 1 row as below
    Test_REF_CURSOR
    (CURSOR)
    I can see the data only when I double click on (CURSOR).
    Is there a way to show the data directly in the result window: likeYou need to understand what a ref cursor is.
    The reason your result is showing "(CURSOR)" (I assume you're using SQL Developer or TOAD) is that the returned result is a cursor, not a set of data. Only when you double click on it, will it actually use that cursor to fetch the data back.
    For more understanding, read the following article...
    PL/SQL 101 : Understanding Ref Cursors

  • How can i migrate Power Builder 8.0 Function into oracle PL/SQL

    Hi Oracle Experts...
    How can i migrate Power Builder 8.0 Function into oracle PL/SQL.. I had migrate some of the coding from PB to PL/SQL. But i don't know how can i convert PB structure(here structure is a data type) into oracle PL/SQL.
    Instead of structure what is the equivalent in oracle plsql
    Below i pasted my POWER BUILDER FUNCTION:
    Long ll_perd,ll_lnperd,ll_mon,ll_effmon,ll_instno,ll_odno
    Decimal{5} ldl_actual,ldl_diff,ldl_inst
    Datetime ldt_first,ldt_exp,ldt_oddt, ldt_lastprod
    String ls_instmode,ls_inst
    str_batch lstr_od //Structure to store odamt and oddate
    Select pay_c_final,lon_d_expiry, lon_d_lastprod
    Into     :ls_inst,:ldt_exp, :ldt_lastprod
    From      loan_mast
    Where branch_c_code = :gs_branch and
              act_c_type      = :as_actype and
              act_c_no           = :as_acno;
    If Sqlca.Sqlcode = -1 Then
         f_message('FT-0189',Sqlca.Sqlerrtext)
         lstr_od.batchslno = -1
         Return lstr_od
    End If
    If adt_prodt > ldt_exp Then
         Select Ceil(months_between(:adt_prodt,:ldt_exp)) Into :lstr_od.batchslno From dual;
         lstr_od.cheqdt = ldt_exp
         lstr_od.batchslno = DaysAfter(Date(ldt_lastprod), Date(adt_prodt))
    Else
         If ls_inst = 'N' Then
              If adt_prodt > ldt_exp Then
                   Select Ceil(months_between(:adt_prodt,:ldt_exp)) Into :lstr_od.batchslno From dual;
                   lstr_od.cheqdt = ldt_exp
              Else
                   lstr_od.batchslno = 1
              End If
         ElseIf ls_inst = 'Y' Then
              Select first_d_due,lon_c_instperd,lon_n_perd
              Into     :ldt_first,:ls_instmode,:ll_lnperd
              From     loan_mast
              Where branch_c_code = :gs_branch and
                        act_c_type      = :as_actype and
                        act_c_no          = :as_acno;
              If Sqlca.Sqlcode = -1 Then
                   f_message('FT-0189',Sqlca.Sqlerrtext)
                   lstr_od.batchslno = -1
                   Return lstr_od // Return Structure
              End If
              Select Ceil(months_between(:adt_prodt,:ldt_first)) Into :ll_mon from dual;
              If ll_mon > 0 Then
                   Select Nvl(ln_n_balance,0),Nvl(ln_n_instlamt,0),Nvl(ln_n_instlno,0)
                   Into     :ldl_actual,:ldl_inst,:ll_instno
                   From     loan_inst_sch
                   Where act_c_type = :as_actype and
                             act_c_no     = :as_acno and
                             ln_d_effdate = (Select Max(ln_d_effdate)
                                                           From     loan_inst_sch
                                                           Where act_c_type = :as_actype and
                                                                     act_c_no     = :as_acno and
                                                                     ln_d_effdate < :adt_prodt);
                   If Sqlca.Sqlcode = -1 Then
                        f_message('FT-0224', Sqlca.Sqlerrtext)
                        lstr_od.batchslno = -1
                        Return lstr_od
                   ElseIf Sqlca.Sqlcode = 100 Then
                        lstr_od.batchslno = 1
    *                    Return lstr_od*
                   End If
                   If adl_bal > ldl_actual Then
                        If ldl_inst > 0 Then
                             lstr_od.batchslno = (adl_bal - ldl_actual) / ldl_inst
                        End If
                   Else
                        lstr_od.batchslno = 1
                   End If     
                   If lstr_od.batchslno = 0 Then lstr_od.batchslno = 1
                   //For full OD
                   If ll_mon > ll_lnperd Then
                        lstr_od.batchslno = (ll_mon - ll_lnperd) + lstr_od.batchslno
                   End If
                   If ls_instmode = 'Q' Then
                        lstr_od.batchslno = lstr_od.batchslno * 3
                   ElseIf ls_instmode = 'H' Then
                        lstr_od.batchslno = lstr_od.batchslno * 6
                   ElseIf ls_instmode = 'Y' Then
                        lstr_od.batchslno = lstr_od.batchslno * 12
                   End If
                   Select :adt_prodt - :lstr_od.batchslno Into :lstr_od.cheqdt From dual;
                   If ls_instmode = 'M' Then
                        ll_odno = ll_instno - lstr_od.batchslno // To get OD Date
                        Select ln_d_effdate
                        Into     :lstr_od.cheqdt
                        From     loan_inst_sch
                        Where act_c_type = :as_actype and
                                  act_c_no     = :as_acno and
                                  ln_n_instlno = :ll_odno;
                        If Sqlca.Sqlcode = -1 Then
                             f_message('FT-0224', + Sqlca.Sqlerrtext)
                             lstr_od.batchslno = -1
                             Return lstr_od
                        End If
                   End If
              Else
                   lstr_od.batchslno = 1
              End If
         End If
    End if
    Return lstr_od
    Thanks in adance
    Arun M M

    What are you going to return the structure to? What I would normally use here if the code was going to be used by other PL/SQL would be a PL/SQL object type.
    However, if PowerBuilder is still in the equation (you're moving the logic to PL/SQL but keeping PowerBuilder for the GUI ), then you'll have to return something else, because PowerBuilder doesn't understand PL/SQL object types. Perhaps passing a REF CURSOR as a OUT argument and populating it from the procedure. PowerBuilder could then retrieve the result of the procedure using a stored procedure based DataWindow.

  • How to Select from Oracle 8i database and insert into Sql Server 2005 datab

    Hi how to Select from Oracle 8i and insert into Sql Server 2005.
    Source db as Oracle 8i
    Target db as Sql Server 2005.
    I need to select one table data from Oracle 8i & insert into Sql Server 2005
    Thanks

    Thanks Khan..
    Is there is any query (OPENQUERY) available for that?
    Regards..

  • Function call from SQL SELECT

    I am calling a function from a SELECT statement. I want to call this function 3 times in the same select statement, to get 3 different levels in a hierarchy for a particular licence number. This function has a hierarchy query using a START WITH.. CONNECT BY clause and a SYS_CONNECT_BY_PATH function to get the full hierarchy path in the SELECT clause. Then the SUBSTR/INSTR functions are used to get the 1st, 2nd or 3rd element in the hierarchy.
    The query is now running very slowly. Is there a better way of doing this -- should I just use in-line views in the SQL statement. Am I trying to do something stupid!!?

    a) you are calling the PL/SQL engine from the SQL engine 3 times for every row of data you are processing. This WILL have a performance impact.
    b) If you can do something purely in SQL then do it that way as this will be the most peformant.
    If you post an example of your data (provide us with CREATE TABLE/INSERTs or WITH statement) and an example of what you are trying to get as output then we may be able to help.

  • How to select data from 3rd row of Excel to insert into Sql server table using ssis

    Hi,
    Iam having Excel files with headers in first two rows , i want two skip that two rows and select data from 3rd row to insert into Sql Server table using ssis.3rd row is having column names.

                                                         CUSTOMER DETAILS
                         REGION
    COL1        COL2        COL3       COL4           COL5          COL6          COL7
           COL8          COL9          COL10            COL11      
    1            XXX            yyyy         zzzz
    2            XXX            yyyy        zzzzz
    3           XXX            yyyy          zzzzz
    4          XXX             yyyy          zzzzz
    First two rows having cells merged and with headings in excel , i want two skip the first two rows and select the data from 3rd row and insert into sql server using ssis
    Set range within Excel command as per below
    See
    http://www.joellipman.com/articles/microsoft/sql-server/ssis/646-ssis-skip-rows-in-excel-source-file.html
    Please Mark This As Answer if it solved your issue
    Please Mark This As Helpful if it helps to solve your issue
    Visakh
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • SQL: select into

    Hello. In both sybase and sql server, you
    can create on-the-fly tables in sql by
    simply doing a
    select column
    into newtable
    from oldtable
    where blahblahblah
    When I do the same in sql (not pl/sql)
    I get the following error:
    SQL> select empno
    2 into myemp
    3 from emp
    4 where ename = 'SMITH';
    into myemp
    ERROR at line 2:
    ORA-00905: missing keyword
    Is it possible to do this kind of select into
    in Oracle?
    Thanks!

    I believe the syntax you're looking for is:
    create table <tablename>
    as select *
    from (<original statement>)
    More examples are available in the Migration Workbench docs

  • How to simplify this query into simple sql select stmt

    Hi,
    Please simplify this query
    I want to convert this query into single select statement. Is it possible?
    If uarserq_choice_ind is not null then
    Select ubbwbst_cust_code
    From ubbwbst,utrchoi
    Where utrchoi_prop_code=ubbwbst_cancel_prod
    Else
    Select max(utvsrvc_ranking)
    From utvsrvc,ubbwbst
    Where utvsrvc_code=ubbwbst_cancel_prod
    End if

    Though i have not tested this statement if mine ...but you can try at your end and let me know whether u got the desired output or not.
    Select Decode(uarserq_choice_ind,Null,max_rnking,ubbwbst_cust_code)uarserq_chc
    from
    (Select max(utvsrvc_ranking)max_rnking,uarserq_choice_ind,ubbwbst_cust_code
    From utvsrvc,ubbwbst,utrchoi
    Where utvsrvc_code=ubbwbst_cancel_prod
    Or utrchoi_prop_code=ubbwbst_cancel_prod
    group by uarserq_choice_ind,ubbwbst_cust_code)
    Best of Luck.
    --Vineet                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Unable to perform "insert into table select ...." using DBF_JDBC30

    below i post my code :
    import java.util.*;
    import java.sql.*;
    import java.io.*;
    import com.hxtt.sql.*;
    public class backofficeDbfVerification {
    public backofficeDbfVerification(String path) throws SQLException {
    Properties prop = new Properties();
    prop.setProperty("user", "");
    prop.setProperty("OtherExtensions","true");
    prop.setProperty("Version Number", "03");
    try {
    Class.forName("com.hxtt.sql.dbf.DBFDriver").newInstance();
    connection = DriverManager.getConnection("jdbc:DBF:/"+path, prop);
    catch (ClassNotFoundException classnotfoundexception) {
    System.out.println("could ot find HXTT class, make sure the classpath have been defined in your system !");
    catch(Exception e) {
    System.out.println(e.getMessage());
    public void createBadRecord(String table, String newtable, int blth) throws SQLException {
    Statement stmt = connection.createStatement();
    String insert = "insert into \""+newtable+"\" select * from \""+table+"\"";
    boolean bInsert = stmt.execute(insert);
    stmt.close();
    public static void main (String args[]) {
         String path = "C:\\MASTER\\SOURCEDATA\\AREA";
    try {
    backofficeDbfVerification test = new backofficeDbfVerification(path);
    test.createBadRecord("source\\area\\123.AA2","source\\area\\others\\89964568.AA1");
    catch(SQLException sqx) {
    System.out.println("Error "+sqx.getMessage());
    i try to perform simple query : insert into tablea select from tableb which has same structure. the source table has only 9 rows, but the process ran very long time, no error message raised,it just run and never end (which make me upset for the whole day).
    i have tried another simple query : insert into table1 values (1,2) using the same driver and execute successfully.
    is it becoz of function limitation since i used evaluation copy ?

    Copy the answer from HXTT's support forum:
    No function limitation. I just tested:
    create table testa1 select * from test;
    insert into testa1 select * from test;
    Passed.
    I also run your backofficeDbfVerification.java sample. Passed too. I'm using the same code as you. The difference is only my 89964568.AA1 and 123.AA2 is simulative tables files. If possible, please zip your 89964568.AA1 and 123.AA2 and email to [email protected] Thanks.
    BTW, I pasted the little modified backofficeDbfVerification.java below:
    import java.sql.*;
    import java.util.*;
    public class backofficeDbfVerification {
    Connection connection;
    public backofficeDbfVerification(String path) throws SQLException {
    Properties prop = new Properties();
    prop.setProperty("user", "");
    prop.setProperty("OtherExtensions", "true");
    prop.setProperty("Version Number", "03");
    try {
    Class.forName("com.hxtt.sql.dbf.DBFDriver").newInstance();
    connection = DriverManager.getConnection("jdbc:DBF:/" + path, prop);
    catch (ClassNotFoundException classnotfoundexception) {
    System.out.println("could ot find HXTT class, make sure the classpath have been defined in your system !");
    catch (Exception e) {
    System.out.println(e.getMessage());
    public void createBadRecord(String table, String newtable) throws
    SQLException {
    Statement stmt = connection.createStatement();
    String insert = "insert into \"" + newtable + "\" select * from \"" +
    table + "\"";
    boolean bInsert = stmt.execute(insert);
    stmt.close();
    public static void main(String args[]) {
    String path = "f:\\dbffiles";
    try {
    backofficeDbfVerification test = new backofficeDbfVerification(path);
    test.createBadRecord("source\\area\\123.AA2",
    "source\\area\\others\\89964568.AA1");
    catch (SQLException sqx) {
    System.out.println("Error " + sqx.getMessage());
    }

  • Use of boolean returning functions in a project

    Hello all gurus,
    in my project, we have a fairly important packaged functions that return boolean values. Working with these ones in pl/sql is very fine. But sometimes we need to reuse these functions in SQL, but no luck because bools are usable under pl/sql only and can't interact in any way in SQL statements. So the workaround should be to use these functions to return us some Y/N or 1/0 to emulate boolean behavior in SQL statements.
    Here what i tested with not luck:
    -- not work
    select r.role, sys.diutil.bool_to_int(dbms_session.is_role_enabled(r.role)) as is_role_enabled
    from   dba_roles r;
    -- not work
    select r.role
    from   dba_roles r
    where  sys.diutil.bool_to_int(dbms_session.is_role_enabled(r.role)) = 1;
    -- not work
    select t1.id,
           bool_to_char(my_bool_func(t1.x, t1.y, ...)) as is_something
    from   t1;
    -- not work
    select t1.id,
           sys.diutil.bool_to_int(my_bool_func(t1.x, t1.y, ...)) as is_something
    from   t1;The odd wrapping trick as a last resort solution is working....
    -- Works! Seems the only way, but a lot of wrapping work...
    create or replace function my_bool_func_wrap(p_x number, p_y number, ...) return varchar2 as
    begin
       return bool_to_char(my_bool_func(p_x, p_y, ...));
    end;
    select t1.id,
           my_bool_func_wrap((t1.x, t1.y, ...)) as is_something
    from   t1;I read a lot, but no elegant and working way.
    Is there a more standard, elegant universal way to call bool functions from SQL?
    Is creating a custom type visible and usable from both pl/sql and sql, if possible, a way to go?
    Any other pointers?
    For new development, is it good to make my boolean type returning functions using SQL compatible type like CHAR (Y/N) or NUMBER (1/0) ? It will make us less wrapping job, but more and less elegant bool handling code on the pl/sql side.
    What is the goal to have bool only in pl/sql and not usable in SQL? It's kind of a feature incompatibility in the same product. Strange...
    Thanks a lot
    Bruno

    brlav wrote:
    Finally, I'll have to dump the BOOLEAN return type to all our boolean functions and return char instead. With this I will be able to call then from SQL.... From this perspective, BOOLEAN is useless.I would not say that. Let's assume that you implement boolean in SQL as a single byte character string containing either Y or N, enforce that with a constraint and also add a not-null constraint to it.
    You simply define two PL functions (not usable from SQL) that deals with the conversion. You use the one function to change boolean to char before hitting the SQL engine, and the other to convert char to boolean when getting data from the SQL engine.
    As I/O routines are modularised, it means that you need to deal with these conversions once only when writing and once only when reading (per module).
    Simple example:
    SQL> create or replace function to_bool( c varchar2 ) return boolean is
      2  begin                                                            
      3          return( c = 'Y' );                                       
      4  end;                                                             
      5  /                                                                
    Function created.
    SQL>
    SQL> create or replace function bool_to_char( b boolean ) return varchar2 is
      2  begin
      3          if b then
      4                  return( 'Y' );
      5          else
      6                  return( 'N' );
      7          end if;
      8  end;
      9  /
    Function created.
    SQL>
    SQL> declare
      2          i       integer;
      3          b       boolean;
      4          flag    all_tables.temporary%type;
      5          tab     all_tables%rowtype;
      6  begin
      7          flag := bool_to_char(true);  
      8          select count(*) into i from all_tables where temporary = flag;
      9
    10          select t.* into tab from all_tables t where rownum = 1;
    11          b := to_bool( tab.temporary );
    12  end;
    13  /
    PL/SQL procedure successfully completed.
    SQL>

  • Want to convert function in SQL Server 2000

    Hi ,
    i am writing this function in oracle.Could you please convert this function in SQL Server 2000 because i am new in this and dont know how to use decode function in sql.
    Please following is the code for oracle.
    CREATE OR REPLACE function fun ( localex varchar2,titlex varchar2)
    return number
    as  x number;
    begin
    select sum ( decode (count (username),max(prereq_count),1,0) ) x into x from
       SELECT
                       prereq_count,
                       username
                 FROM
                         table1
    group by     username ;
    return x;
    end fun;
    Regards
    Vishal

    Just take a look example below might give you idea :
    create or replace function f_makeAddress_tx (
    i_address_tx VARCHAR2,
    i_city_tx VARCHAR2,
    i_state_tx VARCHAR2,
    i_zip_tx VARCHAR2)
    return VARCHAR2
    is
    e_badZip EXCEPTION; u279E8
    pragma EXCEPTION_init(e_badZip,-20998); u279E9
    v_out_tx VARCHAR2(256);
    begin
    p_validateZip (i_zip_tx); u279E12
    v_out_tx:= i_address_tx||u2019, u2018|| u279E13
    i_city_tx ||u2019, u2018||
    i_state_tx ||u2019, u2018||
    i_zip_tx;
    return v_out_tx; u279E17
    exception
    when e_badZip then u279E19
    return i_zip_tx || u2018: Invalid zip code.u2019;
    end;
    Regards,
    Clint

  • Report- Pl/sql function returning sql query parsing page items as text?

    Hi Team,
    I am facing a strange issue .
    I have four page items namely
    1)JOB_CODE
    2)MIN_EXP
    3) MAX_EXP
    4) SOURCES1
    I have a report of the type "Pl/sql function returning sql query"
    declare
    v_sql varchar2(4000);
    begin
    if (:JOB_CODE IS NOT NULL and :MIN_EXP IS NOT NULL and :MAX_EXP IS NOT NULL and :SOURCES1 IS NOT NULL) then
    v_sql:= 'select v_candidate_id, v_fname,v_current_employer,v_Experience_years from candidature where V_REQUIREMENT = :JOB_CODE and v_experience_years >= :MIN_EXP and v_experience_years <= :MAX_EXP and source like ' || '''' || '%'|| ':SOURCES1' || '%' || '''';
    elsif (:JOB_CODE IS NULL and :MIN_EXP IS NOT NULL and :MAX_EXP IS NOT NULL and :SOURCES1 IS NOT NULL) then
    v_sql := 'select v_candidate_id, v_fname,v_current_employer,v_Experience_years from candidature where v_experience_years >= :MIN_EXP and v_experience_years <= :MAX_EXP and source like ' || '''' || '%'|| ':SOURCES1' || '%' || '''';
    elsif (:MIN_EXP IS NULL and :JOB_CODE IS NOT NULL and :MAX_EXP IS NOT NULL and :SOURCES1 IS NOT NULL) then
    v_sql := 'select v_candidate_id, v_fname,v_current_employer,v_Experience_years from candidature where v_experience_years <= :MAX_EXP and V_REQUIREMENT = :JOB_CODE and source like ' || '''' || '%'|| ':SOURCES1' || '%' || '''';
    elsif (:MAX_EXP is null and :JOB_CODE IS NOT NULL and :MIN_EXP IS NOT NULL and :SOURCES1 IS NOT NULL) then
    v_sql := 'select v_candidate_id, v_fname,v_current_employer,v_Experience_years from candidature where V_REQUIREMENT = :JOB_CODE and v_experience_years >= :MIN_EXP and source like ' || '''' || '%'|| ':SOURCES1' || '%' || '''';
    end if;
    insert into query_list values (v_sql);
    insert into debug values (:JOB_CODE , :MIN_EXP , :MAX_EXP , :SOURCES1);
    return v_sql;
    end;
    Please not that I am insertin the query into a table called Query_list and the page item values into the table called Debug thru the pl/sql function which returns teh query.
    Now I select the data from the debug tables.
    select unique(query) from query_list;
    select v_candidate_id, v_fname,v_current_employer,v_Experience_years from candidature where V_REQUIREMENT = :JOB_CODE and v_experience_years >= :MIN_EXP and v_experience_years <= :MAX_EXP and source like '%:SOURCES1%'
    select * from debug;
    JOBCODE     MINEX     MAXEX     SOURCE
    21     1     10     donkeyHire
    And if I run the query in sql I get some records returned
    select v_candidate_id, v_fname,v_current_employer,v_Experience_years from candidature where V_REQUIREMENT = 21 and v_experience_years >= 1 and v_experience_years <= and source like 'donkeyHire'
    V_CANDIDATE_ID     V_FNAME     V_CURRENT_EMPLOYER     V_EXPERIENCE_YEARS
    2     Vengu     Andale Tech     4
    But the record does not show up in the report!
    does this type of report parse page items as text?
    Why is it so?
    Waiting for an early reply.
    Thanks,
    venkat

    Venkat - You don't want to put ':SOURCES1' in quotes like that.
    Scott

Maybe you are looking for

  • HP 6510 not printing black ink

    I bought a new black ink cartridge a few weeks ago, installed it, but I hadn't had a chance to print anything until tonight.  It worked before I installed the new cartridge, and now it doesn't print black ink. (It is an HP cartridge)  I have done all

  • Unable to insert and retrieve Unicode data using Microsoft OLE DB Provider

    Hi, I have an ASP.NET web application that uses OLEDB connection to Oracle database. Database: Oracle 11g Provider: MSDAORA ConnectionString: "Provider=MSDAORA;Data Source=localhost;User ID=system; Password=oracle;*convertNcharLiterals*=true;" When I

  • Albums in Aperture 3 not showing upon IPhone/IPad "Photos" App

    Hello; Some of the Albums I have on file in Aperture 3 are not showing up on my IPhone nor IPad in the "Photos" App. Am I missing a setting? Thanks Mark

  • DB console not view of running database.

    I have installed 10.1.0.4 in Linux RH. And I have first iteration for db console: Installed ASM. Installed database INS1. Installed repository for dbconsole in INS1. Dbconsole has been started and worked. Database INS1 has been deleted (repository no

  • How to edit fields

    i created a new responsibility named PAL Purchasing Intelligence. I added the following reports: POASPANA---Purchases POASPERF----Supplier Performance POASPCOR.- Supplier Consolidation Impact i'd like to edit the function name for ex. POASPANA to PAL