Seat Distribution-Can, we do in SQL?

Hello

11 GR 2 DB

Here is the table structure and data (data and the Test tables)
create table seat_master(grade varchar2(1),balance number);

insert into seat_master values('A',3);
insert into seat_master values('B',2);
insert into seat_master values('C',1);
insert into seat_master values('D',1);
insert into seat_master values('E',6);

create table seat_reservation(res_id varchar2(5),grade varchar2(1),
            res_count number,group_flag varchar2(1));

insert into seat_reservation values('R1','A',2,'Y');
insert into seat_reservation values('R2','B',1,'Y');
insert into seat_reservation values('R3','A',2,'Y');
insert into seat_reservation values('R4','C',2,'N');
insert into seat_reservation values('R5','E',3,'N');
insert into seat_reservation values('R6','D',2,'N');

select *
from seat_master;

GRADE BALANCE
----- -------
A           3 
B           2 
C           1 
D           1 
E           6 


select *
from seat_reservation;

RES_ID GRADE RES_COUNT GROUP_FLAG
------ ----- --------- ----------
R1     A             2 Y          
R2     B             1 Y          
R3     A             2 Y          
R4     C             2 N          
R5     E             3 N          
R6     D             2 N          

 6 rows selected  
Now, the goal is to distribute the seats according to the booking.

Rules:
Distribution of seats is done according to the order of the (ORDER OF RES_ID) RES_ID
A is the highest grade and E is the lowest.
For one person booked for A, and if the balance is not available for him will be given B (and C, D, E).
A person reserved for B, and if the balance is not available for him will be given C (then D, E), but optical quality will not be given
GROUP_FLAG means that the reserve must be in the same category-
For example, R1, is for 2 seats in the a. They won't 1 seat and 1 seat in B.Both the two seats should be in A or B or C...
And for a booking, seats should be allocated that if the total number of requestd is if requested available.ie count is 2 and is only available in the particular category or below it cannot be awarded

The expected results are:
RES_ID SEAT 
------ ----
R1          A1 
R1          A2--Two A grade seats for R1, as R1 has RES_COUNT-2
       
R2     B1

R3          E1--R3 is given E grade, bcause as per now 2 seats 
R3          E2--are not available in A or B or C.And GroupFlag is Y for him

R4          C1--Only one seat availabl in C grade, so next seat will be Given
R4          D1--in lower available grade

R5          E3
R5          E4
R5          E5
R6            --Blank as only one seat can be awarded
Currently, this is done in PL/SQL, we can do it in SQL?

Thank you.

Published by: 884476 on November 18, 2012 12:14 AM

Hello

As I said before the query can be optimized.

I also solved a problem for the group_flag = ' don't
He showed plenty of seats assigned in case there are too many availlable.

See the result below:

WITH BAL AS
--ADD A '0' SEAT TO THE LIST OF SEATS
  (select * from seat_master UNION ALL
  SELECT '0', 0 FROM DUAL
  )
,MOD_IN AS
  (
  SELECT
    SR.RES_ID
    ,RANK() OVER (PARTITION BY BAL.GRADE ORDER BY SR.RES_ID) RES_NO
    ,BAL.GRADE
    ,BAL.BALANCE
    ,SR.GRADE    RES_GRADE
    ,CASE WHEN BAL.GRADE = '0' THEN SR.RES_COUNT ELSE 0 END RES_COUNT
    ,SR.GROUP_FLAG
  FROM
    SEAT_RESERVATION SR
    ,BAL
  )
,MDL AS
  (
  SELECT
    *
  FROM
    MOD_IN
  MODEL
  DIMENSION BY (RES_NO, GRADE)
  MEASURES ( RES_ID, BALANCE,RES_GRADE, RES_COUNT, GROUP_FLAG GF)
  RULES
  SEQUENTIAL ORDER
  ITERATE(10) UNTIL (RES_ID[ITERATION_NUMBER + 1,0] IS NULL)
    (
    --DISTRIBUTE SEATS PER REQUEST
    RES_COUNT[ITERATION_NUMBER + 1, FOR GRADE in (select grade FROM BAL WHERE GRADE > '0' ORDER BY GRADE )] =
            CASE WHEN GF[CV(),CV()] = 'Y'
                      AND MAX(RES_COUNT) [CV(), GRADE > '0'] = 0
                      AND BALANCE[CV(), CV()] >= RES_COUNT[CV(),0]
                      AND RES_GRADE[CV(), CV()] <= CV(GRADE)
                 THEN RES_COUNT[CV(),0] 

                      WHEN GF[CV(),CV()] = 'N'
                      AND SUM(RES_COUNT) [CV(), GRADE > '0'] < RES_COUNT[ITERATION_NUMBER + 1,0]
                      AND SUM(BALANCE) [CV(), GRADE >= RES_GRADE[CV(),CV()] ] >= RES_COUNT[CV(),0]
                      AND RES_GRADE[CV(), CV()] <= CV(GRADE)
                 THEN LEAST(2 * RES_COUNT[CV(),0] - SUM(RES_COUNT) [CV(), GRADE < CV(GRADE)], BALANCE[CV(), CV()] )
                 ELSE 0 END

    --UPDATE CURRENT BALLANCE
    ,BALANCE[ITERATION_NUMBER + 1, ANY] = BALANCE[CV(), CV()] - RES_COUNT[CV(),CV()]
    --UPDATE NEXT BALANCE
    ,BALANCE[ITERATION_NUMBER + 2, ANY] = BALANCE[ITERATION_NUMBER + 1, CV()]
    )
  )

SELECT
  MDL.RES_ID
  ,MDL.GRADE || COUNT(1) OVER (PARTITION BY MDL.GRADE ORDER BY MDL.RES_ID, SC.LVL) SEAT
FROM
  MDL
  ,(SELECT LEVEL LVL FROM DUAL CONNECT BY LEVEL < 100)  SC

WHERE
  MDL.RES_COUNT       > 0
  AND MDL.GRADE       > '0'
  AND SC.LVL          <= MDL.RES_COUNT

ORDER BY
  1,2
;

RES_ID SEAT
------ -----------------------------------------
R1     A1
R1     A2
R2     B1
R3     E1
R3     E2
R4     C1
R4     D1
R5     E3
R5     E4
R5     E5                                        

 10 rows selected 

Kind regards

Peter

Published by: Peter vd Zwan on 27 November 2012 13:35
Changed the end result to match output OP

Tags: Database

Similar Questions

  • WHAT APPLICATIONS CAN BE DEVELOPED FROM SQL SERVER 2012

    I need to know what applications can be developed using SQL SERVER 2012.

    Hi, Chris,.

    This is an overview of SQL Server 2012

    http://www.Microsoft.com/sqlserver/en/us/product-info/overview-capabilities.aspx

    SQL Server 2012 application development

    http://social.technet.Microsoft.com/wiki/contents/articles/6982.SQL-Server-2012-Developer-Training-Kit-BOM-en-us.aspx#Module_5_SQL_Server_2012_Application_Development

    Post your query on TechNet Forum to get help

    http://TechNet.Microsoft.com/en-us/SQLServer/ff898410.aspx

  • can the run/run .sql script in another application?

    Hello..

    I have a problem to run my .sql script (for example: @c:\Users\test.sql) in my netbeans application. There is no problem when I want to run/run my sql query (for example: "select * from...").

    But when I want to run my script, no presentation of the result. my script content my query to export to the csv file.

    script: @c:\Users\test.sql

    in the script:

    coil c:\Users\test.csv;

    ' Select ' ' ' | LOT_NUMBER | « «, » » || DEVICENUMBER | « «, » » || DEVICENAME | « «, » » || STEP_NAME | « «, » » || INSERT_DATE | « «, » » || STATUS | « «, » » || DISPOSEDBY | « «, » » || ACCEPTBY | « «, » » || AVAILABLE | « «, » » || GENDISPOSITION | » » »

    of RF_LOT_ON_HOLD_LIST;

    spool off;

    Thank you.

    bunch

    Yes, we know what talking about your question.

    a .sql script is just a plain text file containing everything you want.  The code in it can be a pure SQL statements, it may contain of the PL/SQL code, and it can also include SQL * more specific orders (keep in mind SQL * more is a tool, not a language, so that these commands are specific to this tool and other tools which can also interpret the same commands).

    Not quite sure how your question relates to this blog, as this blog is showing the code that gets the data in JSON format in a jqGrid (jQuery grid?) and then exports the data in an Excel file.

    What you're trying to do is to take a series of SQL * Plus and SQL statements in a text file and generate a CSV file from them.

    As already mentioned, SPOOL is a SQL * more order, specific to SQL * more command line tool.  The database itself has no idea what "spool" means, while passing to the database somehow does not work.  I also doubt that netbeans knows what that means, either.

    So, in short, how you try to do, not you cannot.

  • How can I write a sql with a Union.

    How can I write a sql with a Union.


    Select emp_name, emp_no, emp_sal of the emp


    If show_Less_100000 = "Yes" then emp_sal < 100000 (all values less than 100000)

    otherwise the full list.



    Thank you
    Harsha

    Published by: taty on July 31, 2012 11:28
    SQL> variable show_Less_100000 varchar2(3)
    SQL> exec :show_Less_100000 := 'Yes';
    
    PL/SQL procedure successfully completed.
    
    SQL> select  ename,
      2          empno,
      3          sal
      4    from  emp
      5    where (
      6               :show_Less_100000 = 'Yes'
      7           and
      8               sal < 2000
      9          )
     10       or nvl(:show_Less_100000,'No') != 'Yes'
     11  /
    
    ENAME           EMPNO        SAL
    ---------- ---------- ----------
    SMITH            7369        800
    ALLEN            7499       1600
    WARD             7521       1250
    MARTIN           7654       1250
    TURNER           7844       1500
    ADAMS            7876       1100
    JAMES            7900        950
    MILLER           7934       1300
    
    8 rows selected.
    
    SQL> exec :show_Less_100000 := 'All';
    
    PL/SQL procedure successfully completed.
    
    SQL> select  ename,
      2          empno,
      3          sal
      4    from  emp
      5    where (
      6               :show_Less_100000 = 'Yes'
      7           and
      8               sal < 3000
      9          )
     10       or nvl(:show_Less_100000,'No') != 'Yes'
     11  /
    
    ENAME           EMPNO        SAL
    ---------- ---------- ----------
    SMITH            7369        800
    ALLEN            7499       1600
    WARD             7521       1250
    JONES            7566       2975
    MARTIN           7654       1250
    BLAKE            7698       2850
    CLARK            7782       2450
    SCOTT            7788       3000
    KING             7839       5000
    TURNER           7844       1500
    ADAMS            7876       1100
    
    ENAME           EMPNO        SAL
    ---------- ---------- ----------
    JAMES            7900        950
    FORD             7902       3000
    MILLER           7934       1300
    
    14 rows selected.
    
    SQL> 
    

    SY.

  • How can I connect to SQL Server with the Muse?

    I want to query items from database and load it to the front end. Is there a way that muse can connect to the sql server database?

    It is not yet possible for Muse. Muse only creates .html pages. Connection to a database would require some php or other scripting to bind the data. It is beyond the scope of Muse and I don't see what is happening for a while.

  • Package DBMS_ADVISOR can be used for SQL Tuning Advisor?

    Package DBMS_ADVISOR can be used for SQL Tuning Advisor?

    It seems that the DBMS_ADVISOR package is responsible for the workload and SQL Access Advisor of related tasks. Package DBMS_SQLTUNE is responsible for setting up SQL and SQL set related tasks.

    Jetq

  • Error Code D59 can not install Microsoft SQL Server 2005 Express Edition Service Pack 4 update (KB2463332) _

    Error Code D59 can not install update of Microsoft SQL Server 2005 Express Edition Service Pack 4 (KB2463332)

    Try posting in the SQL Server Setup & Upgrade forum for assistance:http://social.msdn.microsoft.com/forums/en-US/sqlsetupandupgrade/threads/>

  • KB2760411, KB2760588, but now "can NOT CONNECT to" SQL Server!

    Today I faced with the same Windows Update problems as many people - with KB2760411 and KB2760588 constantly reinstall - and try to resolve which included several reboots - system
    ())

    BUT now... a serious problem on one of these machines: cannot access SQL Server!
    Fortunately, I did not run these updates on any * production * machines (I do updates on development machines, first) - this is a development machine - but I still need to get working SQL Server of this machine!

    I tried to use a Windows login to connect and tried to use a SQL Server to connect user, and what it in either, looks like the same message:
    "Cannot connect to ."
    A network-related or instance-specific error all by establishing a connection to SQL Server. The server is not found or inaccessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - could not open a connection to SQL Server) (Microsoft SQL Server, error: 2)

    Note that for windows, this server running Server 2003 (this is why I chose the value of the drop down menu 'windows xp', below).
    and for sql server, run SQL Server 2005.

    Help!?

    ALSO NOTE: I KNOW THIS ISN'T A "NETWORK ERROR."
    because I get the same message when I remote desktop on the server and try it.
    I did try to look in the windows Server 2003 event viewer, but saw nothing relevant under the security, system or Application.

    When I tried it with a sql server login, I clicked on "Show technical details" and got the below (blank lines removed and replaced with the name of the server):

    ===================================
    Unable to connect to .
    ===================================
    A network-related or instance-specific error all by establishing a connection to SQL Server. The server is not found or inaccessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - could not open a connection to SQL Server) (.Net SqlClient data provider)
    ------------------------------
    For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&EvtSrc=MSSQLServer&EvtID=2&LinkId=20476
    ------------------------------
    Error number: 2
    Severity: 20
    State: 0
    ------------------------------
    Location of the program:
    at System.Data.SqlClient.SqlInternalConnection.OnError (SqlException exception, Boolean breakConnection)
    at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning (TdsParserStateObject stateObj)
    to System.Data.SqlClient.TdsParser.Connect (ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Int64 timerExpire, Boolean ignoreSniOpenTimeout, encrypt Boolean trustServerCert, Boolean, Boolean integratedSecurity, SqlConnection owningObject)
    to System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin (ServerInfo serverInfo, String newPassword, ignoreSniOpenTimeout, Int64 timerExpire, SqlConnection owningObject, Boolean)
    at System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover (String host, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, Int64 timerStart)
    at System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist (SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance)
    to System.Data.SqlClient.SqlInternalConnectionTds... ctor (DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance)
    at System.Data.SqlClient.SqlConnectionFactory.CreateConnection (DbConnectionOptions options Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection)

    at System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection (DbConnection owningConnection, DbConnectionPoolGroup poolGroup)
    at System.Data.ProviderBase.DbConnectionFactory.GetConnection (DbConnection owningConnection)
    at System.Data.ProviderBase.DbConnectionClosed.OpenConnection (DbConnection outerConnection, DbConnectionFactory connectionFactory)
    at System.Data.SqlClient.SqlConnection.Open)
    to Microsoft.SqlServer.Management.UI.VSIntegration.ObjectExplorer.ObjectExplorer.ValidateConnection (UIConnectionInfo above, IServerType server)
    at Microsoft.SqlServer.Management.UI.ConnectionDlg.Connector.ConnectionThreadUser)

    Thanks Nirmal for the acknowledgement of receipt.

    As you can see, we ended up find us the answer.
    (BOWL is not same document how to grant "Log on as a service", under Server 2008 R2, WHEN ON THE DOMAIN CONTROLLER.)  BOWL documents which fully Server 2003, but only partially for Server 2008 R2.)

    But we are not given the opportunity to "mark as answer" on our own solution.
    If YOU think that the INFORMATION we posted had value, YOU may mark as answer.

    The TechNet link:
    Unable to connect to SQL Server... (includes advice in response: measures to grant permissions in Active Directory, the domain server * RUNNING SERVER 2008 R2 *).

    Thanks again.

  • I can't save on SQL server 2008.

    We run on SQL Server 2005 backup and had no problem at all, but as soon as we went to 2008 he started failing. Nothing was changed with the exception of sql server. The app is run remotely. The permissions are checked and work. What can be?

    Original title: backup failed for server 'ServerName '.

    Hi ainirbod,

    You must post your question in the TechNet Forums because it caters to an audience of it professionals.

    Check out the link-

    http://social.technet.Microsoft.com/forums/en-us/categories

     

     

    Hope this helps!

  • can I open a SQL express database in SQL server express 2005 2012?

    Hello

    I have a database and it's in SQL express 2005 but because my windows 8 is not compatible with the installer, I have to install the latest installer from 2012. now, my problem is that I can't open it in the 2012 edition... What should I do?

    This issue is beyond the scope of this site and must be placed on Technet or MSDN

    http://social.technet.Microsoft.com/forums/en-us/home

    http://social.msdn.Microsoft.com/forums/en-us/home

  • Table error ' can not analyze the SQL query!

    Hi all

    I created a view on my database called VIEW_MEMBER_PARTIC_PROJECTS

    If I run a query showing the results of the view:

    SELECT * FROM VIEW_MEMBER_PARTIC_PROJECTS

    I get the following data

    ProjectsParticipants
    131 S
    241
    319
    43
    53
    61
    72

    Now, I wanted to represent this diagram in the APEX so I created a graphic region and entered the Source query generator and the manufacturer produces the following code

    Select null, label projects, value1 Participant link

    of "SCHEMANAME." "" VIEW_MEMBER_PARTIC_PROJECTS ".

    With this code, I get an error:

    Cannot parse the SQL query!

    Select the link null, label projects, value1 "SCHEMANAME Participant." "" VIEW_MEMBER_PARTIC_PROJECTS ".

    Some queries can be run when you run your application, if your query is syntactically correct, you can save your query without validation (see options below the source of the query).

    The code looks OK, but I do not see to save options as the error code is mentioned.

    No one knows how to fix this?

    Thank you

    JaReg wrote:

    I finally found the problem.

    I looked at the code for the view and changed the start of:

    CREATE OR REPLACE FORCE EDITIONABLE VIEW "SCHEMANAME." "" VIEW_MEMBER_PARTIC_PROJECTS "("Participant","Projects")

    AS

    TO

    CREATE OR REPLACE VIEW "SCHEMANAME." "" VIEW_REPEAT_PARATIC ".

    AS

    And that seemed to fix it. I'm not entirely sure why though.

    The view was created using the quoted identifiers for column names. This makes them sensitive and means that they must always be referenced using double quotes. In the absence of quotation marks, Oracle is not case insensitive and automatically converts all uppercase identifiers. The application of graph:

    Select the link null, label projects, value1 "SCHEMANAME Participant." "" VIEW_MEMBER_PARTIC_PROJECTS ".

    has therefore been interpreted by Oracle:

    SELECT THE LINK NULL, LABEL, VALUE1 "SCHEMANAME PARTICIPANT PROJECTS." "" VIEW_MEMBER_PARTIC_PROJECTS ".

    and PROJECTS and PARTICIPANT columns were not recognized because the columns defined for the view have been 'Participant' and 'projects '. The graphic request should have been:

    Select the link null, the label of "Projects", "Participant" value1 "SCHEMANAME." "" VIEW_MEMBER_PARTIC_PROJECTS ".

    As you have now discovered, quoted identifiers are a source of nothing but obscure bugs and should never be used for database objects. He also pointed out the reason why you should always use a standardized, form tiny, coding style as it is faster to type, easy to read and less prone to errors.

  • Can you pass a SQL function?

    I have the following function:

    CREATE OR REPLACE PROCEDURE run_query (p_sql IN VARCHAR2) IS

    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_rowcount NUMBER: = 0;

    v_csv VARCHAR2 (32000);

    BEGIN

    -create a slider

    c: = DBMS_SQL. OPEN_CURSOR;

    -analyze the SQL statement in the cursor

    DBMS_SQL. PARSE (c, p_sql, DBMS_SQL. NATIVE);

    -run the cursor

    d: = DBMS_SQL. Execute (c);

    --

    -Describe the columns that are returned by the SQL statement

    DBMS_SQL. DESCRIBE_COLUMNS (c, col_cnt, rec_tab);

    --

    -Local variables Bind to return to the different columns according to their types

    1.col_cnt J

    LOOP

    CASE rec_tab (j) .col_type

    WHEN 1 THEN DBMS_SQL. DEFINE_COLUMN (c, j, v_v_val, 2000); -Varchar2

    WHEN 2 THEN DBMS_SQL. DEFINE_COLUMN (c, j, v_n_val);      -Number

    WHEN 12 THEN DBMS_SQL. DEFINE_COLUMN (c, j, v_d_val);     -Date

    ON THE OTHER

    DBMS_SQL. DEFINE_COLUMN (c, j, v_v_val, 2000);  -Any other type of return as varchar2

    END CASE;

    END LOOP;

    -This part generates the DATA

    LOOP

    -Retrieves a row of data using the cursor

    v_ret: = DBMS_SQL. FETCH_ROWS (c);

    -Output when no more line

    WHEN OUTPUT v_ret = 0;

    v_rowcount: = v_rowcount + 1;

    -Extract the value of each column of the row

    1.col_cnt J

    LOOP

    -Fetch each column to the correct data type according to the description of the column

    CASE rec_tab (j) .col_type

    WHEN 1 THEN DBMS_SQL. COLUMN_VALUE (c, j, v_v_val);

    v_csv: = v_csv | «, » || v_v_val;

    WHEN 2 THEN DBMS_SQL. COLUMN_VALUE (c, j, v_n_val);

    v_csv: = v_csv | «, » || v_n_val;

    WHEN 12 THEN DBMS_SQL. COLUMN_VALUE (c, j, v_d_val);

    v_csv: = v_csv | «, » || TO_CHAR (v_d_val, ' DD/MM/YYYY HH24:MI:SS');

    ON THE OTHER

    DBMS_SQL. COLUMN_VALUE (c, j, v_v_val);

    DBMS_OUTPUT. Put_line (v_v_val);

    END CASE;

    END LOOP;

    dbms_output.put_line (substr(v_csv,2));

    v_csv: = ";

    END LOOP;

    DBMS_SQL. CLOSE_CURSOR (c);

    END;

    /

    It allows to feed in an arbitrary query and returned a set of data comma separated. For example:

    SQL > run_query exec ('select * from scott.emp where deptno = 10');

    7782, CLARK, MANAGER, 7839, 1981/09/06 00:00:00, 2450, 10

    7839, KING, PRESIDENT, 17/11/1981-00:00:00, 5000, 10

    7934, MILLER, CLERK, 7782, 1982/01/23 00:00:00, 1300, 10

    PL/SQL procedure successfully completed.

    SQL > exec run_query ("select * from (select * from scott.emp where deptno = 10 order by sal desc) where rownum < 5'");

    7839, KING, PRESIDENT, 17/11/1981-00:00:00, 5000, 10

    7782, CLARK, MANAGER, 7839, 1981/09/06 00:00:00, 2450, 10

    7934, MILLER, CLERK, 7782, 1982/01/23 00:00:00, 1300, 10

    (I'm not saying that it is a good practice: on the contrary.) But it is a requirement that was worth and I need to know how to cope, not arguing with it).

    My question is: the code works when the application before she includes not single quotes. As soon as he does, he died:

    SQL > run_query exec ('select 'Example', sal scott.emp where deptno = 10');

    BEGIN run_query ('select 'Example', sal scott.emp where deptno = 10'); END;

    *

    ERROR on line 1:

    ORA-06550: line 1, column 26:

    PLS-00103: encountered the symbol "EXAMPLE" when awaits an of the

    Next:

    ), * & = - + <>/ is mod remains not rem = >

    < an exponent (*) > <>or! = or ~ = > = < = <>and like2 or

    like4 likec in reports between use. Member of type multiset

    submultiset

    The symbol ", has been inserted before"EXAMPLE"to continue."

    I could of course escape quotation marks simple "internal", but the goal is for end-users to feed in their queries, without having to rewrite with delicate escape sequences!

    So the question is: is there a way I can allow users to feed their SQL in the procedure without having to worry about the single quotes that might be in the middle of it?

    Still, I realize has the risk of SQL injection... but I would like to help on the practicalities of quotes, not managing a risk which I am aware (and dealing with outside the procedural code, that I showed here).

    In other words, even if you think it's the worst idea in the world, I still want to know how I could feed 'select 'Example', sal scott.emp where deptno = 10'procedure that it is correctly.

    Is there a character that you can be reasonably confident does not appear in the SQL statement?  If so, you can probably use the q citing the syntax.  For example

    SELECT q'{select 'a', 'b', 'c' from dual}'
      FROM dual
    

    who can get applied to the call to function as well

    SQL> exec run_query( q'{select 'a', 'b', 'c' from dual}' );
    a
    b
    c
    
    PL/SQL procedure successfully completed.
    

    If you can be reasonably sure that there is no {or} character (or a number of other pairs), you can just that wrap the SQL statement.  Of course, this assumes that there is some bit of code enforcement between the user and the procedure call that can add to the {and}.  If this is the case, you could also just double apostrophes that meet you.

    Justin

  • OBIEE 10 G can connect to a SQL Server database (2005)?

    We have Oracle BI already running. We also have a SQL Server database running. Now, there is requirement that requires to connect to SQL Server and directly send some books SQL on SQL Server and retrieve the result and display it in the answers. I know that the normal procedure should be set ETL to load data from the SQL Server in OBIEE and from there, the report can be built. So I'm not sure it's doable?

    Do the same thing using the online mode. so that you can add a connection pool to the RPD, which is located within the BI server.

  • Can I write merge SQL statement having count (*)?

    Hi, this is a follow-up to my previous post question. I tried to use a SQL statement of merger to solve my problem, but now I come across another problem.
    Now, I have a table where the field updated necessary is a partial PK
    When you use a SQL statement of merger, I put a where clause clause that check if count (*) = 1 because of the constraint of PK
    Where I put the count ()) = 1 clause?

    Here are the details:
    I have two tables TA and TB, where TA contains the fields IDS, FULLNAME, TYPE and tuberculosis contains the fields ID, NAME
    I want to update the names in TB for TA names where TB.ID = TA.ID and TA. TYPE = 'ABC '.
    {ID, first NAME} are PKs but for the same ID, there may be more than 1 firstname.
    for example
    TA
    -------------------------------
    ID | FULLNAME | TYPE
    1 Caroline T ABC
    2 Mary C DEF
    3 Peter J ABC

    TB
    ----------------------
    ID | FIRSTNAME
    1 Caroline
    1 Carol
    1 C,
    3 Peter

    I need to update TB with the new names of TA where type is 'ABC', but only for those areas that have count (TB.ID) = 1
    When I try to run this SQL statement

    merge into TB B using TA A
    on (A.ID = B.ID and A.TYPE = 'ABC')
    when matched, then update the value B.FIRSTNAME = substr (A.FULLNAME, 1, instr (A.FULLNAME, ',') - 1)

    I got this error SQL error: ORA-00001: unique constraint (TEST.) PK_TB) violated
    which I believe is because I've updated these fields say ID = 1, with 'Caroline '.
    This means that I'll have to add a clause with count (TB.ID) = 1
    How would you do it?

    Server Oracle 11 g is
    Thank you!

    Hello

    One way is to join your and tb in the USING clause and eliminate duplicates it.

    MERGE INTO     tb     dst
    USING   (
             SELECT    ta.id
             ,           REGEXP_SUBSTR ( MIN (ta.fullname)
                                    , '^[^,]*'
                            )     AS firstname
             FROM      ta
             JOIN      tb  ON  ta.id     = tb.id
             WHERE     ta.type      = 'ABC'
             GROUP BY  ta.id
             HAVING    COUNT (*)     = 1
         )                   src
    ON     (scr.id      = dst.id)
    WHEN MATCHED THEN UPDATE
    SET     dst.firstname     = src.firstname
    ;
    

    If you would care to post CREATE TABLE and INSERT statements for your sample data, and then I could test this.

    I used REGEXP_SUBST instead of SUBSTR and INSTR to search for the first name, because I find it a little cleaner, and because it returns something even when there is none "," fullname, which I assume is what you really want. (None of the fullnames in your sample data have ','s.) You can use SUBSTR and INSTR instead.

  • Where can I practice Pl/sql

    Hi, I m OCA administrator track.

    I now practice PL/SQL, but I have no idea on the tools of Oracle and development which tool is right for me.
    I've heard of

    (* 1) PL/SQL developer *.
    (* 2) Jdeveloper *.
    (* 3) ADF *.

    I want to practice on Windows 7. Kindly help

    NO, you need not Fusion Middleware at all to develop PL/SQL modules. The PL/SQL code can be stored either in a text file and loaded in SQL Developer, or stored as a package, procedure, or function in the database.

    You should really ask this question in a forum DBA or PL/SQL, Oracle Forms uses and needs of PL/SQL, the reverse is not true you don't need Oracle Forms or Weblogic/Fusion Middleware to learn PL/SQL.

    What did I say?

    If you want to build using SQL and PL/SQL oracle applications , then you need Fusion Middleware.

Maybe you are looking for