Using Collection in a sql statement.

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

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

Similar Messages

  • Can we use if/else in sql statement?

    Hi,
    Is it possible to write a sql statement like the one below (not plsql)?
    if (select 'True' from dual) = 'True' -- 1
    then
    select 'True' from dual;  -- 2
    else
      select 'False' from dual; -- 3
    endBasically, I want to execute either sql 2 or 3 based on the result of sql 1. I'm not sure if this is possible using only sql and not having to write a stored proc.
    What are the different ways I can implement this?
    Thanks for the help.

    Billy  Verreynne  wrote:
    The case syntax is a bit funny though as there's not a single condition evaluation (like a DECODE or case structs from some other languages).
    This is what I would expect a typical case struct to look like - evaluating a single condition:
    case <condition>
    when <value-1> then return <result-1>
    when <value-n> then return <result-n>
    else
    return <return-z>
    end
    ?:| You mean like this...?
    SQL> ed
    Wrote file afiedt.buf
      1  select empno, ename, deptno
      2        ,case deptno
      3           when 10 then 'This is Department 10'
      4           when 20 then 'And department 20'
      5           when 30 then 'And of course department 30'
      6         else
      7           'Blimey it is something else!'
      8         end as dept_desc
      9* from emp
    SQL> /
         EMPNO ENAME          DEPTNO DEPT_DESC
          7369 SMITH              20 And department 20
          7499 ALLEN              30 And of course department 30
          7521 WARD               30 And of course department 30
          7566 JONES              20 And department 20
          7654 MARTIN             30 And of course department 30
          7698 BLAKE              30 And of course department 30
          7782 CLARK              10 This is Department 10
          7788 SCOTT              20 And department 20
          7839 KING               10 This is Department 10
          7844 TURNER             30 And of course department 30
          7876 ADAMS              20 And department 20
          7900 JAMES              30 And of course department 30
          7902 FORD               20 And department 20
          7934 MILLER             10 This is Department 10
    14 rows selected.

  • Using Date objects in SQL statements

    Hi, I am wondering if it is possible to use Date objects while trying to retrieve entries from an access database with fields set as "Date/Time" fields, as opposed to "Text"? If so, do I need to reformat it before inserting it into the SQL statement, or can I just leave it as a Date object, and call up the variable name?
    For example - "SELECT * FROM database WHERE startDate = ' " + dateObject + ' ". And do i need quotes round this value?
    Thanks in advance.

    I had some problems by just fetching a date and pushing it back to a MS SQL Database.
    I used the following reformating step to fix it:
    if (o instanceof Timestamp)
    String time = o.toString().substring(8,10)+"."+o.toString().substring(5,7)+"."+o.toString().substring(0,4)+" "+o.toString().substring(11,19);
    ht.put(columnName, time);
    o is the object i receve from the select statement and ht is a Hashtable where i put my data.
    To write the data back i now can use:
    UPDATE table SET columnname = 'valueOfColumn'
    This means i use the value i created above in Quotes to write it back.
    Format of Timestamp.toString() is something like yyyy-mm-dd hh:mm:ss.xx
    Format used by MS SQL (and i think by Access to) 'dd.mm.yyyy hh:mm:ss'

  • Using cursor function in sql statement

    hi all
    can anyone plss explain why and when we will use cursor function in a sql statement like this and what is the difference while executing this sql statement with cursor function in comparison of a simple sql statement----
    select
    department_name,
    cursor (
    select last_name
    from employees e
    where e.department_id = d.department_id
    order by last_name
    ) the_employees
    from departments d
    thnx in advance

    RTFM
    http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14261/sqloperations.htm#sthref1452
    Cheers
    Sarma.

  • Using 1 = 1 in SQL Statements

    I have just been told by our DBA that we have to go through
    our code and remove the "WHERE 1 = 1" in our SQL statements on a
    SQL 2000 database. He said it is a performance issue when nothing
    else follows it (no AND's).
    For example (the wrong way):
    SELECT this_ID FROM thistable WHERE 1 = 1
    Versus...
    SELECT this_ID FROM thistable WHERE 1 = 1 AND this_ID = 1001
    He said Microsoft said that this is causing a performance hit
    when there is no AND clauses after the WHERE.
    Some of these SQL statements are pretty big and there is no
    practical way to do a CFIF beforehand.
    Has anyone heard of a performance hit like this? If so, how
    much of a hit? The main table in the DB has about 2 million records
    with full text indexes.
    Thanks,
    Rob in Tampa

    Phil,
    Thanks for the speedy response. I forgot to mention.. there
    are TOP 200 clauses in all the big SQL statements.
    And, like I said before... some of the queries are too big to
    test to see if at least 1 of the condidtions exsist. More often
    than not, the WHERE 1 = 1 clause will not be alone. I personally
    think it is a pet peeve of the DBA where he doesn't see any use of
    the 1 = 1. He said.. it's always going to be true. Kinda the point
    of having it.
    This was taught to me years ago.. but, this is the biggest
    application I have worked on where SQL performance could be an
    issue. It was mentioned that the hit comes when SQL Server is
    building its execution plan and has to include the WHERE 1 = 1
    clause. How much of a hit can it cause? Most of the empty clauses
    with no AND's are most likely in a JOIN clause or something.
    The WHERE placeholder is in almost all of our queries in one
    way or another. Not a small project.
    Thanks,
    Rob

  • Using Variables in a SQL Statement

    I know, I know, this is written in VB..I'm doing a VB Project right now for my Instructor (While in an Intermediate Java Class)
    But VB (I feel) doesnt have very good support Forums.
    Anyway, this is the problem:
    I want to use String Variables to hold the place of field names in
    a SQL Statement and the change the ORDER according to intCount's Loop:
    The key word(s) here is "ORDER BY"
    Private Sub DataGrid1_Click()
    Dim intCount As Integer
    Dim strColHead(11) As String
    strColHead(0) = "RES__PUR_DT"
    strColHead(1) = "VENDOR"
    strColHead(2) = "VEN_LOC"
    strColHead(3) = "RES_TYPE"
    strColHead(4) = "RES_FROM_DT"
    strColHead(5) = "RES_TO_DT"
    strColHead(6) = "MISC_ADJ"
    strColHead(7) = "STATE_TAX"
    strColHead(8) = "LOC_CHARGE"
    strColHead(9) = "RES_ID"
    strColHead(10) = "RES_OP"
    For intCount = 0 To 10
    If DataGrid1.SelStartCol = intCount Then
    Adodc1.RecordSource = "Select * from tblReservation order by 'strColHead(intCount)'"
    End If
    Adodc1.Refresh
    Next intCount
    End Sub

    I'm just wondering if anyone knows a work around so that I might be able to store a Table's FIELD name in a variable or an array[] so that I can do a query based on the decision of a loop without having to code 10 IF/ELSE statements.For instance, although the above code will not work, this code, although quite lengthy, does:
    If DataGrid1.SelStartCol = 0 Then
    Adodc1.RecordSource = "Select * from tblReservation order by RES__PUR_DT"
    Adodc1.Refresh
    ElseIf DataGrid1.SelStartCol = 1 Then
    Adodc1.RecordSource = "Select * from tblReservation order by VENDOR"
    Adodc1.Refresh
    ElseIf DataGrid1.SelStartCol = 2 Then
    Adodc1.RecordSource = "Select * from tblReservation order by VEN_LOC"
    Adodc1.Refresh
    ElseIf DataGrid1.SelStartCol = 3 Then
    Adodc1.RecordSource = "Select * from tblReservation order by RES_TYPE"
    Adodc1.Refresh
    ElseIf DataGrid1.SelStartCol = 4 Then
    Adodc1.RecordSource = "Select * from tblReservation order by RES_FROM_DT"
    Adodc1.Refresh
    ElseIf DataGrid1.SelStartCol = 5 Then
    Adodc1.RecordSource = "Select * from tblReservation order by RES_TO_DT"
    Adodc1.Refresh
    ElseIf DataGrid1.SelStartCol = 6 Then
    Adodc1.RecordSource = "Select * from tblReservation order by MISC_ADJ"
    Adodc1.Refresh
    ElseIf DataGrid1.SelStartCol = 7 Then
    Adodc1.RecordSource = "Select * from tblReservation order by STATE_TAX"
    Adodc1.Refresh
    ElseIf DataGrid1.SelStartCol = 8 Then
    Adodc1.RecordSource = "Select * from tblReservation order by LOC_CHARGE"
    Adodc1.Refresh
    ElseIf DataGrid1.SelStartCol = 9 Then
    Adodc1.RecordSource = "Select * from tblReservation order by RES_ID"
    Adodc1.Refresh
    ElseIf DataGrid1.SelStartCol = 10 Then
    Adodc1.RecordSource = "Select * from tblReservation order by RES_OP"
    Adodc1.Refresh
    End If
    Do you see where i'm going with this?
    I simple want to use a variable in the "select * from <Table> Order by <Field>"

  • NDS : how to use a ' in the sql statement ?

    Hi folks,
    I would like to use a sql statement which includes single quotes "'" into my NDS statement.
    Since I have to put my statement into a varchar within single qutes I have to
    mark the internal quotes as quotes which have to be in my varchar buit don't effect the quoting of the whole varchar.
    How can I do that ?
    Best regards,
    Daniel

    I got it. In order to distinguish between data single quote and varchar sigle quote, you need to use 2 single-quotes instead of one in DATA.
    Like this.
    SQL>
    SQL> drop table table1;
    Table dropped.
    SQL>
    SQL> create table table1(col1 varchar2(20));
    Table created.
    SQL>
    SQL> insert into table1 values('Sarma''s');
    1 row created.
    SQL>
    SQL> commit
      2  /
    Commit complete.
    SQL> select * from table1
      2  /
    COL1
    Sarma's
    SQL> Cheers
    Sarma.

  • Passing date to another form and use the date in sql statement

    hello! to all programmers
    i have some small problem that need some help.
    i want to use date value parameter from the first page in the second page sql statement but i get invalid cursor state error so if anyone can solve this problem or give me a better solution to do this process.
    thanks in advance
    p/s
    EBDATE is define as date data type in my database.
    this is part of my jsp code...
    <---------------------------------------------------------------------->
    SimpleDateFormat sdfInput = new SimpleDateFormat( "yyyy-MM-dd" );
    SimpleDateFormat sdfOutput = new SimpleDateFormat ( "dd/MM/yyyy" );
    String date= request.getParameter("date");
    Date date1 = sdfInput.parse(date);
    Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection con=DriverManager.getConnection("jdbc:odbc:wtmis_db","","");
    Statement stmt=con.createStatement();
    ResultSet set=stmt.executeQuery("select * from ELECTRICBIL where EBDATE="+sdfOutput.format(date1));
    if (set!=null)
    set.next();
         Date bildate =set.getDate ("EBDATE");
         Date sdate =set.getDate ("EBSTARTDATE");
         Date edate =set.getDate ("EBENDDATE");
         int kw =set.getInt ("EBKILOWATT");
         int maxdemand =set.getInt ("EBMAXIMUMDEMAND");
         int days =set.getInt ("EBDAYS");     
    <---------------------------------------------------------------------->

    Try this
    <%
    while(set.next())
    Date bildate =set.getDate ("EBDATE");
    Date sdate =set.getDate ("EBSTARTDATE");
    Date edate =set.getDate ("EBENDDATE");
    int kw =set.getInt ("EBKILOWATT");
    int maxdemand =set.getInt ("EBMAXIMUMDEMAND");
    int days =set.getInt ("EBDAYS");
    %>
    <tr>
    <td width="211"><div align="left"><b>Bill Date :</b></div></td>
    <td width="573"><%=sdfOutput.format(date1)%></td>
    </tr>
    <tr>
    <td width="211"><div align="left"><b>Bill From :</b></div></td>
    <td width="573"> <input type="text" name="textfield" value="<%=sdate%>"></td>
    </tr>
    <tr>
    <td width="211"><div align="left"><b>Bill To :</b></div></td>
    <td width="573"> <input type="text" name="textfield2" value="<%=edate%>"></td>
    </tr>
    <tr>
    <td width="211"><div align="left"><b><b>kiloWatt Use (Rm)</b>: </b></div></td>
    <td width="573"> <input type="text" name="textfield2" value="<%=kw%>"></td>
    </tr>
    <tr>
    <td width="211"><div align="left"><b>Max Demand kiloWatt (Rm):</b></div></td>
    <td width="573"> <input type="text" name="textfield2" value="<%=maxdemand%>"></td>
    </tr>
    <tr>
    <td width="211"><div align="left"><b>Days In Billing :</b></div></td>
    <td width="573"> <input type="text" name="textfield2" value="<%=days%>"></td>
    </tr>
    <%
    %>
    i hope. Now u wouldn't get any error message...but...u wouldn't get results as well...Check ur date format with access date format....
    Revert back

  • Using bind variables with sql statements

    We connect from a VB 6.0 program via OO4O to an Oracle 8.1.7 database, using bind variables in connection with select statements. Running ok, but performance again by using bind vars not as good as expected!
    When looking into the table v$sqlarea, we were able to detect the reason. We expected that our program submits the sql statement with bind vars, Oracle parses this once, and with each select statement again, we do not have a reparse. But: It seems that with each new session Oracle reparses the sql statement, that is, Oracle is not able to memorize or cache bind vars and statements. Even more worrying, this kind of behaviour was visible with each new dynaset, but the same database/session.
    Is there anybody our there with an idea of what is happening here?
    Code snippet:
    Dim OraSession As OracleInProcServer.OraSessionClass
    Dim OraDatabase As OracleInProcServer.OraDatabase
    Set OraSession = CreateObject("OracleInProcServer.XOraSession")
    Set OraDatabase = OraSession.OpenDatabase(my database", "my connect", 0&)
    OraDatabase.Parameters.Add "my_bind", 0, ORAPARM_INPUT
    OraDatabase.Parameters("my_bind").DynasetOption = ORADYN_NOCACHE
    OraDatabase.Parameters("my_bind").serverType = ORATYPE_NUMBER ' Bind Var Type
    Dim RS As OracleInProcServer.OraDynaset
    strSQLstatement= "Select * from my_table where igz= [my_bind] "
    Set RS = OraDatabase.CreateDynaset(strSQLstatement, &H4)
    OraDatabase.Parameters("my_bind").Value = myValue
    RS.Refresh
    Cheers and thanks a lot :)
    Michael Sonntag

    We connect from a VB 6.0 program via OO4O to an Oracle 8.1.7 database, using bind variables in connection with select statements. Running ok, but performance again by using bind vars not as good as expected!
    When looking into the table v$sqlarea, we were able to detect the reason. We expected that our program submits the sql statement with bind vars, Oracle parses this once, and with each select statement again, we do not have a reparse. But: It seems that with each new session Oracle reparses the sql statement, that is, Oracle is not able to memorize or cache bind vars and statements. Even more worrying, this kind of behaviour was visible with each new dynaset, but the same database/session.
    Is there anybody our there with an idea of what is happening here?
    Code snippet:
    Dim OraSession As OracleInProcServer.OraSessionClass
    Dim OraDatabase As OracleInProcServer.OraDatabase
    Set OraSession = CreateObject("OracleInProcServer.XOraSession")
    Set OraDatabase = OraSession.OpenDatabase(my database", "my connect", 0&)
    OraDatabase.Parameters.Add "my_bind", 0, ORAPARM_INPUT
    OraDatabase.Parameters("my_bind").DynasetOption = ORADYN_NOCACHE
    OraDatabase.Parameters("my_bind").serverType = ORATYPE_NUMBER ' Bind Var Type
    Dim RS As OracleInProcServer.OraDynaset
    strSQLstatement= "Select * from my_table where igz= [my_bind] "
    Set RS = OraDatabase.CreateDynaset(strSQLstatement, &H4)
    OraDatabase.Parameters("my_bind").Value = myValue
    RS.Refresh
    Cheers and thanks a lot :)
    Michael Sonntag

  • Can we use repository variables in SQL statement of column prompt?

    Hi Dudes,
    Below is the query
    SELECT "- End Date"."End Fiscal Year" FROM "Consumer Sector" WHERE ("- End Date"."End Fiscal Year" = valueof (current_year)) or ("- End Date"."End Fiscal Year" = valueof (current_year) -1)
    when use this sql in criteria prompt getting error.
    Please suggest .
    thanks.sri

    Make sure your syntax is correct it should be like VALUEOF("CURRENT_YEAR")-1
    If you still have issues then VALUEOF("CURRENT_YEAR")-1 cast it to int before you subtract.
    If helps pls mark as correct else let share error message

  • Using a string as sql statement in PL/SQL

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

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

  • USE sequence.nextval in SQL statement

    Hi,
    I want to use SEQUENCE_name.NEXVAL in our query.
    But it gives error
    ora-02287: sequence number not allowed here
    Select distinct dd.agreementid,dd.cityid,dd.bankid,dd.bankbranchid,zz.bankbranchdesc,
    account_no,account_type,Sysdate,'A',Null,'1001',Sysdate,NULL,NULL,
    ELEC_PMNT_SEQ.Nextval seq_num
    From pdi.pdi_instr_d_tmp dd,
    pdi.pdi_bankbranch_m zz,
    pdi.pdi_bankaccount_tmp t
    Where t.agreementid = dd.agreementid
    And dd.cityid = zz.cityid
    And dd.bankid = zz.bankid
    And dd.bankbranchid= zz.bankbranchid
    And dd.mc_status = 'M' And dd.status = 'M' And instr_type <> 'P'
    Thanks & Regards
    K S Ratan

    You can use a subquery, but maybe have you need an order by clause ?
    SQL> ed
    Wrote file afiedt.buf
      1* select distinct username, MySeq.nextval from dba_users
    SQL> /
    select distinct username, MySeq.nextval from dba_users
    ERROR at line 1:
    ORA-02287: sequence number not allowed here
    SQL> ed
    Wrote file afiedt.buf
      1  select a.*, MySeq.nextval
      2* from (select distinct username from dba_users order by username) a
    SQL> /
    USERNAME                          NEXTVAL
    DBSNMP                                  1
    H89UCBAC                                2
    OUTLN                                   3
    PEOPLE                                  4
    PS                                      5
    SYS                                     6
    SYSTEM                                  7
    7 rows selected.
    SQL> /
    USERNAME                          NEXTVAL
    DBSNMP                                  8
    H89UCBAC                                9
    OUTLN                                  10
    PEOPLE                                 11
    PS                                     12
    SYS                                    13
    SYSTEM                                 14
    7 rows selected.Is this do you want ? Sequence will increment on each query execution, or did you want the number of output line to have the same result on each sql execution :
    SQL> ed
    Wrote file afiedt.buf
      1  select a.*, rownum
      2* from (select distinct username from dba_users order by username) a
    SQL> /
    USERNAME                           ROWNUM
    DBSNMP                                  1
    H89UCBAC                                2
    OUTLN                                   3
    PEOPLE                                  4
    PS                                      5
    SYS                                     6
    SYSTEM                                  7
    7 rows selected.
    SQL> /
    USERNAME                           ROWNUM
    DBSNMP                                  1
    H89UCBAC                                2
    OUTLN                                   3
    PEOPLE                                  4
    PS                                      5
    SYS                                     6
    SYSTEM                                  7
    7 rows selected.
    SQL> Nicolas.
    Sorry Laurent, you've already showed that works with subquery...
    Message was edited by:
    N. Gasparotto

  • Using passed values in SQL statements

    Using Adobe Livecycle Designer 7, we wish to populate a pdf document with values from a MS SQL database. The values will change depending on the ID of the record called for.
    We can already populate the form using SQL (SELECT firstname FROM names WHERE id = 1), but we need to populate it based on a 'passed' value in a url (http://www.mysite.com/mypdf.pdf?id=1).
    When we try to include this into the SQL (SELECT firstname FROM names WHERE id = request.id) we get an error. Could anyone provide us with the correct syntax that will allow us to populate the form based on the ID passed in a URL?
    Many Thanks
    Craig

    Hi all of you,
    I do have a problem with coding correctly a form I am designing sing the Adobe Livecycle . In one of the field, there is an underlying field that when you exit the first name field or the Middle Initial field or the last name, it should all pass the respective values to the underlying field which becomes visible on printout. I do have this code I wrote on the exit event, but do not understand why it it not working. Please, can anyone tell me why it is not working or help me out on a better way of making it work.
    xfa.host.messageBox("Check this");
    if (EMPFNAME.rawValue <> " " ){
    xfa.host.messageBox("EMPFNAME");
    EMPNAME.rawValue = String(EMPFNAME.rawValue) + " ";
    if (EMPFNAME.rawValue <> " " )&&(EMPMI.rawValue <> " "){
    EMPNAME.rawValue = String(EMPFNAME.rawValue) + " " + String(EMPMI.rawValue) + ".";
    var s = EMPMI.rawValue;
    EMPMI.rawValue = s.toUpperCase();
    if (EMPFNAME.rawValue <> " " )&&(EMPMI.rawValue <> " ")&&(EMPLNAME.rawValue <> " "){
    EMPNAME.rawValue = String(EMPFNAME.rawValue) + " " + String(EMPMI.rawValue) + "." + " " + String(EMPLNAME.rawValue);
    var s = EMPMI.rawValue;
    EMPMI.rawValue = s.toUpperCase();
    Thanks
    Lucky P

  • Use of variables in SQL statements

    Hi,
    I am looking for for a way to set a variable which will be referenced several times within a UNION query.
    Something like:
    Var=3
    SELECT * FROM VIEW_1 WHERE FIELD_1 = Var
    UNION
    SELECT * FROM VIEW_2 WHERE FIELD_1 = Var
    UNION
    SELECT * FROM VIEW_3 WHERE FIELD_1 = Var
    Instead of something like:
    SELECT * FROM VIEW_1 WHERE FIELD_1 = 3
    UNION
    SELECT * FROM VIEW_2 WHERE FIELD_1 = 3
    UNION
    SELECT * FROM VIEW_3 WHERE FIELD_1 = 3

    I'm sure that for this you were requiring a database solution and not a sqlplus solution ? If so, then you have a couple of options:-
    1) change the Var to a function call and have the function return a packaged variable or value in a lookup table that you can set as you require [ i.e. WHERE FIELD_1 = your_function ].
    2) use an application context, such that you set an attribute within the context and use it within the view [ i.e. WHERE FIELD_1 = SYS_CONTEXT( 'your_context', 'your_attribute' ) ].
    In both methods, you will need to set the value of your variable before referencing the view. The view therefore becomes "parameterised" in this sense.
    It might be possible that your view is mergeable. By this I mean that Oracle might be able to push a predicate against the view inside it instead, such that Oracle rewrites this:-
    SELECT <cols>
    FROM your_union_view
    WHERE field_1 = 3;
    ...and takes that value of field_1 = 3 and "pushes" it into your_union_view itself, in which case you will not need to worry about any of the above solutions. You can test this out by removing the where clauses from your view definition and running an explain plan against a query of the form above. If you see a "VIEW" step in the results, then the view is not mergeable in its current form and you should revert to the methods I listed.
    Regards
    Adrian
    For this you can use application contexts

  • Using store procedure within sql statement?

    I have the following sample tables:
    project id project_name
    ====== ===============
    1          project one
    2          project two
    3           project three
    employee_id     fname          lname
    =========== =============     =====
    100          amy          A
    200          better          B
    300          carrie          C
    project_id     employee_id
    ===========     ===========
    1          200
    2          300
    3          100
    there is a procedure getFullname(empployee_id) in place that combines the fname with lname to full name
    what i need to accomplish is the following.
    project is created by employee
    ==============================
    project one is created by better b
    project two is created by carrie C
    project three is created by amy A
    but the rule is: you have to call the procedure getFullName(employee_id) to accomplish the task above, and don't use the join tables to get the full employee name

    CREATE OR REPLACE FUNCTION YOUR_FUNCTION(i_nEmpId IN NUMBER)
    RETURN VARCHAR2 IS
    BEGIN
      RETURN 'Lastname ' || TO_CHAR(i_nEmpId) || ' Firstname';
    END;
    WITH PROJECTS AS (SELECT 1 PROJECT_id, 'project one' PROJECT_NAME FROM DUAL
                      UNION ALL
                      SELECT 2 PROJECT_id, 'project two' PROJECT_NAME FROM DUAL
                      UNION ALL
                      SELECT 3 PROJECT_id, 'project three' PROJECT_NAME FROM DUAL
      PROJ_TO_EMP AS (SELECT 1 PROJ_ID, 100 EMP_ID FROM DUAL
                      UNION ALL
                      SELECT 2 PROJ_ID, 200 EMP_ID FROM DUAL
                      UNION ALL
                      SELECT 3 PROJ_ID, 300 EMP_ID FROM DUAL
    SELECT PROJECT_ID,
           PROJECT_NAME,
           EMP_ID,
           YOUR_FUNCTION(EMP_ID),
           PROJECT_NAME || ' is created by ' || YOUR_FUNCTION(EMP_ID)
      FROM PROJECTS,
           PROJ_TO_EMP
    WHERE PROJECT_ID=PROJ_ID;

Maybe you are looking for

  • Installation problem with HP Officejet Pro Plus 8600 with Windows 8.1

    My system recently updated to Windows 8.1 and my HP Officejet Pro Plus 8600 will no longer function with my computers (Dell desktop, Hp laptop). It shows up in control panel, but says the driver is unavailable. I have tried to download the compatible

  • MacBook won't load

    Hi! After few days fine work my recently purchased Intel Macbook won't boot even from MacOSX install DVD and showing crossed out circle and rotating boot indicator. I tried to boot from Linux CD but it freezes on Kernel boot. Also I tried CommOpt+PR

  • Request.dsn and error

    I am working on a site and I have two databases. I used the Request.DSN in the application.cfm for the first data base...but how can I do something similar for the second? I would rather not have to go back and rename everywhere the database is liste

  • Why do all of my previously purchased app say they are no longer available?

    Each time I try to download a previously purchased app, a message says it is no longer available.  It even happens with my movies I've purchased.  Is iCloud down or something?

  • DESADV IDoc using EAN's

    Hi all, A bit of guidance if you could. I am trying to simulate an inbound delivery creation process using DELVRY06/DESADV for a PO. The issue I have is that the EDI provider will not be sending the material number in either the E1EDL24 (delivery lin