lobius.blogg.se

Mysql create view with variable
Mysql create view with variable













I found an ugly workaround: CREATE FUNCTION GetMyVariable() RETURNS INTEGER DETERMINISTIC NO SQLĪnd then the view is: CREATE VIEW MyView AS SELECT Column FROM Table WHERE Value = MySQL doesn't allow this. I'd like to make it more generic, it means to change 2 into a variable. SELECT Column FROM Table WHERE Value = 2 I have a view like this: CREATE VIEW MyView AS You can then use the other columns in the where clause for example where orders.order_id = param_table.order_id. This will cross join with only one row from the parameter table which is what you want. In the view use a cross join to the parameter table and put WHERE param_nnection_id = CONNECTION_ID(). replace into the parameter table and use CONNECTION_ID() to populate the connection_id value. Place columns in that table for parameters for the view. I previously came up with a different workaround that doesn't use stored procedures, but instead uses a parameter table and some connection_id() magic.Ĭreate a table that contains a column called connection_id (make it a bigint). Note: Unless the View is very complicated, MySQL will optimize this just fine. Is the proper solution in MySQL, some other SQLs let you define Views more exactly. SELECT Column FROM MyView WHERE Value = 1 Then you can call a view with a parameter: select s.* from (select p) parm, h_parm s Select * from sw_hardware_big where unit_id = p1() Actually if you create func: create function p1() returns INTEGER DETERMINISTIC NO SQL return view: create view h_parm as















Mysql create view with variable