To generate sql string of desired row  using function.

Hi l,
I return the below query to get sum of vehicles which falls between the specific weight ranges.
It returns 20 rows( As I selected 4 classification vehicles).I was expect only 4 rows .One row for each classification of vehicles.
Is there a way if do some loop or decode in my function logic?
will tht work?
"(This is only smple. In my real appilication, if I use 15 classification vehicles it returns 320 rows. But i expect only 16 rows - 0 to 15 one row for each classification .Duirng runtime I'm getting an error as buffer string too small)"
How could I solve this?
I use this query inside a function and I call that function in a dynamic sql.
SELECT 'SUM('
    || 'CASE '
    || 'WHEN weight_report_data.weight >=  '|| repo_range_param.min_value ||' 
        AND weight_report_data.weight   <       repo_range_param.max_value
        THEN weight_report_data.weight_count '   
    || 'ELSE 0 '
    || 'END '
    || ') "Class ' || repo_param.r_value || '" '   
      FROM repo_param
      JOIN repo_range_param
        ON repo_param.r_id = repo_range_param.r_id
     WHERE repo_param.r_id    = 1
       AND repo_param.r_group = 'class'
       AND repo_param.r_name  = 'class'
       AND repo_range_param.r_group = 'gvw'
       AND repo_range_param.r_name  = 'gvw'
     ORDER BY CAST(repo_param.r_value AS NUMBER) ASC;
"sample sql string output when I run the above query "
SUM(CASE WHEN weight_report_data.weight >=10
         AND weight_report_data.weight  <15
        THEN weight_report_data.weight_count ELSE 0 END ) "Class 0"
SUM(CASE WHEN weight_report_data.weight >=15
         AND weight_report_data.weight  <20
        THEN weight_report_data.weight_count ELSE 0 END ) "Class 1"
SUM(CASE WHEN weight_report_data.weight >=5
         AND weight_report_data.weight  <10
        THEN weight_report_data.weight_count ELSE 0 END ) "Class 2"
SUM(CASE WHEN weight_report_data.weight >=20
         AND weight_report_data.weight  <25
        THEN weight_report_data.weight_count ELSE 0 END ) "Class 3"
"sample data for the tables involved"
CREATE  TABLE weight_report_data
start_date_time       TIMESTAMP      NOT NULL,
end_date_time         TIMESTAMP      NOT NULL,
weight                NUMBER(12,0)   NOT NULL,
weight_count          NUMBER(12,0)   NOT NULL
INSERT INTO weight_report_data(start_date_time, end_date_time, weight, weight_count)
       VALUES('01-JUL-08 12:00:00','03-JUL-08 12:00:00',4,5);
INSERT INTO weight_report_data(start_date_time, end_date_time, weight, weight_count)
       VALUES('01-JUL-08 12:00:00','03-JUL-08 12:00:00',3,1);
INSERT INTO weight_report_data(start_date_time, end_date_time, weight, weight_count)
       VALUES('01-JUL-08 12:00:00','03-JUL-08 12:00:00',8,6);
INSERT INTO weight_report_data(start_date_time, end_date_time, weight, weight_count)
       VALUES('01-JUL-08 12:00:00','03-JUL-08 12:00:00',25,9);
CREATE  TABLE repo_param
R_ID       NUMBER(12,0),
R_GROUP     VARCHAR2(10),
R_NAME     VARCHAR2(10),
R_VALUE     VARCHAR2(10)
INSERT INTO repo_param(r_id, r_group, r_name, r_value)
       VALUES(1,'class','class',0);
INSERT INTO repo_param(r_id, r_group, r_name, r_value)
       VALUES(1,'class','class',1);
INSERT INTO repo_param(r_id, r_group, r_name, r_value)
       VALUES(1,'class','class',2);
INSERT INTO repo_param(r_id, r_group, r_name, r_value)
       VALUES(1,'class','class',3);
CREATE  TABLE repo_range_param
R_ID       NUMBER(12,0),
R_GROUP     VARCHAR2(10),
R_NAME     VARCHAR2(10),
MIN_VALUE NUMBER(3,0),
MAX_VALUE     NUMBER(3,0)
INSERT INTO repo_range_param(r_id, r_group, r_name, min_value, max_value)
       VALUES(1,'gvw','gvw',0,5);
INSERT INTO repo_range_param(r_id, r_group, r_name, min_value, max_value)
       VALUES(1,'gvw','gvw',5,10);
INSERT INTO repo_range_param(r_id, r_group, r_name, min_value, max_value)
       VALUES(1,'gvw','gvw',10,15);
INSERT INTO repo_range_param(r_id, r_group, r_name, min_value, max_value)
       VALUES(1,'gvw','gvw',15,20);
       INSERT INTO repo_range_param(r_id, r_group, r_name, min_value, max_value)
       VALUES(1,'gvw','gvw',20,25);
Thanks in advance
Edited by: user10641405 on Jun 18, 2009 4:10 PM
Edited by: user10641405 on Jun 18, 2009 4:15 PM
Edited by: user10641405 on Jun 18, 2009 4:15 PM
Edited by: user10641405 on Jun 18, 2009 4:16 PM
Edited by: user10641405 on Jun 18, 2009 4:17 PM
Edited by: user10641405 on Jun 18, 2009 7:47 PM
Edited by: user10641405 on Jun 19, 2009 4:15 PM

Say you have a 3 tables
Table name Description rowcount()
============================================================================
weight_report_data report table having weights and counts 4
repo_param having id column gives different classes 4
repo_range_param is detail table of repo_param with id 4
          as foreign key and defines weight
          min max ranges.
Now you need to report
per class how many weights weights are there ?
--not understood report id clearly in relation to weight_report_data
step1:
need to map each row of weight_report_data againist its class.
select wrd.weight,wrd.weight_count,(select rp.class||rp.value
from repo_range_param rrp,
          repo_param rp
where rrp.id= rp.id
and rp.id=1 -- add your other join condition
and wrd.weight between rrp.min and rrp.max ) class_nm
from weight_report_data wrd ;
This will give 4 rows , i.e for each row in wrd it tells which class it falls.
now you want to group by class_nm to get sum or count of weights.
step2:
select class_nm,sum(weight), count(weight), sum(weight_count)
from (
select wrd.weight,wrd.weight_count,(select rp.class||rp.value
from repo_range_param rrp,
          repo_param rp
where rrp.id= rp.id
and rp.id=1 -- add your other join condition
and wrd.weight between rrp.min and rrp.max ) class_nm
from weight_report_data wrd ) wrd_classnm
group by class_nm;
I hope this helps .
suggestion: first analyse and breakdown into stpes how you r going to do if you do by hand and then translate into sql and then optimise

Similar Messages

  • How to modify the pre generated SQL string in Db adapter

    Hello All,
    I am using a DB adapter to poll a database. So in the configuration of adapter, i have specified the option of logical delete, i want to update to a field PF as 'Y'. In my BPEL process, I want to update those records as 'Y' for their process_Completion field after i am done doing logic on those records.. Actually in the database adapter configuration, we get the SQL string right ?. So inorder to edit that SQL how should we go ahead ?
    I mean i want to poll the database, i want to get like 1000 records for my BPEL Process Instance, and after all those 1000 gets processed and completed. Iwant to get the next 1000. So i want to write a query something like...
    select seqid, id, field1, field2..... from STable a where a.PF = 'N' and exists(select 1 from STable b where b.seqid = a.seqid - 1 and b.PF = 'Y' and b.process_Completion = 'Y')
    So, how to write my custom quesries while polling the database. cant we write custom quesries while we are doing Inbound operation with Dbadapter. Please help me with this thing.
    Thanks,
    N

    Whenever you use a JCA DB Adapter in JDeveloper it creates an OR mapping xml that contains the select/polling query that you might have.
    Below is an example of one such query. You can edit the sql here manually and redeploy your process.
    <querying xsi:type="query-policy">
    <queries>
    <query name="DBConnSelect" xsi:type="read-all-query">
    <call xsi:type="sql-call">
    <sql>SELECT MESSAGE_ID,BU_ID,CREATED_BY FROM MESSAGE_BUFFER where BU_ID IN (3232,4747) and 3 > rownum</sql>
    </call>
    <reference-class>DBConn.MessageBuffer</reference-class>
    <container xsi:type="list-container-policy">
    <collection-type>java.util.Vector</collection-type>
    </container>
    </query>
    </queries>
    In case you need to add parameters to your query you should be able to do that as well while you are creating your DB Adapter.
    Edited by: Arun Pareek on Jun 15, 2011 9:34 AM

  • How to see generated SQL when execute JPQL query using entity manager?

    I want to see generated SQL query in console or in a log file. How do I do that?
    I'm using GlassFish if it matters

    If you want to see SQL query that is generated from JPQL in GlassFish console you should do following:
    Log on admin console.
    Select 'Application Server' from tree, then select Logging tab and Log Levels sub-tab.
    Log level for 'Persistence' must be set to FINE or level with more verbosity.

  • Problem deleting rows using JDBC

    Hi,
    I have a problem with the following code listed below. I am attempting to delete a user's details from a SQLServer db based on the user selected from a combobox. The code given below is just a section and relates to a JButton I have on the application that performs the delete command.
    public void deleteButton_actionPerformed(ActionEvent e) {
    try{
    String opName = (String)userNameBox.getSelectedItem();
    String deleteQuery = "select * from Operator where OperatorName = " + "'"+opName+"'";
    //Load Database Driver Class
    Class.forName(JDBC_DRIVER);
    //Establish a connection to the Database
    connection = DriverManager.getConnection(DATABASE_URL);
    //Create Select statement for returning all usernames to the combobox
    statement2 = connection.createStatement(java.sql.ResultSet.TYPE_SCROLL_SENSITIVE, java.sql.ResultSet.CONCUR_READ_ONLY);
    //dQuery.setString(1,opName);
    resultSet = statement2.executeQuery(deleteQuery);
    while (resultSet.next()){
    resultSet.deleteRow();
    catch(Exception exception){
    exception.printStackTrace();}
    To explain the code, to begin with a String holds the value of the selected field of the combobox i have in my app. I have the SQL select statement the using this variable as the where clause.
    The usual connection and statement objects are declared etc and then the query is executed. Within the While loop I then attempt to delete the row that the query has retrieved for me. However this results in the following error.
    java.sql.SQLException: [Microsoft][ODBC SQL Server Driver]Invalid attribute/option identifier
    Any help is much appreciated.
    Thanks
    Alan

    Thanks for the reply. I understand your comment about
    using the delete statement and it seems I am making
    an obvious error. However I was using the select
    statement to generate a resultSet object with which I
    can delete elements from. Hence the reason for the
    use of the select statement.This is brain dead, the classic newbie mistake. The database vendor has optimized their code more than you ever will in making those deletes, so use their code. Not only will they do it faster than you will, but you'll save yourself (n+1) network roundtrips (1 for the SELECT, 1 for each DELETE you issue). Better to learn SQL and use a WHERE clause to do it on the database side.
    You have however solved the problem I had with
    directly executing the delete statement as an SQL
    String. I was using the following statement:
    String deleteQuery = "select * from Operator where
    OperatorName = " + "'"+opName+"'";
    The wildcard character is not required and it was
    this that gave me problems and made me look to using
    a select query and deleting results from a
    resultSet.Sounds like you need a SQL book. I recommend "SQL For Smarties".
    %

  • Easy Question: How to split concatenated string into multiple rows?

    Hi folks,
    this might be an easy question.
    How can I split a concatenated string into multiple rows using SQL query?
    INPUT:
    select 'AAA,BBB,CC,DDDD' as data from dualDelimiter = ','
    Expected output:
    data
    AAA
    BBB
    CCC
    DDDDI'm looking for something kind of "an opposite for 'sys_connect_by_path'" function.
    Thanks,
    Tomas

    Here is the SUBSTR/INSTR version of the solution:
    SQL> WITH test_data AS
      2  (
      3          SELECT ',' || 'AAA,BBB,CC,DDDD' || ',' AS DATA FROM DUAL
      4  )
      5  SELECT  SUBSTR
      6          (
      7                  DATA
      8          ,       INSTR
      9                  (
    10                          DATA
    11                  ,       ','
    12                  ,       1
    13                  ,       LEVEL
    14                  ) + 1
    15          ,       INSTR
    16                  (
    17                          DATA
    18                  ,       ','
    19                  ,       1
    20                  ,       LEVEL + 1
    21                  ) -
    22                  INSTR
    23                  (
    24                          DATA
    25                  ,       ','
    26                  ,       1
    27                  ,       LEVEL
    28                  ) - 1
    29          )       AS NEW_STRING
    30  FROM    test_data
    31  CONNECT BY LEVEL <= LENGTH(REGEXP_REPLACE(DATA,'[^,]','')) - 1
    32  /
    NEW_STRING
    AAA
    BBB
    CC
    DDDD

  • How to make 3 similar fun's does generate different sql string in 1 db call

    Hi All,
    In my sql package I'm using 3 different functions to create two different sql strings and the 3rd function does some percentage calculations. My Db architect on code review suggest me that those two functions are almost the same except the sql string it does generate. So she asked me to write one function that does everything in one db call.
    "_Function 1_"
    FUNCTION get_class_select_text
         in_report_parameter_id IN NUMBER
    RETURN VARCHAR2
    IS
    my_class_select_text VARCHAR2(10000);
    my_class_select_value VARCHAR2(10000);
    CURSOR class_select_text IS
         SELECT 'SUM(DECODE(bin_id, ' || report_parameters.report_parameter_value
                        || ', bin_value, 0)) "Class ' || report_parameters.report_parameter_value || '" '
    FROM report_parameters
    WHERE report_parameters.report_parameter_id = in_report_parameter_id
    AND report_parameters.report_parameter_group = 'CLASS'
    AND report_parameters.report_parameter_name = 'CLASS'
    GROUP BY
    report_parameters.report_parameter_value
    ORDER BY
    CAST(report_parameters.report_parameter_value AS NUMBER);
    BEGIN
    my_class_select_text := '';
    OPEN class_select_text;
    LOOP
    FETCH class_select_text INTO my_class_select_value;
    EXIT WHEN class_select_text%NOTFOUND;
    my_class_select_text := my_class_select_text || ', ' || my_class_select_value;
    END LOOP;
    CLOSE class_select_text;
    RETURN my_class_select_text;
    END get_class_select_text;
    FUNCTION 2:
    FUNCTION get_class_sum_text
         in_report_parameter_id IN NUMBER
    RETURN VARCHAR2
    IS
    my_class_sum_text VARCHAR2(10000);
    my_class_sum_value VARCHAR2(10000);
    CURSOR class_sum_text IS
         SELECT 'SUM(NVL("Class ' || report_parameters.report_parameter_value || '", 0)) "Class ' || report_parameters.report_parameter_value || '" '
    FROM report_parameters
    WHERE report_parameters.report_parameter_id = in_report_parameter_id
    AND report_parameters.report_parameter_group = 'CLASS'
    AND report_parameters.report_parameter_name = 'CLASS'
    GROUP BY
    report_parameters.report_parameter_value
    ORDER BY
    CAST(report_parameters.report_parameter_value AS NUMBER);
    BEGIN
    my_class_sum_text := '';
    OPEN class_sum_text;
    LOOP
    FETCH class_sum_text INTO my_class_sum_value;
    EXIT WHEN class_sum_text%NOTFOUND;
    my_class_sum_text := my_class_sum_text || ', ' || my_class_sum_value;
    END LOOP;
    CLOSE class_sum_text;
    RETURN my_class_sum_text;
    END get_class_sum_text;
    FUNCTION 3:
    FUNCTION get_class_perc_text
         in_report_parameter_id IN NUMBER
    RETURN VARCHAR2
    IS
    my_class_perc_text VARCHAR2(10000);
    my_class_perc_value VARCHAR2(10000);
    CURSOR class_perc_text IS
    SELECT 'ROUND((("Class ' || report_parameters.report_parameter_value || '" / "Total") * 100), 2) "Class ' || report_parameters.report_parameter_value || '" '
    FROM report_parameters
    WHERE report_parameters.report_parameter_id = in_report_parameter_id
    AND report_parameters.report_parameter_group = 'CLASS'
    AND report_parameters.report_parameter_name = 'CLASS'
    GROUP BY
    report_parameters.report_parameter_value
    ORDER BY
    CAST(report_parameters.report_parameter_value AS NUMBER);
    BEGIN
    my_class_perc_text := '';
    OPEN class_perc_text;
    LOOP
    FETCH class_perc_text INTO my_class_perc_value;
    EXIT WHEN class_perc_text%NOTFOUND;
    my_class_perc_text := my_class_perc_text || ', ' || my_class_perc_value;
    END LOOP;
    CLOSE class_perc_text;
    my_class_perc_text := my_class_perc_text || ', ' || 'DECODE("Total", -1, 0, 100) "Total" ';
    RETURN my_class_perc_text;
    END get_class_perc_text;
    Could anyone help me?
    Thanks in advance.

    Hi ,
    Thanks a lot for your reply and tips how to post the code.
    As you know that previously I used 3 different variables called
    my_class_select_text,
    my_class_sum_text,
    my_class_perc_text
    to get corresponding values. I'm using these values in a dynamic SQL like below in the code.
          SELECT 3 "Rank", '
        || '            ''Final Row'' "Row Type", '
        || '            TRUNC(edr_rpt_tmp_bin_periods.bin_start_date_time ) "Date", '
        || '            MAX(edr_rpt_tmp_bin_periods.bin_end_date_time) - numtodsinterval(0.000000001, ''SECOND'') "Date/Time", '
        || '            '''' "Lane", '
        || '            ''Total'' "Hour"  '
        ||              my_class_sum_text
        || '                           , '
        || '             SUM(NVL(" ", 0)) " " '
        || '           FROM ( '
        || '                  SELECT edr_class_by_hour_report_data.bin_start_date_time start_date_time '
        ||                               my_class_select_text || ', '
        || '                             SUM(NVL(edr_class_by_hour_report_data.bin_value, 0)) " " '
        || '                    FROM edr_class_by_hour_report_data '
        || '             GROUP BY edr_class_by_hour_report_data.bin_start_date_time '
        || '                ) results '
       As per your new function it returns in a single parameter called 'my_class_perc_text' . Now I dont know how to use single variable in these places?
    Hope you could understand my question.
    I used to display code. :)
       Thanks once again.
    Edited by: user10641405 on May 21, 2009 2:06 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • How can i pass sql string in proc as in parameter and use in cursor forloop

    Dear Experts ,
    Please help me in below code.
    create or replace PROCEDURE Sample_Spool_Data (SQLSTRING IN VARCHAR2, FILENAME in VARCHAR2) IS
    v_spool_file UTL_FILE.FILE_TYPE ;
    SQLSTRING VARCHAR2(1000);
    BEGIN
    v_spool_file := UTL_FILE.FOPEN('MPLD_DQMT',FILENAME,'w');
    UTL_FILE.PUT_LINE(v_spool_file,'Start: '||to_char(sysdate,'dd/mm/yyyy hh:mi s'));
    FOR c1_rec in SQLSTRING
    LOOP
    UTL_FILE.PUT_LINE(v_spool_file,c1_rec.rec);
    end loop;
    UTL_FILE.PUT_LINE(v_spool_file,'End: '||to_char(sysdate,'dd/mm/yyyy hh:mi s'));
    SQL String is having like select col1, col2, col3 from table_name;

    Looks like you're tring to write a generic way of outputting the results of a query to a file.
    You won't do it the way you're trying to, because your dynamic SQL means that you don't know the resultant columns of the query so that you can output them. To do that you need to use the DBMS_SQL package to describe the query and fetch the returned columns by position e.g.
    As sys user:
    CREATE OR REPLACE DIRECTORY TEST_DIR AS '\tmp\myfiles'
    GRANT READ, WRITE ON DIRECTORY TEST_DIR TO myuser
    /As myuser:
    CREATE OR REPLACE PROCEDURE run_query(p_sql IN VARCHAR2
                                         ,p_dir IN VARCHAR2
                                         ,p_header_file IN VARCHAR2
                                         ,p_data_file IN VARCHAR2 := NULL) IS
      v_finaltxt  VARCHAR2(4000);
      v_v_val     VARCHAR2(4000);
      v_n_val     NUMBER;
      v_d_val     DATE;
      v_ret       NUMBER;
      c           NUMBER;
      d           NUMBER;
      col_cnt     INTEGER;
      f           BOOLEAN;
      rec_tab     DBMS_SQL.DESC_TAB;
      col_num     NUMBER;
      v_fh        UTL_FILE.FILE_TYPE;
      v_samefile  BOOLEAN := (NVL(p_data_file,p_header_file) = p_header_file);
    BEGIN
      c := DBMS_SQL.OPEN_CURSOR;
      DBMS_SQL.PARSE(c, p_sql, DBMS_SQL.NATIVE);
      d := DBMS_SQL.EXECUTE(c);
      DBMS_SQL.DESCRIBE_COLUMNS(c, col_cnt, rec_tab);
      FOR j in 1..col_cnt
      LOOP
        CASE rec_tab(j).col_type
          WHEN 1 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_v_val,2000);
          WHEN 2 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_n_val);
          WHEN 12 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_d_val);
        ELSE
          DBMS_SQL.DEFINE_COLUMN(c,j,v_v_val,2000);
        END CASE;
      END LOOP;
      -- This part outputs the HEADER
      v_fh := UTL_FILE.FOPEN(upper(p_dir),p_header_file,'w',32767);
      FOR j in 1..col_cnt
      LOOP
        v_finaltxt := ltrim(v_finaltxt||','||lower(rec_tab(j).col_name),',');
      END LOOP;
      --  DBMS_OUTPUT.PUT_LINE(v_finaltxt);
      UTL_FILE.PUT_LINE(v_fh, v_finaltxt);
      IF NOT v_samefile THEN
        UTL_FILE.FCLOSE(v_fh);
      END IF;
      -- This part outputs the DATA
      IF NOT v_samefile THEN
        v_fh := UTL_FILE.FOPEN(upper(p_dir),p_data_file,'w',32767);
      END IF;
      LOOP
        v_ret := DBMS_SQL.FETCH_ROWS(c);
        EXIT WHEN v_ret = 0;
        v_finaltxt := NULL;
        FOR j in 1..col_cnt
        LOOP
          CASE rec_tab(j).col_type
            WHEN 1 THEN DBMS_SQL.COLUMN_VALUE(c,j,v_v_val);
                        v_finaltxt := ltrim(v_finaltxt||',"'||v_v_val||'"',',');
            WHEN 2 THEN DBMS_SQL.COLUMN_VALUE(c,j,v_n_val);
                        v_finaltxt := ltrim(v_finaltxt||','||v_n_val,',');
            WHEN 12 THEN DBMS_SQL.COLUMN_VALUE(c,j,v_d_val);
                        v_finaltxt := ltrim(v_finaltxt||','||to_char(v_d_val,'DD/MM/YYYY HH24:MI:SS'),',');
          ELSE
            v_finaltxt := ltrim(v_finaltxt||',"'||v_v_val||'"',',');
          END CASE;
        END LOOP;
      --  DBMS_OUTPUT.PUT_LINE(v_finaltxt);
        UTL_FILE.PUT_LINE(v_fh, v_finaltxt);
      END LOOP;
      UTL_FILE.FCLOSE(v_fh);
      DBMS_SQL.CLOSE_CURSOR(c);
    END;This allows for the header row and the data to be written to seperate files if required.
    e.g.
    SQL> exec run_query('select * from emp','TEST_DIR','output.txt');
    PL/SQL procedure successfully completed.Output.txt file contains:
    empno,ename,job,mgr,hiredate,sal,comm,deptno
    7369,"SMITH","CLERK",7902,17/12/1980 00:00:00,800,,20
    7499,"ALLEN","SALESMAN",7698,20/02/1981 00:00:00,1600,300,30
    7521,"WARD","SALESMAN",7698,22/02/1981 00:00:00,1250,500,30
    7566,"JONES","MANAGER",7839,02/04/1981 00:00:00,2975,,20
    7654,"MARTIN","SALESMAN",7698,28/09/1981 00:00:00,1250,1400,30
    7698,"BLAKE","MANAGER",7839,01/05/1981 00:00:00,2850,,30
    7782,"CLARK","MANAGER",7839,09/06/1981 00:00:00,2450,,10
    7788,"SCOTT","ANALYST",7566,19/04/1987 00:00:00,3000,,20
    7839,"KING","PRESIDENT",,17/11/1981 00:00:00,5000,,10
    7844,"TURNER","SALESMAN",7698,08/09/1981 00:00:00,1500,0,30
    7876,"ADAMS","CLERK",7788,23/05/1987 00:00:00,1100,,20
    7900,"JAMES","CLERK",7698,03/12/1981 00:00:00,950,,30
    7902,"FORD","ANALYST",7566,03/12/1981 00:00:00,3000,,20
    7934,"MILLER","CLERK",7782,23/01/1982 00:00:00,1300,,10The procedure allows for the header and data to go to seperate files if required. Just specifying the "header" filename will put the header and data in the one file.
    Adapt to output different datatypes and styles are required.

  • Generate SQL Insert Statement using EXPORTED dmp file

    Dear DBAs,
    Kindly inform me that is it possible to generate SQL script file using the exported file dmp,
    I am looking for some option in import utility that generates script without import any rows in the database
    Secondly is there any other way to check the validity of exported dmp file data validity without importing it back into the database.
    Regards,
    Asif

    Hi Satish,
    Yes you are correct the insert into statements won't be avaliable using either the indexfile or the show parameter.I had given these two options as per his 1st post requirement where he had mentioned
    >
    it possible to generate SQL script file using the exported file dmp,I am looking for some option in import utility that generates script without import any rows in the database
    >
    So, i thought he needed to see whats all objects are in the .dmp
    Apologies for my 2nd post.
    Anand

  • Mutiple Rows from a Single Row using SQL

    How can i get Multiple rows from a single row using sql ?
    Example : one row contains the complete address separated by delimiter say comma (,) as address1,address2,city,state,zip,country
    I want to split this row and get the output in multiple rows as address1 address2 city state zip country using sql query.
    Thanks,

    Hi,
    The solution above assumes that the |-delimited entries always contain at least one character. If you have a string like
    1 Elm Street|||Sioux City|IA||it will think 'Siuox City' is address2.
    If you have empty entries, like that, then you need something a little more complicated:
    INSERT INTO table2
    (       address1
    ,     address2
    ,     address3
    ,     city
    ,     state
    ,     postal
    ,     country
    SELECT     SUBSTR (REGEXP_SUBSTR ('|' || txt, '\|[^|]*', 1, 1), 2)     -- address1
    ,     SUBSTR (REGEXP_SUBSTR ('|' || txt, '\|[^|]*', 1, 2), 2)     -- address2
    ,     SUBSTR (REGEXP_SUBSTR ('|' || txt, '\|[^|]*', 1, 3), 2)     -- address3
    ,     SUBSTR (REGEXP_SUBSTR ('|' || txt, '\|[^|]*', 1, 4), 2)     -- city
    ,     SUBSTR (REGEXP_SUBSTR ('|' || txt, '\|[^|]*', 1, 5), 2)     -- state
    ,     SUBSTR (REGEXP_SUBSTR ('|' || txt, '\|[^|]*', 1, 6), 2)     -- postal
    ,     SUBSTR (REGEXP_SUBSTR ('|' || txt, '\|[^|]*', 1, 7), 2)     -- country
    FROM     table1
    ;

  • How to encode sql string for SQL Server when using JDBC?

    in code, dynamically generate sql stirng like:
    String sqlstring = "select column from table where column=' " + var + " ' ";
    Question is: if var include char ' , it will cause error becuase ' is reserved by SQL Server for string reference.
    So how to encode string for dynamic sql string? for example, following sql(when var =" I'm tester"):
    select column from table where column like ' I'm tester '
    Edited by: KentZhou on Jun 17, 2009 3:10 PM

    Use PreparedStatement. Use it all the way. It not only saves you from SQL injections, but also eases setting non-standard Java objects like Date and InputStream in a SQL statement.
    Prepare here: [http://java.sun.com/docs/books/tutorial/jdbc/basics/prepared.html].

  • How to use Native SQL String

    Hi all,
    How do i use Native SQL String in the Reciver JDBC Adapter.
    Do i need to change the message format could u suggest me some blogs on the same.
    Also please can anyone let me knw if i can use this for stored procedure.

    hi aditya,
    there shud be no format as such. for sql xml format there are specific structure. but for native sql there shudnt be any specific structure.
    as pointed in sap documentaion:
    Instead of an XML document format, a text is expected that represents any valid SQL statement.
    When inserting a line into a table the corresponding document looks as follows:
    INSERT INTO tableName  (column-name1, column-name2, column-name3) VALUES(‘column-value1’, ‘column-value2’, ‘column-value3’)
    so jus make sure that u give a valid sql statement becoz if will be passed as it is to the database and try ur scenario.
    regards,
    latika.

  • SQL Server 2005 64BIT Linked Server Cannot fetch a row using a bookmark

    We get the following error SOMETIMES when trying to delete a row from an Oracle 10g database table via the SQL 2005 64BIT linked server.
    DELETE [edwdev]..SYSTEM.SAIC_ARTIFACT_LOG FROM tblArtifactLog src WHERE src.source_seq_no = SAIC_ARTIFACT_LOG.art_seq_no and src.source_name = 'edwdev' [SQLSTATE 01000] (Message 0) Cannot fetch a row using a bookmark from OLE DB provider "OraOLEDB.Oracle" for linked server "edwdev". [SQLSTATE 42000] (Error 7333). The step failed.
    They keyword here is SOMETIMES. The job would fail 100% of the time before applying ODAC 10.2.0.3.0, after the ODAC install the job fails about 40% of the time. We have this setup in a test enviornment and yes there are rows of data in the table everytime the job runs.
    As far as the OraOLEDB10.dll install we have a date of 2/20/07 but a version of 10.2.0.2. I am wondering if this shouldn't be a new version.

    LearnMoreAgile wrote:
    so does that mean no one at oracle can guide me in this issue before i goto microsoft ?How has the Linked Server been created in MSSQL? OraOLEDb.Oracle is the class name for the Oracle OLEDB provider which should appear in your list of OLEDB providers in your favourite windows dev tool or when creating the linked server. If it doesn't appear likely you didn't choose to install it. I don't know if it's a default install with the 64bit client, but the ODAC client contains the .net provider and not the OLEDB provider.
    Niall

  • Dynamic SQL Select String VS non-dynamic USING Clause

    This isn’t a question, I just wanted to share a solution to a problem I have encountered several times.
    e.g. You have ‘n’ number of variables, of which any combination could be used in a SQL string. But it’s difficult to execute the SQL string with USING without an unpleasant CASE statement.
    Solution: Reference all ‘n’ bind variables in the FROM clause of the SQL in an in-line-view. And specify all variables in the USING Clause.
    When building the SQL String, specify the view.variable rather than directly referencing bind variables
    This eliminates the requirement to check which variables have been populated.
    <h6>
    t_select := ‘SELECT tab.cola, tab.colb’;
    t_from := ‘FROM (SELECT :1 cola, :2 colb, :3 colc, :4 cold, :5 cole) parms, tablea tab’;
    t_where := ‘WHERE tab.cola = parms.cola’;
    OPEN c t_select||t_from||t_where USING v1, v2, v3, v4, v5;
    </h6>
    I hope this is useful to someone...
    PeteD

    Interesting approach.. but I would still prefer creating a DBMS_SQL cursor instead - as there the binding can be fully controlled at run-time.
    If this has to return a ref cursor (caller is an external process), then I would rather use conditional processing logic (as that is what PL is about) in PL/SQL and build a "+proper+" SQL statement (with only the required bind variables) at run-time. Features like polymorphism makes this easy - and the call interface that is provided to the client is a lot cleaner.

  • How to retrieve generated sql query from interface using groovy

    Hi All,
    I'm new to odi and i need the generated sql query code from the interface using groovy.

    Hi All,
    I'm new to odi and i need the generated sql query code from the interface using groovy.

  • Is there a way to add a column after a filled DataTable from SQL with the same rows?

    My problem is that not to add rows like filled by SQLDataAdapter at the same row in DataGridView. How to make that? I showed below the details with my code also a screen shot, which shows the rows differences from the origin one.
    I don't want to add an expression as column behave in my sql script to get what I need with query result. I don't want to obtain that way.
    using (SqlConnection c = new SqlConnection(ConnStrMSSQL))
    c.Open();
    // 2
    // Create new DataAdapter
    using (SqlDataAdapter a = new SqlDataAdapter("SELECT SIPNO, SERINO, TARIH FROM SNOHAREKETLER WHERE Cast(TARIH as DATE) BETWEEN '2015/03/20' AND '2015/03/20' AND (TEZNO = 'T23' OR TEZNO = 'T31') AND CIKTI is null", c))
    // 3
    // Use DataAdapter to fill DataTable
    DataTable t = new DataTable();
    a.Fill(t);
    t.Columns.Add("MyColumn", typeof(string));
    DataRow workRow;
    int iGetCount = t.Rows.Count;
    for (int i = 0; i <= iGetCount - 1; i++)
    workRow = t.NewRow();
    workRow["MyColumn"] = i;
    t.Rows.Add(workRow);
    dataGridView1.DataSource = t;

    The extra column isn't applied to only certain rows.  The columns of a table identify what data each row will contain.  Hence adding a column to the table automatically adds them to the rows.  What you're seeing is that all the initial rows
    aren't being assigned a value so they retain their default value of null.  Later you enumerate the rows of the existing table and call AddRow which adds new rows.  This isn't adding columns, but rows.
    To generate values for the existing rows you should ideally simply pass the data back from the database.  DT computed columns can be difficult to set up as it is limited to what it can do.  If you want to use a computed column on the Datatable
    itself then define the column as a computed column and every row will calculate its own value.
    DataTable data = GetData();
    //Add elapsed time column
    var col = new DataColumn("ElapsedTime", typeof(TimeSpan), "expr");
    data.Columns.Add(col);
    dataGridView1.DataSource = data;
    The issue you will run into however is that calculating a diff on DateTime doesn't work in a computed column as the expression doesn't support the necessary functions.  You can google for how people solved this if you are interested in alternatives. 
    Most people just tend to add the column and then hook into the various change events to update the value as needed.

Maybe you are looking for

  • How much RAM can my Macbook Pro hold MAX?

    Can my Macbook Pro hold a MAX of 8GB or is it just 4GB? I'm getting different answers online and I'm a little annoyed at this point. My computer specs currently are: 15 inch Laptop MacBook Pro 2.6 GHz Intel Core 2 Duo 2 GB 667 MHz DDR2 SDRAM. Got my

  • How to conditionally hide/show form item for multiple requests?

    Ver 4.1.0 Hi There, I have a database form where in one of the fields I need to hide /show based on if the user selects a copy row option or create a new row. To explain in details, 1. I have a report and form application created. When the user edits

  • Jdeveloper + UDDI

    Hello everyone, Can anyone help me to provide the links where I can find the tutorials about using Jdeveloper with UDDI? My object is to create a business process, then I will deploy the services in repository, UDDI. Then, I will create an other busi

  • What type of shows can you get on Apple TV?

    What type of shows can you get on Apple TV? Now question is about the content one can get with Apple TV< if we switched. presently live in Canada. Can one get the News on Apple TV, such as CTV< cbc etc? Can one watch. Daily soap operas on Apple TV? A

  • Does anyone know how to share libraries in home share on this new version of itunes.

    Does anyone know how to share music or import music from 1 computer to another on the home share. My daughter and I have been doing it for a while now but the new updated version wont let us. And the instructions on the help are of no help as there i